diff options
author | Andras Becsi <andras.becsi@digia.com> | 2014-03-18 13:16:26 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-20 15:55:39 +0100 |
commit | 3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch) | |
tree | 92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/build/toolchain | |
parent | e90d7c4b152c56919d963987e2503f9909a666d2 (diff) | |
download | qtwebengine-chromium-3f0f86b0caed75241fa71c95a5d73bc0164348c5.tar.gz |
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies
needed on Windows.
Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42
Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu>
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/build/toolchain')
-rw-r--r-- | chromium/build/toolchain/OWNERS | 2 | ||||
-rw-r--r-- | chromium/build/toolchain/linux/BUILD.gn | 180 | ||||
-rw-r--r-- | chromium/build/toolchain/mac/BUILD.gn | 82 | ||||
-rw-r--r-- | chromium/build/toolchain/mac/setup_toolchain.py | 29 | ||||
-rw-r--r-- | chromium/build/toolchain/nacl/BUILD.gn | 62 | ||||
-rw-r--r-- | chromium/build/toolchain/win/BUILD.gn | 154 | ||||
-rw-r--r-- | chromium/build/toolchain/win/setup_toolchain.py | 123 |
7 files changed, 632 insertions, 0 deletions
diff --git a/chromium/build/toolchain/OWNERS b/chromium/build/toolchain/OWNERS new file mode 100644 index 00000000000..9b79b9a9b50 --- /dev/null +++ b/chromium/build/toolchain/OWNERS @@ -0,0 +1,2 @@ +set noparent +brettw@chromium.org diff --git a/chromium/build/toolchain/linux/BUILD.gn b/chromium/build/toolchain/linux/BUILD.gn new file mode 100644 index 00000000000..ffb378beb88 --- /dev/null +++ b/chromium/build/toolchain/linux/BUILD.gn @@ -0,0 +1,180 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +cc = "gcc" +cxx = "g++" +ar = "ar" +ld = cxx + +# The toolchains below all issue the same commands with some different flags. +# TODO(brettw) it would be nice to have a different way to express this without +# so much duplication. +cc_command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out" +cxx_command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out" +alink_command = "rm -f \$out && $ar rcs \$out \$in" +solink_command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ]; then $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi" +link_command = "$ld \$ldflags -o \$out -Wl,--start-group \$in \$solibs -Wl,--end-group \$libs" +stamp_command = "\${postbuilds}touch \$out" +copy_command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)" + +# ARM -------------------------------------------------------------------------- + +cc = "arm-linux-gnueabi-gcc" +cxx = "arm-linux-gnueabi-g++" +ar = "arm-linux-gnueabi-ar" +ld = cxx + +toolchain("arm") { + # Make these apply to all tools below. + lib_prefix = "-l" + lib_dir_prefix="-L" + + tool("cc") { + # cflags_pch_c + command = cc_command + description = "CC \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("cxx") { + # cflags_pch_cc + command = cxx_command + description = "CXX \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("alink") { + command = alink_command + description = "AR \$out" + } + tool("solink") { + command = solink_command + description = "SOLINK \$lib" + #pool = "link_pool" + restat = "1" + } + tool("link") { + command = link_command + description = "LINK \$out" + #pool = "link_pool" + } + tool("stamp") { + command = stamp_command + description = "STAMP \$out" + } + tool("copy") { + command = copy_command + description = "COPY \$in \$out" + } + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args() { + cpu_arch = "arm" + } +} + +# 32-bit ----------------------------------------------------------------------- + +toolchain("32") { + # Make these apply to all tools below. + lib_prefix = "-l" + lib_dir_prefix="-L" + + tool("cc") { + # cflags_pch_c + command = cc_command + description = "CC \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("cxx") { + # cflags_pch_cc + command = cxx_command + description = "CXX \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("alink") { + command = alink_command + description = "AR \$out" + } + tool("solink") { + command = solink_command + description = "SOLINK \$lib" + #pool = "link_pool" + restat = "1" + } + tool("link") { + command = link_command + description = "LINK \$out" + #pool = "link_pool" + } + tool("stamp") { + command = stamp_command + description = "STAMP \$out" + } + tool("copy") { + command = copy_command + description = "COPY \$in \$out" + } + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args() { + cpu_arch = "x32" + } +} + +# 64-bit ----------------------------------------------------------------------- + +toolchain("64") { + # Make these apply to all tools below. + lib_prefix = "-l" + lib_dir_prefix="-L" + + tool("cc") { + # cflags_pch_c + command = cc_command + description = "CC \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("cxx") { + # cflags_pch_cc + command = cxx_command + description = "CXX \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("alink") { + command = alink_command + description = "AR \$out" + } + tool("solink") { + command = solink_command + description = "SOLINK \$lib" + #pool = "link_pool" + restat = "1" + } + tool("link") { + command = link_command + description = "LINK \$out" + #pool = "link_pool" + } + tool("stamp") { + command = stamp_command + description = "STAMP \$out" + } + tool("copy") { + command = copy_command + description = "COPY \$in \$out" + } + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args() { + cpu_arch = "x64" + } +} diff --git a/chromium/build/toolchain/mac/BUILD.gn b/chromium/build/toolchain/mac/BUILD.gn new file mode 100644 index 00000000000..b8a3c5eef17 --- /dev/null +++ b/chromium/build/toolchain/mac/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Should only be running on Mac. +assert(is_mac) + +cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang", ".", root_build_dir) +cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++", ".", root_build_dir) +ld = cxx + +# This will copy the gyp-mac-tool to the build directory. We pass in the source +# file of the win tool. +gyp_mac_tool_source = + rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", ".", root_build_dir) +exec_script("setup_toolchain.py", [ gyp_mac_tool_source ], "value") + +toolchain("clang") { + # Make these apply to all tools below. + lib_prefix = "-l" + lib_dir_prefix="-L" + + tool("cc") { + command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_pch_c -c \$in -o \$out" + description = "CC \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("cxx") { + command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_pch_cc -c \$in -o \$out" + description = "CXX \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("objc") { + command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c \$cflags_objc \$cflags_pch_objc -c \$in -o \$out" + description = "OBJC \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("objcxx") { + command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc \$cflags_objcc \$cflags_pch_objcc -c \$in -o \$out" + description = "OBJCXX \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("alink") { + command = "rm -f \$out && ./gyp-mac-tool filter-libtool libtool \$libtool_flags -static -o \$out \$in \$postbuilds" + description = "LIBTOOL-STATIC \$out, POSTBUILDS" + } + tool("solink") { + command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ] || otool -l \$lib | grep -q LC_REEXPORT_DYLIB ; then $ld -shared \$ldflags -o \$lib \$in \$solibs \$libs \$postbuilds && { otool -l \$lib | grep LC_ID_DYLIB -A 5; nm -gP \$lib | cut -f1-2 -d' ' | grep -v U\$\$; true; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib \$in \$solibs \$libs \$postbuilds && { otool -l \$lib | grep LC_ID_DYLIB -A 5; nm -gP \$lib | cut -f1-2 -d' ' | grep -v U\$\$; true; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi" + description = "SOLINK \$lib, POSTBUILDS" + #pool = "link_pool" + restat = "1" + } + tool("link") { + command = "$ld \$ldflags -o \$out \$in \$solibs \$libs \$postbuilds" + description = "LINK \$out, POSTBUILDS" + #pool = "link_pool" + } + #tool("infoplist") { + # command = "$cc -E -P -Wno-trigraphs -x c \$defines \$in -o \$out && plutil -convert xml1 \$out \$out" + # description = "INFOPLIST \$out" + #} + #tool("mac_tool") { + # command = "\$env ./gyp-mac-tool \$mactool_cmd \$in \$out" + # description = "MACTOOL \$mactool_cmd \$in" + #} + #tool("package_framework") { + # command = "./gyp-mac-tool package-framework \$out \$version \$postbuilds && touch \$out" + # description = "PACKAGE FRAMEWORK \$out, POSTBUILDS" + #} + tool("stamp") { + command = "\${postbuilds}touch \$out" + description = "STAMP \$out" + } + tool("copy") { + command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)" + description = "COPY \$in \$out" + } +} diff --git a/chromium/build/toolchain/mac/setup_toolchain.py b/chromium/build/toolchain/mac/setup_toolchain.py new file mode 100644 index 00000000000..431078fb180 --- /dev/null +++ b/chromium/build/toolchain/mac/setup_toolchain.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import stat +import sys + +def CopyTool(source_path): + """Copies the given tool to the current directory, including a warning not + to edit it.""" + with open(source_path) as source_file: + tool_source = source_file.readlines() + + # Add header and write it out to the current directory (which should be the + # root build dir). + out_path = 'gyp-mac-tool' + with open(out_path, 'w') as tool_file: + tool_file.write(''.join([tool_source[0], + '# Generated by setup_toolchain.py do not edit.\n'] + + tool_source[1:])) + st = os.stat(out_path) + os.chmod(out_path, st.st_mode | stat.S_IEXEC) + +# Find the tool source, it's the first argument, and copy it. +if len(sys.argv) != 2: + print "Need one argument (mac_tool source path)." + sys.exit(1) +CopyTool(sys.argv[1]) diff --git a/chromium/build/toolchain/nacl/BUILD.gn b/chromium/build/toolchain/nacl/BUILD.gn new file mode 100644 index 00000000000..fbced9732d7 --- /dev/null +++ b/chromium/build/toolchain/nacl/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +toolchain("x86_newlib") { + toolprefix = "gen/sdk/toolchain/linux_x86_newlib/bin/x86_64-nacl-" + cc = toolprefix + "gcc" + cxx = toolprefix + "g++" + ld = toolprefix + "g++" + + tool("cc") { + command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out" + description = "CC(NaCl x86 Newlib) \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("cxx") { + # cflags_pch_cc + command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out" + description = "CXX(NaCl x86 Newlib) \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("alink") { + command = "rm -f \$out && ${toolprefix}ar rcs \$out \$in" + description = "AR(NaCl x86 Newlib) \$out" + } + tool("solink") { + command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ]; then $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi" + description = "SOLINK(NaCl x86 Newlib) \$lib" + #pool = "link_pool" + restat = "1" + } + tool("link") { + command = "$ld \$ldflags -o \$out -Wl,--start-group \$in \$solibs -Wl,--end-group \$libs" + description = "LINK(NaCl x86 Newlib) \$out" + #pool = "link_pool" + } + + if (is_win) { + tool("stamp") { + command = "$python_path gyp-win-tool stamp \$out" + description = "STAMP \$out" + } + } else { + tool("stamp") { + command = "touch \$out" + description = "STAMP \$out" + } + } + + toolchain_args() { + # Override the default OS detection. The build config will set the is_* + # flags accordingly. + os = "nacl" + + # Component build not supported in NaCl, since it does not support shared + # libraries. + is_component_build = false + } +} diff --git a/chromium/build/toolchain/win/BUILD.gn b/chromium/build/toolchain/win/BUILD.gn new file mode 100644 index 00000000000..6abf8082daa --- /dev/null +++ b/chromium/build/toolchain/win/BUILD.gn @@ -0,0 +1,154 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Should only be running on Windows. +assert(is_win) + +# Setup the Visual Studio state. +# +# Its argument is the location to write the environment files. +# It will write "environment.x86" and "environment.x64" to this directory, +# and return a list to us. +# +# The list contains the include path as its only element. (I'm expecting to +# add more so it's currently a list inside a list.) +#exec_script("get_msvc_config.py", + # [relative_root_output_dir], + # "value") + +# This will save the environment block and and copy the gyp-win-tool to the +# build directory. We pass in the source file of the win tool. +gyp_win_tool_source = + rebase_path("//tools/gyp/pylib/gyp/win_tool.py", ".", root_build_dir) +exec_script("setup_toolchain.py", [ gyp_win_tool_source ], "value") + +stamp_command = "$python_path gyp-win-tool stamp \$out" +copy_command = "$python_path gyp-win-tool recursive-mirror \$in \$out" + +# 32-bit toolchain ------------------------------------------------------------- + +toolchain("32") { + # Make these apply to all tools below. + lib_prefix = "" + lib_dir_prefix="/LIBPATH:" + + cc_command = "ninja -t msvc -e environment.x86 -- cl.exe /nologo /showIncludes /FC @\$out.rsp /c \$in /Fo\$out /Fd\$pdbname" + tool("cc") { + command = cc_command + description = "CC \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$defines \$includes \$cflags \$cflags_c" + deps = "msvc" + } + tool("cxx") { + command = cc_command # Same as above + description = "CXX \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$defines \$includes \$cflags \$cflags_cc" + deps = "msvc" + } + tool("rc") { + command = "$python_path gyp-win-tool rc-wrapper environment.x86 rc.exe \$defines \$includes \$rcflags /fo\$out \$in" + description = "RC \$in" + } + tool("asm") { + command = "$python_path gyp-win-tool asm-wrapper environment.x86 ml.exe \$defines \$includes /c /Fo \$out \$in" + description = "ASM \$in" + } + tool("alink") { + command = "$python_path gyp-win-tool link-wrapper environment.x86 lib.exe /nologo /ignore:4221 /OUT:\$out @\$out.rsp" + description = "LIB \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$in_newline \$libflags" + } + tool("solink") { + command = "cmd /c $python_path gyp-win-tool link-wrapper environment.x86 link.exe /nologo \$implibflag /DLL /OUT:\$dll /PDB:\$dll.pdb @\$dll.rsp && $python_path gyp-win-tool manifest-wrapper environment.x86 cmd /c if exist \$dll.manifest del \$dll.manifest && $python_path gyp-win-tool manifest-wrapper environment.x86 mt.exe -nologo -manifest \$manifests -out:\$dll.manifest" + description = "LINK(DLL) \$dll" + restat = "1" + rspfile = "\$dll.rsp" + rspfile_content = "\$libs \$in_newline \$ldflags" + } + tool("link") { + command = "cmd /c $python_path gyp-win-tool link-wrapper environment.x86 link.exe /nologo /OUT:\$out /PDB:\$out.pdb @\$out.rsp && $python_path gyp-win-tool manifest-wrapper environment.x86 cmd /c if exist \$out.manifest del \$out.manifest && $python_path gyp-win-tool manifest-wrapper environment.x86 mt.exe -nologo -manifest \$manifests -out:\$out.manifest" + description = "LINK \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$in_newline \$libs \$ldflags" + } + tool("stamp") { + command = stamp_command + description = "STAMP \$out" + } + tool("copy") { + command = copy_command + description = "COPY \$in \$out" + } +} + +# 64-bit toolchain ------------------------------------------------------------- + +toolchain("64") { + # Make these apply to all tools below. + lib_prefix = "" + lib_dir_prefix="/LIBPATH:" + + cc_command = "ninja -t msvc -e environment.x64 -- cl.exe /nologo /showIncludes /FC @\$out.rsp /c \$in /Fo\$out /Fd\$pdbname" + tool("cc") { + command = cc_command + description = "CC \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$defines \$includes \$cflags \$cflags_c" + deps = "msvc" + } + tool("cxx") { + command = cc_command # Same as above + description = "CXX \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$defines \$includes \$cflags \$cflags_cc" + deps = "msvc" + } + tool("rc") { + command = "$python_path gyp-win-tool rc-wrapper environment.x64 rc.exe \$defines \$includes \$rcflags /fo\$out \$in" + description = "RC \$in" + } + tool("asm") { + command = "$python_path gyp-win-tool asm-wrapper environment.x64 ml.exe \$defines \$includes /c /Fo \$out \$in" + description = "ASM \$in" + } + tool("alink") { + command = "$python_path gyp-win-tool link-wrapper environment.x64 lib.exe /nologo /ignore:4221 /OUT:\$out @\$out.rsp" + description = "LIB \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$in_newline \$libflags" + } + tool("solink") { + command = "cmd /c $python_path gyp-win-tool link-wrapper environment.x64 link.exe /nologo \$implibflag /DLL /OUT:\$dll /PDB:\$dll.pdb @\$dll.rsp && $python_path gyp-win-tool manifest-wrapper environment.x64 cmd /c if exist \$dll.manifest del \$dll.manifest && $python_path gyp-win-tool manifest-wrapper environment.x64 mt.exe -nologo -manifest \$manifests -out:\$dll.manifest" + description = "LINK(DLL) \$dll" + restat = "1" + rspfile = "\$dll.rsp" + rspfile_content = "\$libs \$in_newline \$ldflags" + } + tool("link") { + command = "cmd /c $python_path gyp-win-tool link-wrapper environment.x64 link.exe /nologo /OUT:\$out /PDB:\$out.pdb @\$out.rsp && $python_path gyp-win-tool manifest-wrapper environment.x64 cmd /c if exist \$out.manifest del \$out.manifest && $python_path gyp-win-tool manifest-wrapper environment.x64 mt.exe -nologo -manifest \$manifests -out:\$out.manifest" + description = "LINK \$out" + rspfile = "\$out.rsp" + rspfile_content = "\$in_newline \$libs \$ldflags" + } + tool("stamp") { + command = stamp_command + description = "STAMP \$out" + } + tool("copy") { + command = copy_command + description = "COPY \$in \$out" + } + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args() { + cpu_arch = "x64" + # Normally the build config resets the CPU architecture to 32-bits. Setting + # this flag overrides that behavior. + force_win64 = true + } +} diff --git a/chromium/build/toolchain/win/setup_toolchain.py b/chromium/build/toolchain/win/setup_toolchain.py new file mode 100644 index 00000000000..162c2e16cef --- /dev/null +++ b/chromium/build/toolchain/win/setup_toolchain.py @@ -0,0 +1,123 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import re +import sys + +def ExtractImportantEnvironment(): + """Extracts environment variables required for the toolchain from the + current environment.""" + envvars_to_save = ( + 'goma_.*', # TODO(scottmg): This is ugly, but needed for goma. + 'Path', + 'PATHEXT', + 'SystemRoot', + 'TEMP', + 'TMP', + ) + result = {} + for envvar in envvars_to_save: + if envvar in os.environ: + if envvar == 'Path': + # Our own rules (for running gyp-win-tool) and other actions in + # Chromium rely on python being in the path. Add the path to this + # python here so that if it's not in the path when ninja is run + # later, python will still be found. + result[envvar.upper()] = os.path.dirname(sys.executable) + \ + os.pathsep + os.environ[envvar] + else: + result[envvar.upper()] = os.environ[envvar] + for required in ('SYSTEMROOT', 'TEMP', 'TMP'): + if required not in result: + raise Exception('Environment variable "%s" ' + 'required to be set to valid path' % required) + return result + + +# VC setup will add a path like this in 32-bit mode: +# c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN +# And this in 64-bit mode: +# c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64 +# Note that in 64-bit it's duplicated but the 64-bit one comes first. +# +# What we get as the path when running this will depend on which VS setup +# script you've run. The following two functions try to do this. + +# For 32-bit compiles remove anything that ends in "\VC\WIN\amd64". +def FixupPath32(path): + find_64 = re.compile("VC\\\\BIN\\\\amd64\\\\*$", flags=re.IGNORECASE) + + for i in range(len(path)): + if find_64.search(path[i]): + # Found 32-bit path, insert the 64-bit one immediately before it. + dir_64 = path[i].rstrip("\\") + dir_64 = dir_64[:len(dir_64) - 6] # Trim off "\amd64". + path[i] = dir_64 + break + return path + +# For 64-bit compiles, append anything ending in "\VC\BIN" with "\amd64" as +# long as that thing isn't already in the list, and append it immediately +# before the non-amd64-one. +def FixupPath64(path): + find_32 = re.compile("VC\\\\BIN\\\\*$", flags=re.IGNORECASE) + + for i in range(len(path)): + if find_32.search(path[i]): + # Found 32-bit path, insert the 64-bit one immediately before it. + dir_32 = path[i] + if dir_32[len(dir_32) - 1] == '\\': + dir_64 = dir_32 + "amd64" + else: + dir_64 = dir_32 + "\\amd64" + path.insert(i, dir_64) + break + + return path + + +def FormatAsEnvironmentBlock(envvar_dict): + """Format as an 'environment block' directly suitable for CreateProcess. + Briefly this is a list of key=value\0, terminated by an additional \0. See + CreateProcess documentation for more details.""" + block = '' + nul = '\0' + for key, value in envvar_dict.iteritems(): + block += key + '=' + value + nul + block += nul + return block + +def CopyTool(source_path): + """Copies the given tool to the current directory, including a warning not + to edit it.""" + with open(source_path) as source_file: + tool_source = source_file.readlines() + + # Add header and write it out to the current directory (which should be the + # root build dir). + with open("gyp-win-tool", 'w') as tool_file: + tool_file.write(''.join([tool_source[0], + '# Generated by setup_toolchain.py do not edit.\n'] + + tool_source[1:])) + + +# Find the tool source, it's the first argument, and copy it. +if len(sys.argv) != 2: + print "Need one argument (win_tool source path)." + sys.exit(1) +CopyTool(sys.argv[1]) + +important_env_vars = ExtractImportantEnvironment() +path = important_env_vars["PATH"].split(";") + +important_env_vars["PATH"] = ";".join(FixupPath32(path)) +environ = FormatAsEnvironmentBlock(important_env_vars) +with open('environment.x86', 'wb') as env_file: + env_file.write(environ) + +important_env_vars["PATH"] = ";".join(FixupPath64(path)) +environ = FormatAsEnvironmentBlock(important_env_vars) +with open('environment.x64', 'wb') as env_file: + env_file.write(environ) |