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.
  """
  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:
      toolchain_data = json.load(tempf)
    os.unlink(data_file)

    toolchain = toolchain_data['path']
    version = toolchain_data['version']
    version_is_pro = version[-1] != 'e'
    win8sdk = toolchain_data['win8sdk']
    wdk = toolchain_data['wdk']
    # TODO(scottmg): The order unfortunately matters in these. They should be
    # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
    # below). http://crbug.com/345992
    vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs']

    os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
    os.environ['GYP_MSVS_VERSION'] = version
    # We need to make sure windows_sdk_path is set to the automated
    # toolchain values in GYP_DEFINES, but don't want to override any
    # otheroptions.express
    # values there.
    gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
    gyp_defines_dict['windows_sdk_path'] = win8sdk
    os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
        for k, v in gyp_defines_dict.iteritems())
    os.environ['WINDOWSSDKDIR'] = win8sdk
    os.environ['WDK_DIR'] = wdk
    # Include the VS runtime in the PATH in case it's not machine-installed.
    runtime_path = ';'.join(vs2013_runtime_dll_dirs)
    os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
  return vs2013_runtime_dll_dirs
Exemple #2
0
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.
  """
    vs_runtime_dll_dirs = None
    depot_tools_win_toolchain = 0
    #   bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
    # When running on a non-Windows host, only do this if the SDK has explicitly
    # been downloaded before (in which case json_data_file will exist).
    if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file))
            and depot_tools_win_toolchain):
        if ShouldUpdateToolchain():
            Update()
        with open(json_data_file, 'r') as tempf:
            toolchain_data = json.load(tempf)

        toolchain = toolchain_data['path']
        version = toolchain_data['version']
        win_sdk = toolchain_data.get('win_sdk')
        if not win_sdk:
            win_sdk = toolchain_data['win8sdk']
        wdk = toolchain_data['wdk']
        # TODO(scottmg): The order unfortunately matters in these. They should be
        # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
        # below). http://crbug.com/345992
        vs_runtime_dll_dirs = toolchain_data['runtime_dirs']

        os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
        os.environ['GYP_MSVS_VERSION'] = version
        # We need to make sure windows_sdk_path is set to the automated
        # toolchain values in GYP_DEFINES, but don't want to override any
        # otheroptions.express
        # values there.
        gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
        gyp_defines_dict['windows_sdk_path'] = win_sdk
        os.environ['GYP_DEFINES'] = ' '.join(
            '%s=%s' % (k, pipes.quote(str(v)))
            for k, v in gyp_defines_dict.iteritems())
        os.environ['WINDOWSSDKDIR'] = win_sdk
        os.environ['WDK_DIR'] = wdk
        # Include the VS runtime in the PATH in case it's not machine-installed.
        runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
        os.environ[
            'PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
    elif sys.platform == 'win32' and not depot_tools_win_toolchain:
        if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
            os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
        if not 'GYP_MSVS_VERSION' in os.environ:
            os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()

    return vs_runtime_dll_dirs
Exemple #3
0
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:
        if not os.path.exists(json_data_file):
            Update()
        with open(json_data_file, 'r') as tempf:
            toolchain_data = json.load(tempf)

        toolchain = toolchain_data['path']
        version = toolchain_data['version']
        version_is_pro = version[-1] != 'e'
        win8sdk = toolchain_data['win8sdk']
        wdk = toolchain_data['wdk']
        # TODO(scottmg): The order unfortunately matters in these. They should be
        # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
        # below). http://crbug.com/345992
        vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs']

        os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
        os.environ['GYP_MSVS_VERSION'] = version
        # We need to make sure windows_sdk_path is set to the automated
        # toolchain values in GYP_DEFINES, but don't want to override any
        # otheroptions.express
        # values there.
        gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
        gyp_defines_dict['windows_sdk_path'] = win8sdk
        os.environ['GYP_DEFINES'] = ' '.join(
            '%s=%s' % (k, pipes.quote(str(v)))
            for k, v in gyp_defines_dict.iteritems())
        os.environ['WINDOWSSDKDIR'] = win8sdk
        os.environ['WDK_DIR'] = wdk
        # Include the VS runtime in the PATH in case it's not machine-installed.
        runtime_path = ';'.join(vs2013_runtime_dll_dirs)
        os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
    return vs2013_runtime_dll_dirs
Exemple #4
0
def main():
  # Disabling garbage collection saves about 5% processing time. Since this is a
  # short-lived process it's not a problem.
  gc.disable()

  args = sys.argv[1:]

  if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)):
    print 'Skipping gyp_webrtc.py due to GYP_CHROMIUM_NO_ACTION env var.'
    sys.exit(0)

  if 'SKIP_WEBRTC_GYP_ENV' not in os.environ:
    # Update the environment based on webrtc.gyp_env.
    gyp_env_path = os.path.join(os.path.dirname(checkout_root),
                                'webrtc.gyp_env')
    gyp_helper.apply_gyp_environment_from_file(gyp_env_path)

  # This could give false positives since it doesn't actually do real option
  # parsing.  Oh well.
  gyp_file_specified = False
  for arg in args:
    if arg.endswith('.gyp'):
      gyp_file_specified = True
      break

  # If we didn't get a file, assume 'all.gyp' in the root of the checkout.
  if not gyp_file_specified:
    # Because of a bug in gyp, simply adding the abspath to all.gyp doesn't
    # work, but chdir'ing and adding the relative path does. Spooky :/
    os.chdir(checkout_root)
    args.append('all.gyp')

  # There shouldn't be a circular dependency relationship between .gyp files,
  args.append('--no-circular-check')

  # Default to ninja unless GYP_GENERATORS is set.
  if not os.environ.get('GYP_GENERATORS'):
    os.environ['GYP_GENERATORS'] = 'ninja'

  fixVS2015Ninja()

  # Enable check for missing sources in GYP files on Windows.
  if sys.platform.startswith('win'):
    gyp_generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '')
    if not 'msvs_error_on_missing_sources' in gyp_generator_flags:
      os.environ['GYP_GENERATOR_FLAGS'] = (
          gyp_generator_flags + ' msvs_error_on_missing_sources=1')

  vs2013_runtime_dll_dirs = None
  if int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')):
    vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs()
  else:
    gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
    winSdkDir = os.environ.get('UniversalCRTSdkDir')
    if winSdkDir != None:
        gyp_defines_dict['windows_sdk_path'] = winSdkDir
        os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
            for k, v in gyp_defines_dict.iteritems())

  # Enforce gyp syntax checking. This adds about 20% execution time.
  args.append('--check')

  supplemental_includes = GetSupplementalFiles()
  gyp_vars = gyp_chromium.GetGypVars(supplemental_includes)

  # Automatically turn on crosscompile support for platforms that need it.
  if all(('ninja' in os.environ.get('GYP_GENERATORS', ''),
          gyp_vars.get('OS') in ['android', 'ios'],
          'GYP_CROSSCOMPILE' not in os.environ)):
    os.environ['GYP_CROSSCOMPILE'] = '1'

  args.extend(['-I' + i for i in
               gyp_chromium.additional_include_files(supplemental_includes,
                                                     args)])

  # Set the gyp depth variable to the root of the checkout.
  args.append('--depth=' + os.path.relpath(checkout_root))

  print 'Updating projects from gyp files...'
  sys.stdout.flush()

  # Off we go...
  gyp_rc = gyp.main(args)

  if vs2013_runtime_dll_dirs:
    # pylint: disable=unpacking-non-sequence
    x64_runtime, x86_runtime = vs2013_runtime_dll_dirs
    vs_toolchain.CopyVsRuntimeDlls(
        os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()),
        (x86_runtime, x64_runtime))

  sys.exit(gyp_rc)
