Commit 278873e4 authored by Puneet Kaushik's avatar Puneet Kaushik Committed by Facebook Github Bot

Add support to pass vcvarsall path on the command line

Summary: On Windows "--vcvars-path" can be passed to point to the toolchain we want to use.

Reviewed By: wez

Differential Revision: D15926044

fbshipit-source-id: 2b0cde793f7c7f8473b78afde8794640bae351f3
parent 68cf61fc
......@@ -367,6 +367,9 @@ def build_argparser():
common_args.add_argument(
"--scratch-path", help="Where to maintain checkouts and build dirs"
)
common_args.add_argument(
"--vcvars-path", default=None, help="Path to the vcvarsall.bat on Windows."
)
common_args.add_argument(
"--install-prefix",
help=(
......
......@@ -49,30 +49,13 @@ class BuilderBase(object):
env = self.env
if self.build_opts.is_windows():
# On Windows, the compiler is not available in the PATH by default
# so we need to run the vcvarsall script to populate the environment.
# We use a glob to find some version of this script as deployed with
# Visual Studio 2017. This logic will need updating when we switch
# to a newer compiler.
vcvarsall = glob.glob(
os.path.join(
os.environ["ProgramFiles(x86)"],
"Microsoft Visual Studio",
"2017",
"*",
"VC",
"Auxiliary",
"Build",
"vcvarsall.bat",
)
)
if len(vcvarsall) > 0:
vcvarsall = self.build_opts.get_vcvars_path()
if vcvarsall is not None:
# Since it sets rather a large number of variables we mildly abuse
# the cmd quoting rules to assemble a command that calls the script
# to prep the environment and then triggers the actual command that
# we wanted to run.
cmd = [vcvarsall[0], "amd64", "&&"] + cmd
cmd = [vcvarsall, "amd64", "&&"] + cmd
run_cmd(cmd=cmd, env=env, cwd=cwd or self.build_dir)
......
......@@ -9,6 +9,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
import base64
import errno
import glob
import hashlib
import ntpath
import os
......@@ -41,6 +42,7 @@ class BuildOptions(object):
install_dir=None,
num_jobs=0,
use_shipit=False,
vcvars_path=None,
):
""" fbcode_builder_dir - the path to either the in-fbsource fbcode_builder dir,
or for shipit-transformed repos, the build dir that
......@@ -53,6 +55,7 @@ class BuildOptions(object):
install_dir - where the project will ultimately be installed
num_jobs - the level of concurrency to use while building
use_shipit - use real shipit instead of the simple shipit transformer
vcvars_path - Path to external VS toolchain's vsvarsall.bat
"""
if not num_jobs:
import multiprocessing
......@@ -83,6 +86,28 @@ class BuildOptions(object):
self.fbcode_builder_dir = fbcode_builder_dir
self.host_type = host_type
self.use_shipit = use_shipit
if vcvars_path is None and is_windows():
# On Windows, the compiler is not available in the PATH by
# default so we need to run the vcvarsall script to populate the
# environment. We use a glob to find some version of this script
# as deployed with Visual Studio 2017. This logic will need
# updating when we switch to a newer compiler.
vcvarsall = glob.glob(
os.path.join(
os.environ["ProgramFiles(x86)"],
"Microsoft Visual Studio",
"2017",
"*",
"VC",
"Auxiliary",
"Build",
"vcvarsall.bat",
)
)
vcvars_path = vcvarsall[0]
self.vcvars_path = vcvars_path
def is_darwin(self):
return self.host_type.is_darwin()
......@@ -90,6 +115,9 @@ class BuildOptions(object):
def is_windows(self):
return self.host_type.is_windows()
def get_vcvars_path(self):
return self.vcvars_path
def is_linux(self):
return self.host_type.is_linux()
......@@ -310,4 +338,5 @@ def setup_build_options(args, host_type=None):
install_dir=args.install_prefix,
num_jobs=args.num_jobs,
use_shipit=args.use_shipit,
vcvars_path=args.vcvars_path,
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment