summaryrefslogtreecommitdiffstats
path: root/build/vs_toolchain.py
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 01:56:20 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 01:56:20 +0000
commitc71d328d02df039bd0868904d3c80acee4395653 (patch)
treef3f4726cc0b8c541bc3359f5f8a3f8f0da81d21b /build/vs_toolchain.py
parent647b16abbaee76aea325d32379a2ffb72b7533b6 (diff)
downloadchromium_src-c71d328d02df039bd0868904d3c80acee4395653.zip
chromium_src-c71d328d02df039bd0868904d3c80acee4395653.tar.gz
chromium_src-c71d328d02df039bd0868904d3c80acee4395653.tar.bz2
Split toolchain update and install lookup to make generation faster
runhooks does toolchain update, saving relevant information to build/win_toolchain.json, and during generation this is loaded and used. This worked almost the same previously, however update was called at generation time and the .json was deleted after it was used. This speeds up generation time by a few seconds. (In preference to https://codereview.chromium.org/228093002/) R=dpranke@chromium.org BUG=360878 Review URL: https://codereview.chromium.org/226643011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262590 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/vs_toolchain.py')
-rw-r--r--build/vs_toolchain.py96
1 files changed, 56 insertions, 40 deletions
diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py
index 247703b8..4b925f0 100644
--- a/build/vs_toolchain.py
+++ b/build/vs_toolchain.py
@@ -8,7 +8,6 @@ import pipes
import shutil
import subprocess
import sys
-import tempfile
script_dir = os.path.dirname(os.path.realpath(__file__))
@@ -16,46 +15,23 @@ chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(1, os.path.join(chrome_src, 'tools'))
sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
+json_data_file = os.path.join(script_dir, 'win_toolchain.json')
import gyp
-def GetDesiredVsToolchainHashes():
- """Load a list of SHA1s corresponding to the toolchains that we want installed
- to build with."""
- sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash')
- with open(sha1path, 'rb') as f:
- return f.read().strip().splitlines()
-
-
-def DownloadVsToolchain():
- """Download the Visual Studio toolchain on Windows.
-
- If on Windows, request that depot_tools install/update the automatic
- toolchain, and then use it (unless opted-out) and return a tuple containing
- the x64 and x86 paths. Otherwise return None.
+def SetEnvironmentAndGetRuntimeDllDirs():
+ """Sets up os.environ to use the depot_tools VS toolchain with gyp, and
+ returns the location of the VS runtime DLLs so they can be copied into
+ the output directory after gyp generation.
"""
vs2013_runtime_dll_dirs = None
depot_tools_win_toolchain = \
bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain:
- import find_depot_tools
- depot_tools_path = find_depot_tools.add_depot_tools_to_path()
- temp_handle, data_file = tempfile.mkstemp(suffix='.json')
- os.close(temp_handle)
- get_toolchain_args = [
- sys.executable,
- os.path.join(depot_tools_path,
- 'win_toolchain',
- 'get_toolchain_if_necessary.py'),
- '--output-json', data_file,
- ] + GetDesiredVsToolchainHashes()
- subprocess.check_call(get_toolchain_args)
-
- with open(data_file, 'r') as tempf:
+ with open(json_data_file, 'r') as tempf:
toolchain_data = json.load(tempf)
- os.unlink(data_file)
toolchain = toolchain_data['path']
version = toolchain_data['version']
@@ -132,18 +108,58 @@ def CopyVsRuntimeDlls(output_dir, runtime_dirs):
copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll')
+def _GetDesiredVsToolchainHashes():
+ """Load a list of SHA1s corresponding to the toolchains that we want installed
+ to build with."""
+ sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash')
+ with open(sha1path, 'rb') as f:
+ return f.read().strip().splitlines()
+
+
+def Update():
+ """Requests an update of the toolchain to the specific hashes we have at
+ this revision. The update outputs a .json of the various configuration
+ information required to pass to gyp which we use in |GetToolchainDir()|.
+ """
+ depot_tools_win_toolchain = \
+ bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
+ if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain:
+ import find_depot_tools
+ depot_tools_path = find_depot_tools.add_depot_tools_to_path()
+ json_data_file = os.path.join(script_dir, 'win_toolchain.json')
+ get_toolchain_args = [
+ sys.executable,
+ os.path.join(depot_tools_path,
+ 'win_toolchain',
+ 'get_toolchain_if_necessary.py'),
+ '--output-json', json_data_file,
+ ] + _GetDesiredVsToolchainHashes()
+ subprocess.check_call(get_toolchain_args)
+
+ return 0
+
+
+def GetToolchainDir():
+ """Gets location information about the current toolchain (must have been
+ previously updated by 'update')."""
+ SetEnvironmentAndGetRuntimeDllDirs()
+ print '["%s", "%s"]' % (
+ os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['WINDOWSSDKDIR'])
+
+
def main():
- if len(sys.argv) < 2:
- print >>sys.stderr, 'Expected either "get_toolchain_dir" or "copy_dlls"'
+ if not sys.platform.startswith(('win32', 'cygwin')):
+ return 0
+ commands = {
+ 'update': Update,
+ 'get_toolchain_dir': GetToolchainDir,
+ # TODO(scottmg): Add copy_dlls for GN builds (gyp_chromium calls
+ # CopyVsRuntimeDlls via import, currently).
+ }
+ if len(sys.argv) < 2 or sys.argv[1] not in commands:
+ print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
return 1
- if sys.argv[1] == 'get_toolchain_dir':
- DownloadVsToolchain()
- print '["%s", "%s"]' % (
- os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['WINDOWSSDKDIR'])
- else:
- print >>sys.stderr, 'TODO: not implemented "%s"' % sys.argv[1]
- return 1
- return 0
+ return commands[sys.argv[1]]()
if __name__ == '__main__':