def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--input-file', help='Path to the AAR file.', required=True, metavar='FILE') parser.add_argument('--extract', help='Extract the files to output directory.', action='store_true') parser.add_argument('--list', help='List all the resource and jar files.', action='store_true') parser.add_argument('--output-dir', help='Output directory for the extracted files. Must ' 'be set if --extract is set.', metavar='DIR') args = parser.parse_args() if not args.extract and not args.list: parser.error('Either --extract or --list has to be specified.') aar_file = args.input_file output_dir = args.output_dir if args.extract: # Clear previously extracted versions of the AAR. shutil.rmtree(output_dir, True) build_utils.ExtractAll(aar_file, path=output_dir) if args.list: data = {} data['aidl'] = [] data['assets'] = [] data['resources'] = [] data['subjars'] = [] data['subjar_tuples'] = [] data['has_classes_jar'] = False data['has_proguard_flags'] = False # data['has_native_libraries'] = False with zipfile.ZipFile(aar_file) as z: data['is_manifest_empty'] = ( _IsManifestEmpty(z.read('AndroidManifest.xml'))) for name in z.namelist(): if name.endswith('/'): continue if name.startswith('aidl/'): data['aidl'].append(name) elif name.startswith('res/'): data['resources'].append(name) elif name.startswith('libs/') and name.endswith('.jar'): label = posixpath.basename(name)[:-4] label = re.sub(r'[^a-zA-Z0-9._]', '_', label) data['subjars'].append(name) data['subjar_tuples'].append([label, name]) elif name.startswith('assets/'): data['assets'].append(name) # elif name.startswith('jni/'): # data['has_native_libraries'] = True elif name == 'classes.jar': data['has_classes_jar'] = True elif name == 'proguard.txt': data['has_proguard_flags'] = True print gn_helpers.ToGNString(data)
def SetupToolchain(version_as_year, vs_path, sdk_version=None, clang_base_path=None, clang_msc_ver=None): cpus = ('x86', 'x64', 'arm', 'arm64') # vcvarsall.bat for VS 2017 fails if run after running vcvarsall.bat from # VS 2013 or VS 2015. Fix this by clearing the vsinstalldir environment # variable. # Since vcvarsall.bat appends to the INCLUDE, LIB, and LIBPATH # environment variables we need to clear those to avoid getting double # entries when vcvarsall.bat has been run before gn gen. vcvarsall.bat # also adds to PATH, but there is no clean way of clearing that and it # doesn't seem to cause problems. if 'VSINSTALLDIR' in os.environ: del os.environ['VSINSTALLDIR'] del os.environ['INCLUDE'] del os.environ['LIB'] del os.environ['LIBPATH'] if version_as_year == 'latest': version_as_year, vs_path = FindLatestVisualStudio() elif not vs_path or vs_path == 'default': vs_path = DetectVisualStudioPath(version_as_year) # TODO(tim): We now launch all processes at once, but this still takes too long processes = {} for (cpu, is_uwp) in itertools.product(cpus, (False, True)): suffix = '_uwp' if is_uwp else '' processes[cpu + suffix] = _Spawn( _BuildToolchainSetupCommand(vs_path, cpu, sdk_version, is_uwp)) windows_sdk_paths = {} envs = {} for (cpu, is_uwp) in itertools.product(cpus, (False, True)): name = cpu + ('_uwp' if is_uwp else '') # Extract environment variables for subprocesses. env = _ExtractImportantEnvironment(_ProcessSpawnResult( processes[name])) envs[name] = env vc_bin_dir = '' vc_lib_path = '' vc_lib_atlmfc_path = '' vc_lib_um_path = '' for path in env['PATH'].split(os.pathsep): if os.path.exists(os.path.join(path, 'cl.exe')): vc_bin_dir = os.path.realpath(path) break if not vc_bin_dir: continue for path in env['LIB'].split(os.pathsep): if os.path.exists(os.path.join(path, 'msvcrt.lib')): vc_lib_path = os.path.realpath(path) break for path in env['LIB'].split(os.pathsep): if os.path.exists(os.path.join(path, 'atls.lib')): vc_lib_atlmfc_path = os.path.realpath(path) break for path in env['LIB'].split(os.pathsep): if os.path.exists(os.path.join(path, 'User32.Lib')): vc_lib_um_path = os.path.realpath(path) break # Ignore incomplete installations. # e.g. VS supports ARM64, but the Windows SDK does not. if not vc_lib_path or not vc_lib_um_path: continue windows_sdk_paths[name] = os.path.realpath(env['WINDOWSSDKDIR']) # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [ p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p ] # Make include path relative to builddir when cwd and sdk in same drive. try: include = list(map(os.path.relpath, include)) except ValueError: pass lib = [p.replace('"', r'\"') for p in env['LIB'].split(';') if p] # Make lib path relative to builddir when cwd and sdk in same drive. try: lib = list(map(os.path.relpath, lib)) except ValueError: pass def q(s): # Quote s if it contains spaces or other weird characters. return s if re.match(r'^[a-zA-Z0-9._/\\:-]*$', s) else '"' + s + '"' include_I = ' '.join([q('/I' + i) for i in include]) include_imsvc = ' '.join([q('-imsvc' + i) for i in include]) libpath_flags = ' '.join([q('-libpath:' + i) for i in lib]) env_block = _FormatAsEnvironmentBlock(env) env_filename = 'environment_{}'.format(name) with open(env_filename, 'wb') as f: f.write(env_block) print(name + ' = {') print('env_filename = ' + gn_helpers.ToGNString(env_filename)) assert vc_bin_dir print('vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir)) assert include_I print('include_flags_I = ' + gn_helpers.ToGNString(include_I)) assert include_imsvc print('include_flags_imsvc = ' + gn_helpers.ToGNString(include_imsvc)) assert vc_lib_path print('vc_lib_path = ' + gn_helpers.ToGNString(vc_lib_path)) # Possible atlmfc library path gets introduced in the future for store thus # output result if a result exists. if vc_lib_atlmfc_path != '': print('vc_lib_atlmfc_path = ' + gn_helpers.ToGNString(vc_lib_atlmfc_path)) assert vc_lib_um_path print('vc_lib_um_path = ' + gn_helpers.ToGNString(vc_lib_um_path)) print('paths = ' + gn_helpers.ToGNString(env['PATH'])) assert libpath_flags print('libpath_flags = ' + gn_helpers.ToGNString(libpath_flags)) print('}') if len(set(windows_sdk_paths.values())) != 1: raise Exception("WINDOWSSDKDIR is different for x86/x64") print('visual_studio_version = ' + gn_helpers.ToGNString(version_as_year)) print('visual_studio_path = ' + gn_helpers.ToGNString(vs_path)) # SDK is always the same print('windows_sdk_path = ' + gn_helpers.ToGNString(windows_sdk_paths['x86'])) # TODO(tim): Check for mismatches between x86 and x64? if clang_base_path: msc_ver = clang_msc_ver or _GetClangMscVersionFromYear(version_as_year) clang_version, msc_full_ver = _GetClangVersion(clang_base_path, msc_ver) print('clang_version = ' + gn_helpers.ToGNString(clang_version)) print('msc_ver = ' + gn_helpers.ToGNString(msc_full_ver // 100000)) print('msc_full_ver = ' + gn_helpers.ToGNString(msc_full_ver)) else: # TODO(tim): Do we want to support different toolchain versions for # different architectures? msc_full_ver = _ParseClVersion( _ProcessSpawnResult(_Spawn(['cl'], env=envs['x86']))) print('msc_ver = ' + gn_helpers.ToGNString(msc_full_ver // 100000)) print('msc_full_ver = ' + gn_helpers.ToGNString(msc_full_ver))
def main(): if len(sys.argv) != 7 and len(sys.argv) != 4: print( 'Usage setup_toolchain.py ' '<visual studio path> <win sdk path> ' '<runtime dirs> <target_os> <target_cpu> ' '<environment block name|none>') print( 'or setup_toolchain.py <target_os> <target_cpu>' '<environment block name|none>') sys.exit(2) if len(sys.argv) == 7: win_sdk_path = sys.argv[2] runtime_dirs = sys.argv[3] target_os = sys.argv[4] target_cpu = sys.argv[5] environment_block_name = sys.argv[6] else: target_os = sys.argv[1] target_cpu = sys.argv[2] environment_block_name = sys.argv[3] if (environment_block_name == 'none'): environment_block_name = '' if (target_os == 'winuwp'): target_store = True else: target_store = False cpus = ('x86', 'x64', 'arm', 'arm64') assert target_cpu in cpus vc_bin_dir = '' vc_lib_path = '' vc_lib_atlmfc_path = '' vc_lib_um_path = '' include = '' lib = '' ninja_use_custom_environment_files = (len(sys.argv) == 7) for cpu in cpus: if cpu != target_cpu: continue if not ninja_use_custom_environment_files: env = os.environ else: # Extract environment variables for subprocesses. env = _LoadToolchainEnv(cpu, win_sdk_path, target_store) env['PATH'] = runtime_dirs + os.pathsep + env['PATH'] for path in env['PATH'].split(os.pathsep): if os.path.exists(os.path.join(path, 'cl.exe')): vc_bin_dir = os.path.realpath(path) break for path in env['LIB'].split(';'): if os.path.exists(os.path.join(path, 'msvcrt.lib')): vc_lib_path = os.path.realpath(path) break for path in env['LIB'].split(';'): if os.path.exists(os.path.join(path, 'atls.lib')): vc_lib_atlmfc_path = os.path.realpath(path) break for path in env['LIB'].split(';'): if os.path.exists(os.path.join(path, 'User32.Lib')): vc_lib_um_path = os.path.realpath(path) break # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [ p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p ] # Make include path relative to builddir when cwd and sdk in same drive. try: include = map(os.path.relpath, include) except ValueError: pass lib = [p.replace('"', r'\"') for p in env['LIB'].split(';') if p] # Make lib path relative to builddir when cwd and sdk in same drive. try: lib = map(os.path.relpath, lib) except ValueError: pass def q(s): # Quote s if it contains spaces or other weird characters. return s if re.match(r'^[a-zA-Z0-9._/\\:-]*$', s) else '"' + s + '"' include_I = ' '.join([q('/I' + i) for i in include]) include_imsvc = ' '.join([q('-imsvc' + i) for i in include]) libpath_flags = ' '.join([q('-libpath:' + i) for i in lib]) if (environment_block_name != ''): env_block = _FormatAsEnvironmentBlock(env) with open(environment_block_name, 'wb') as f: f.write(env_block) assert vc_bin_dir print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) assert include_I print 'include_flags_I = ' + gn_helpers.ToGNString(include_I) assert include_imsvc print 'include_flags_imsvc = ' + gn_helpers.ToGNString(include_imsvc) assert vc_lib_path print 'vc_lib_path = ' + gn_helpers.ToGNString(vc_lib_path) if (target_store != True): # Path is assumed not to exist for desktop applications assert vc_lib_atlmfc_path # Possible atlmfc library path gets introduced in the future for store thus # output result if a result exists. if (vc_lib_atlmfc_path != ''): print 'vc_lib_atlmfc_path = ' + gn_helpers.ToGNString( vc_lib_atlmfc_path) assert vc_lib_um_path print 'vc_lib_um_path = ' + gn_helpers.ToGNString(vc_lib_um_path) print 'paths = ' + gn_helpers.ToGNString(env['PATH']) assert libpath_flags print 'libpath_flags = ' + gn_helpers.ToGNString(libpath_flags)
def SetupToolchain(version_as_year, vs_path, include_prefix, sdk_version=None, clang_base_path=None, clang_msc_ver=None): cpus = ('x86', 'x64') bin_dirs = {} windows_sdk_paths = {} include_flags = {} envs = {} for cpu in cpus: # Extract environment variables for subprocesses. env = _LoadToolchainEnv(vs_path, cpu, sdk_version) envs[cpu] = env windows_sdk_paths[cpu] = os.path.realpath(env['WINDOWSSDKDIR']) for path in env['PATH'].split(os.pathsep): if os.path.exists(os.path.join(path, 'cl.exe')): bin_dirs[cpu] = os.path.realpath(path) break # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [include_prefix + p for p in env['INCLUDE'].split(';') if p] include = ' '.join( ['"' + i.replace('"', r'\"') + '"' for i in include]) include_flags[cpu] = include env_block = _FormatAsEnvironmentBlock(env) with open('environment.' + cpu, 'wb') as f: f.write(env_block) # Create a store app version of the environment. if 'LIB' in env: env['LIB'] = env['LIB'].replace(r'\VC\LIB', r'\VC\LIB\STORE') if 'LIBPATH' in env: env['LIBPATH'] = env['LIBPATH'].replace(r'\VC\LIB', r'\VC\LIB\STORE') env_block = _FormatAsEnvironmentBlock(env) with open('environment.winrt_' + cpu, 'wb') as f: f.write(env_block) if len(set(windows_sdk_paths.values())) != 1: raise Exception("WINDOWSSDKDIR is different for x86/x64") print('x86_bin_dir = ' + gn_helpers.ToGNString(bin_dirs['x86'])) print('x64_bin_dir = ' + gn_helpers.ToGNString(bin_dirs['x64'])) print('x86_include_flags = ' + gn_helpers.ToGNString(include_flags['x86'])) print('x64_include_flags = ' + gn_helpers.ToGNString(include_flags['x64'])) # SDK is always the same print('windows_sdk_path = ' + gn_helpers.ToGNString(windows_sdk_paths['x86'])) # TODO(tim): Check for mismatches between x86 and x64? if clang_base_path: msc_ver = clang_msc_ver or _GetClangMscVersionFromYear(version_as_year) clang_version, msc_full_ver = _GetClangVersion(clang_base_path, msc_ver) print('clang_version = ' + gn_helpers.ToGNString(clang_version)) print('msc_ver = ' + gn_helpers.ToGNString(msc_full_ver // 100000)) print('msc_full_ver = ' + gn_helpers.ToGNString(msc_full_ver)) else: msc_full_ver = _ParseClVersion(_Call(['cl'], env=envs['x86'])) print('msc_ver = ' + gn_helpers.ToGNString(msc_full_ver // 100000)) print('msc_full_ver = ' + gn_helpers.ToGNString(msc_full_ver))
def main(): if len(sys.argv) != 7: print('Usage setup_toolchain.py ' '<visual studio path> <win sdk path> ' '<runtime dirs> <target_os> <target_cpu> ' '<environment block name|none>') sys.exit(2) win_sdk_path = sys.argv[2] runtime_dirs = sys.argv[3] target_os = sys.argv[4] target_cpu = sys.argv[5] environment_block_name = sys.argv[6] if (environment_block_name == 'none'): environment_block_name = '' if (target_os == 'winuwp'): target_store = True else: target_store = False cpus = ('x86', 'x64', 'arm', 'arm64') assert target_cpu in cpus vc_bin_dir = '' vc_lib_path = '' vc_lib_atlmfc_path = '' vc_lib_um_path = '' include = '' lib = '' # TODO(scottmg|goma): Do we need an equivalent of # ninja_use_custom_environment_files? for cpu in cpus: if cpu == target_cpu: # Extract environment variables for subprocesses. env = _LoadToolchainEnv(cpu, win_sdk_path, target_store) env['PATH'] = runtime_dirs + os.pathsep + env['PATH'] vc_bin_dir = FindFileInEnvList(env, 'PATH', os.pathsep, 'cl.exe') vc_lib_path = FindFileInEnvList(env, 'LIB', ';', 'msvcrt.lib') vc_lib_atlmfc_path = FindFileInEnvList( env, 'LIB', ';', 'atls.lib', optional=True) vc_lib_um_path = FindFileInEnvList(env, 'LIB', ';', 'user32.lib') # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p] # Make include path relative to builddir when cwd and sdk in same drive. try: include = list(map(os.path.relpath, include)) except ValueError: pass lib = [p.replace('"', r'\"') for p in env['LIB'].split(';') if p] # Make lib path relative to builddir when cwd and sdk in same drive. try: lib = map(os.path.relpath, lib) except ValueError: pass def q(s): # Quote s if it contains spaces or other weird characters. return s if re.match(r'^[a-zA-Z0-9._/\\:-]*$', s) else '"' + s + '"' include_I = ' '.join([q('/I' + i) for i in include]) include_imsvc = ' '.join([q('-imsvc' + i) for i in include]) libpath_flags = ' '.join([q('-libpath:' + i) for i in lib]) if (environment_block_name != ''): env_block = _FormatAsEnvironmentBlock(env) with open(environment_block_name, 'w') as f: f.write(env_block) print('vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir)) assert include_I print('include_flags_I = ' + gn_helpers.ToGNString(include_I)) assert include_imsvc print('include_flags_imsvc = ' + gn_helpers.ToGNString(include_imsvc)) print('vc_lib_path = ' + gn_helpers.ToGNString(vc_lib_path)) # Possible atlmfc library path gets introduced in the future for store thus # output result if a result exists. if (vc_lib_atlmfc_path != ''): print('vc_lib_atlmfc_path = ' + gn_helpers.ToGNString(vc_lib_atlmfc_path)) print('vc_lib_um_path = ' + gn_helpers.ToGNString(vc_lib_um_path)) print('paths = ' + gn_helpers.ToGNString(env['PATH'])) assert libpath_flags print('libpath_flags = ' + gn_helpers.ToGNString(libpath_flags))
def main(): if len(sys.argv) != 7: print('Usage setup_toolchain.py ' '<visual studio path> <win sdk path> ' '<runtime dirs> <target_os> <target_cpu> ' '<environment block name|none>') sys.exit(2) # toolchain_root and win_sdk_path are only read if the hermetic Windows # toolchain is set, that is if DEPOT_TOOLS_WIN_TOOLCHAIN is not set to 0. # With the hermetic Windows toolchain, the visual studio path in argv[1] # is the root of the Windows toolchain directory. toolchain_root = sys.argv[1] win_sdk_path = sys.argv[2] runtime_dirs = sys.argv[3] target_os = sys.argv[4] target_cpu = sys.argv[5] environment_block_name = sys.argv[6] if (environment_block_name == 'none'): environment_block_name = '' if (target_os == 'winuwp'): target_store = True else: target_store = False cpus = ('x86', 'x64', 'arm', 'arm64') assert target_cpu in cpus vc_bin_dir = '' include = '' lib = '' # TODO(scottmg|goma): Do we need an equivalent of # ninja_use_custom_environment_files? def relflag( s): # Make s relative to builddir when cwd and sdk on same drive. try: return os.path.relpath(s).replace('\\', '/') except ValueError: return s def q(s): # Quote s if it contains spaces or other weird characters. return s if re.match(r'^[a-zA-Z0-9._/\\:-]*$', s) else '"' + s + '"' for cpu in cpus: if cpu == target_cpu: # Extract environment variables for subprocesses. env = _LoadToolchainEnv(cpu, toolchain_root, win_sdk_path, target_store) env['PATH'] = runtime_dirs + os.pathsep + env['PATH'] vc_bin_dir = FindFileInEnvList(env, 'PATH', os.pathsep, 'cl.exe') # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [ p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p ] include = list(map(relflag, include)) lib = [p.replace('"', r'\"') for p in env['LIB'].split(';') if p] lib = list(map(relflag, lib)) include_I = ' '.join([q('/I' + i) for i in include]) include_imsvc = ' '.join([q('-imsvc' + i) for i in include]) libpath_flags = ' '.join([q('-libpath:' + i) for i in lib]) if (environment_block_name != ''): env_block = _FormatAsEnvironmentBlock(env) with open(environment_block_name, 'w') as f: f.write(env_block) print('vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir)) assert include_I print('include_flags_I = ' + gn_helpers.ToGNString(include_I)) assert include_imsvc if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and win_sdk_path: print('include_flags_imsvc = ' + gn_helpers.ToGNString(q('/winsysroot' + relflag(toolchain_root)))) else: print('include_flags_imsvc = ' + gn_helpers.ToGNString(include_imsvc)) print('paths = ' + gn_helpers.ToGNString(env['PATH'])) assert libpath_flags print('libpath_flags = ' + gn_helpers.ToGNString(libpath_flags)) if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and win_sdk_path: print('libpath_lldlink_flags = ' + gn_helpers.ToGNString(q('/winsysroot:' + relflag(toolchain_root)))) else: print('libpath_lldlink_flags = ' + gn_helpers.ToGNString(libpath_flags))
def SetupToolchain(version_as_year, vs_path, include_prefix, sdk_version=None, clang_base_path=None, clang_msc_ver=None): cpus = ('x86', 'x64', 'arm', 'arm64') # vcvarsall.bat for VS 2017 fails if run after running vcvarsall.bat from # VS 2013 or VS 2015. Fix this by clearing the vsinstalldir environment # variable. if 'VSINSTALLDIR' in os.environ: del os.environ['VSINSTALLDIR'] if version_as_year == 'latest': version_as_year, vs_path = FindLatestVisualStudio() elif not vs_path or vs_path == 'default': vs_path = DetectVisualStudioPath(version_as_year) # TODO(tim): We now launch all processes at once, but this still takes too long processes = {} for (cpu, is_uwp) in itertools.product(cpus, (False, True)): suffix = '_uwp' if is_uwp else '' processes[cpu + suffix] = _Spawn( _BuildToolchainSetupCommand(vs_path, cpu, sdk_version, is_uwp)) windows_sdk_paths = {} envs = {} for (cpu, is_uwp) in itertools.product(cpus, (False, True)): suffix = '_uwp' if is_uwp else '' # Extract environment variables for subprocesses. env = _ExtractImportantEnvironment( _ProcessSpawnResult(processes[cpu + suffix])) envs[cpu + suffix] = env vc_bin_dir = '' vc_lib_path = '' vc_lib_atlmfc_path = '' vc_lib_um_path = '' for path in env['PATH'].split(os.pathsep): if os.path.exists(os.path.join(path, 'cl.exe')): vc_bin_dir = os.path.realpath(path) break if not vc_bin_dir: continue for path in env['LIB'].split(os.pathsep): if os.path.exists(os.path.join(path, 'msvcrt.lib')): vc_lib_path = os.path.realpath(path) break for path in env['LIB'].split(os.pathsep): if os.path.exists(os.path.join(path, 'atls.lib')): vc_lib_atlmfc_path = os.path.realpath(path) break for path in env['LIB'].split(os.pathsep): if os.path.exists(os.path.join(path, 'User32.Lib')): vc_lib_um_path = os.path.realpath(path) break windows_sdk_paths[cpu + suffix] = os.path.realpath( env['WINDOWSSDKDIR']) # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [include_prefix + p for p in env['INCLUDE'].split(';') if p] include = ' '.join( ['"' + i.replace('"', r'\"') + '"' for i in include]) include_flags = include env_block = _FormatAsEnvironmentBlock(env) env_filename = 'environment_{}{}'.format(cpu, suffix) with open(env_filename, 'wb') as f: f.write(env_block) print(cpu + suffix + ' = {') print( gn_helpers.ToGNString( dict(vc_bin_dir=vc_bin_dir, vc_lib_path=vc_lib_path, vc_lib_atlmfc_path=vc_lib_atlmfc_path, vc_lib_um_path=vc_lib_um_path, include_flags=include_flags, env_filename=env_filename))) print('}') if len(set(windows_sdk_paths.values())) != 1: raise Exception("WINDOWSSDKDIR is different for x86/x64") print('visual_studio_version = ' + gn_helpers.ToGNString(version_as_year)) print('visual_studio_path = ' + gn_helpers.ToGNString(vs_path)) # SDK is always the same print('windows_sdk_path = ' + gn_helpers.ToGNString(windows_sdk_paths['x86'])) # TODO(tim): Check for mismatches between x86 and x64? if clang_base_path: msc_ver = clang_msc_ver or _GetClangMscVersionFromYear(version_as_year) clang_version, msc_full_ver = _GetClangVersion(clang_base_path, msc_ver) print('clang_version = ' + gn_helpers.ToGNString(clang_version)) print('msc_ver = ' + gn_helpers.ToGNString(msc_full_ver // 100000)) print('msc_full_ver = ' + gn_helpers.ToGNString(msc_full_ver)) else: # TODO(tim): Do we want to support different toolchain versions for # different architectures? msc_full_ver = _ParseClVersion( _ProcessSpawnResult(_Spawn(['cl'], env=envs['x86']))) print('msc_ver = ' + gn_helpers.ToGNString(msc_full_ver // 100000)) print('msc_full_ver = ' + gn_helpers.ToGNString(msc_full_ver))
def test_ToGNString(self): self.assertEqual( gn_helpers.ToGNString([1, 'two', ['"thr$\\', True, False, []]]), '[ 1, "two", [ "\\"thr\\$\\\\", true, false, [ ] ] ]')
def main(): parser = argparse.ArgumentParser(description=__doc__) command_parsers = parser.add_subparsers(dest='command') subp = command_parsers.add_parser( 'list', help='Output a GN scope describing the contents of the .aar.') _AddCommonArgs(subp) subp.add_argument('--output', help='Output file.', default='-') subp = command_parsers.add_parser('extract', help='Extracts the .aar') _AddCommonArgs(subp) subp.add_argument('--output-dir', help='Output directory for the extracted files.', required=True, type=os.path.normpath) subp.add_argument('--assert-info-file', help='Path to .info file. Asserts that it matches what ' '"list" would output.', type=argparse.FileType('r')) subp.add_argument('--ignore-resources', action='store_true', help='Whether to skip extraction of res/') args = parser.parse_args() aar_info = _CreateInfo(args.aar_file) formatted_info = """\ # Generated by //build/android/gyp/aar.py # To regenerate, use "update_android_aar_prebuilts = true" and run "gn gen". """ + gn_helpers.ToGNString(aar_info, pretty=True) if args.command == 'extract': if args.assert_info_file: cached_info = args.assert_info_file.read() if formatted_info != cached_info: pass # TODO(smaier) - uncomment this as soon as possible. #raise Exception('android_aar_prebuilt() cached .info file is ' # 'out-of-date. Run gn gen with ' # 'update_android_aar_prebuilts=true to update it.') with zipfile.ZipFile(args.aar_file) as zf: names = zf.namelist() if args.ignore_resources: names = [n for n in names if not n.startswith('res')] output_paths = [os.path.join(args.output_dir, n) for n in names] output_paths.append(os.path.join(args.output_dir, 'source.info')) def on_stale_md5(): _PerformExtract(args.aar_file, args.output_dir, set(names)) md5_check.CallAndRecordIfStale(on_stale_md5, input_strings=[aar_info], input_paths=[args.aar_file], output_paths=output_paths) elif args.command == 'list': aar_output_present = args.output != '-' and os.path.isfile(args.output) if aar_output_present: # Some .info files are read-only, for examples the cipd-controlled ones # under third_party/android_deps/repositoty. To deal with these, first # that its content is correct, and if it is, exit without touching # the file system. file_info = open(args.output, 'r').read() if file_info == formatted_info: return # Try to write the file. This may fail for read-only ones that were # not updated. try: with open(args.output, 'w') as f: f.write(formatted_info) except IOError as e: if not aar_output_present: raise e raise Exception('Could not update output file: %s\n%s\n' % (args.output, e))
def test_ToGNString(self): test_cases = [ (42, '42', '42'), ('foo', '"foo"', '"foo"'), (True, 'true', 'true'), (False, 'false', 'false'), ('', '""', '""'), ('\\$"$\\', '"\\\\\\$\\"\\$\\\\"', '"\\\\\\$\\"\\$\\\\"'), (' \t\r\n', '" $0x09$0x0D$0x0A"', '" $0x09$0x0D$0x0A"'), (u'\u2713', '"$0xE2$0x9C$0x93"', '"$0xE2$0x9C$0x93"'), ([], '[ ]', '[]'), ([1], '[ 1 ]', '[\n 1\n]\n'), ([3, 1, 4, 1], '[ 3, 1, 4, 1 ]', '[\n 3,\n 1,\n 4,\n 1\n]\n'), (['a', True, 2], '[ "a", true, 2 ]', '[\n "a",\n true,\n 2\n]\n'), ({ 'single': 'item' }, 'single = "item"\n', 'single = "item"\n'), ({ 'kEy': 137, '_42A_Zaz_': [False, True] }, '_42A_Zaz_ = [ false, true ]\nkEy = 137\n', '_42A_Zaz_ = [\n false,\n true\n]\nkEy = 137\n'), ([1, 'two', ['"thr,.$\\', True, False, [], u'(\u2713)'] ], '[ 1, "two", [ "\\"thr,.\\$\\\\", true, false, ' + '[ ], "($0xE2$0x9C$0x93)" ] ]', '''[ 1, "two", [ "\\"thr,.\\$\\\\", true, false, [], "($0xE2$0x9C$0x93)" ] ] '''), ({ 's': 'foo', 'n': 42, 'b': True, 'a': [3, 'x'] }, 'a = [ 3, "x" ]\nb = true\nn = 42\ns = "foo"\n', 'a = [\n 3,\n "x"\n]\nb = true\nn = 42\ns = "foo"\n'), ( [[[], [[]]], []], '[ [ [ ], [ [ ] ] ], [ ] ]', '[\n [\n [],\n [\n []\n ]\n ],\n []\n]\n', ), ( [{ 'a': 1, 'c': { 'z': 8 }, 'b': [] }], '[ { a = 1\nb = [ ]\nc = { z = 8 } } ]\n', '[\n {\n a = 1\n b = []\n c = {\n' + ' z = 8\n }\n }\n]\n', ) ] for obj, exp_ugly, exp_pretty in test_cases: out_ugly = gn_helpers.ToGNString(obj) self.assertEqual(exp_ugly, out_ugly) out_pretty = gn_helpers.ToGNString(obj, pretty=True) self.assertEqual(exp_pretty, out_pretty)
def main(): if len(sys.argv) != 6 and len(sys.argv) != 3: print( 'Usage setup_toolchain.py ' '<visual studio path> <win sdk path> ' '<runtime dirs> <target_cpu> <include prefix>') print('or setup_toolchain.py <target_cpu> <include prefix>') sys.exit(2) if len(sys.argv) == 6: win_sdk_path = sys.argv[2] runtime_dirs = sys.argv[3] target_cpu = sys.argv[4] include_prefix = sys.argv[5] else: target_cpu = sys.argv[1] include_prefix = sys.argv[2] cpus = ('x86', 'x64') assert target_cpu in cpus vc_bin_dir = '' include = '' ninja_use_custom_environment_files = (len(sys.argv) == 6) for cpu in cpus: # Extract environment variables for subprocesses. if not ninja_use_custom_environment_files: env = os.environ else: env = _LoadToolchainEnv(cpu, win_sdk_path) env['PATH'] = runtime_dirs + os.pathsep + env['PATH'] if cpu == target_cpu: for path in env['PATH'].split(os.pathsep): if os.path.exists(os.path.join(path, 'cl.exe')): vc_bin_dir = os.path.realpath(path) break # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [ include_prefix + p for p in env['INCLUDE'].split(';') if p ] include = ' '.join( ['"' + i.replace('"', r'\"') + '"' for i in include]) env_block = _FormatAsEnvironmentBlock(env) with open('environment.' + cpu, 'wb') as f: f.write(env_block) # Create a store app version of the environment. # If using environment it should already be correct, and changing it # would break the normal build if ninja_use_custom_environment_files: if 'LIB' in env: env['LIB'] = env['LIB'].replace(r'\VC\LIB', r'\VC\LIB\STORE') if 'LIBPATH' in env: env['LIBPATH'] = env['LIBPATH'].replace( r'\VC\LIB', r'\VC\LIB\STORE') env_block = _FormatAsEnvironmentBlock(env) with open('environment.winrt_' + cpu, 'wb') as f: f.write(env_block) assert vc_bin_dir print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) assert include print 'include_flags = ' + gn_helpers.ToGNString(include)
def main(): if len(sys.argv) != 8: print( 'Usage setup_toolchain.py ' '<visual studio path> <win sdk path> ' '<runtime dirs> <target_os> <target_cpu> ' '<environment block name|none> <goma_disabled>') sys.exit(2) win_sdk_path = sys.argv[2] runtime_dirs = sys.argv[3] target_os = sys.argv[4] target_cpu = sys.argv[5] environment_block_name = sys.argv[6] if (environment_block_name == 'none'): environment_block_name = '' goma_disabled = sys.argv[7] if (target_os == 'winuwp'): target_store = True else: target_store = False cpus = ('x86', 'x64', 'arm', 'arm64') assert target_cpu in cpus vc_bin_dir = '' vc_lib_path = '' vc_lib_atlmfc_path = '' vc_lib_um_path = '' include = '' # TODO(scottmg|goma): Do we need an equivalent of # ninja_use_custom_environment_files? for cpu in cpus: if cpu == target_cpu: # Extract environment variables for subprocesses. env = _LoadToolchainEnv(cpu, win_sdk_path, target_store) env['PATH'] = runtime_dirs + os.pathsep + env['PATH'] env['GOMA_DISABLED'] = goma_disabled for path in env['PATH'].split(os.pathsep): if os.path.exists(os.path.join(path, 'cl.exe')): vc_bin_dir = os.path.realpath(path) break for path in env['LIB'].split(';'): if os.path.exists(os.path.join(path, 'msvcrt.lib')): vc_lib_path = os.path.realpath(path) break for path in env['LIB'].split(';'): if os.path.exists(os.path.join(path, 'atls.lib')): vc_lib_atlmfc_path = os.path.realpath(path) break for path in env['LIB'].split(';'): if os.path.exists(os.path.join(path, 'User32.Lib')): vc_lib_um_path = os.path.realpath(path) break # The separator for INCLUDE here must match the one used in # _LoadToolchainEnv() above. include = [ p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p ] include_I = ' '.join(['"/I' + i + '"' for i in include]) include_imsvc = ' '.join(['"-imsvc' + i + '"' for i in include]) if (environment_block_name != ''): env_block = _FormatAsEnvironmentBlock(env) with open(environment_block_name, 'wb') as f: f.write(env_block) assert vc_bin_dir print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) assert include_I print 'include_flags_I = ' + gn_helpers.ToGNString(include_I) assert include_imsvc print 'include_flags_imsvc = ' + gn_helpers.ToGNString(include_imsvc) assert vc_lib_path print 'vc_lib_path = ' + gn_helpers.ToGNString(vc_lib_path) if (target_store != True): # Path is assumed not to exist for desktop applications assert vc_lib_atlmfc_path # Possible atlmfc library path gets introduced in the future for store thus # output result if a result exists. if (vc_lib_atlmfc_path != ''): print 'vc_lib_atlmfc_path = ' + gn_helpers.ToGNString( vc_lib_atlmfc_path) assert vc_lib_um_path print 'vc_lib_um_path = ' + gn_helpers.ToGNString(vc_lib_um_path) print 'paths = ' + gn_helpers.ToGNString(env['PATH'])