Exemple #5
0
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.

  Return value is [x64path, x86path] or None
  """
    vs_runtime_dll_dirs = None
    depot_tools_win_toolchain = \
        bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
    # When running on a non-Windows host, only do this if the SDK has explicitly
    # been downloaded before (in which case json_data_file will exist).
    if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file))
            and depot_tools_win_toolchain):
        if ShouldUpdateToolchain():
            update_result = Update()
            if update_result != 0:
                raise Exception('Failed to update, error code %d.' %
                                update_result)
        with open(json_data_file, 'r') as tempf:
            toolchain_data = json.load(tempf)

        toolchain = toolchain_data['path']
        version = toolchain_data['version']
        win_sdk = toolchain_data.get('win_sdk')
        if not win_sdk:
            win_sdk = toolchain_data['win8sdk']
        wdk = toolchain_data['wdk']
        # TODO(scottmg): The order unfortunately matters in these. They should be
        # split into separate keys for x86 and x64. (See CopyDlls call below).
        # http://crbug.com/345992
        vs_runtime_dll_dirs = toolchain_data['runtime_dirs']

        os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
        os.environ['GYP_MSVS_VERSION'] = version

        # Limit the scope of the gyp import to only where it is used. This
        # potentially lets build configs that never execute this block to drop
        # their GYP checkout.
        import gyp

        # We need to make sure windows_sdk_path is set to the automated
        # toolchain values in GYP_DEFINES, but don't want to override any
        # otheroptions.express
        # values there.
        gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
        gyp_defines_dict['windows_sdk_path'] = win_sdk
        os.environ['GYP_DEFINES'] = ' '.join(
            '%s=%s' % (k, pipes.quote(str(v)))
            for k, v in gyp_defines_dict.iteritems())

        os.environ['WINDOWSSDKDIR'] = win_sdk
        os.environ['WDK_DIR'] = wdk
        # Include the VS runtime in the PATH in case it's not machine-installed.
        runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
        os.environ[
            'PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
    elif sys.platform == 'win32' and not depot_tools_win_toolchain:
        if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
            os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
        if not 'GYP_MSVS_VERSION' in os.environ:
            os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()

        # When using an installed toolchain these files aren't needed in the output
        # directory in order to run binaries locally, but they are needed in order
        # to create isolates or the mini_installer. Copying them to the output
        # directory ensures that they are available when needed.
        bitness = platform.architecture()[0]
        # When running 64-bit python the x64 DLLs will be in System32
        x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
        x64_path = os.path.join(os.path.expandvars('%windir%'), x64_path)
        vs_runtime_dll_dirs = [
            x64_path, os.path.expandvars('%windir%/SysWOW64')
        ]

    return vs_runtime_dll_dirs