def GetSvnRevision(svn_repo): """Returns current revision of the svn repo at svn_repo.""" if sys.platform == 'darwin': # mac_files toolchain must be set for hermetic builds. root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) sys.path.append(os.path.join(root, 'build')) import mac_toolchain mac_toolchain.SetToolchainEnvironment() svn_info = subprocess.check_output('svn info ' + svn_repo, shell=True) m = re.search(r'Revision: (\d+)', svn_info) return m.group(1)
def SetEnvironment(): """Sets defaults for GYP_* variables.""" gyp_helper.apply_chromium_gyp_env() # Default to ninja on linux and windows, but only if no generator has # explicitly been set. # Also default to ninja on mac, but only when not building chrome/ios. # . -f / --format has precedence over the env var, no need to check for it # . set the env var only if it hasn't been set yet # . chromium.gyp_env has been applied to os.environ at this point already if sys.platform.startswith(('linux', 'win', 'freebsd', 'darwin')) and \ not os.environ.get('GYP_GENERATORS'): os.environ['GYP_GENERATORS'] = 'ninja' vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() mac_toolchain.SetToolchainEnvironment()
def main(): parser = OptionParser() parser.add_option( "--verify", action="store_true", dest="verify", default=False, help="return the sdk argument and warn if it doesn't exist") parser.add_option("--sdk_path", action="store", type="string", dest="sdk_path", default="", help="user-specified SDK path; bypasses verification") parser.add_option( "--print_sdk_path", action="store_true", dest="print_sdk_path", default=False, help="Additionaly print the path the SDK (appears first).") options, args = parser.parse_args() if len(args) != 1: parser.error('Please specify a minimum SDK version') min_sdk_version = args[0] # Try using the toolchain in mac_files. mac_toolchain.SetToolchainEnvironment() job = subprocess.Popen(['xcode-select', '-print-path'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = job.communicate() if job.returncode != 0: print >> sys.stderr, out print >> sys.stderr, err raise Exception('Error %d running xcode-select' % job.returncode) sdk_dir = os.path.join(out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') sdks = [ re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir) ] sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] sdks = [ s for s in sdks # ['10.5', '10.6'] => ['10.6'] if parse_version(s) >= parse_version(min_sdk_version) ] if not sdks: raise Exception('No %s+ SDK found' % min_sdk_version) best_sdk = sorted(sdks, key=parse_version)[0] if options.verify and best_sdk != min_sdk_version and not options.sdk_path: print >> sys.stderr, '' print >> sys.stderr, ' vvvvvvv' print >> sys.stderr, '' print >> sys.stderr, \ 'This build requires the %s SDK, but it was not found on your system.' \ % min_sdk_version print >> sys.stderr, \ 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' print >> sys.stderr, '' print >> sys.stderr, ' ^^^^^^^' print >> sys.stderr, '' return min_sdk_version if options.print_sdk_path: print subprocess.check_output( ['xcrun', '-sdk', 'macosx' + best_sdk, '--show-sdk-path']).strip() return best_sdk
def main(): # Disabling garbage collection saves about 1 second out of 16 on a Linux # z620 workstation. Since this is a short-lived process it's not a problem to # leak a few cyclyc references in order to spare the CPU cycles for # scanning the heap. gc.disable() args = sys.argv[1:] use_analyzer = len(args) and args[0] == '--analyzer' if use_analyzer: args.pop(0) os.environ['GYP_GENERATORS'] = 'analyzer' args.append('-Gconfig_path=' + args.pop(0)) args.append('-Ganalyzer_output_path=' + args.pop(0)) gyp_chromium_no_action = os.environ.get('GYP_CHROMIUM_NO_ACTION') if gyp_chromium_no_action == '1': print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.' sys.exit(0) # Use the Psyco JIT if available. if psyco: psyco.profile() print "Enabled Psyco JIT." # Fall back on hermetic python if we happen to get run under cygwin. # TODO(bradnelson): take this out once this issue is fixed: # http://code.google.com/p/gyp/issues/detail?id=177 if sys.platform == 'cygwin': import find_depot_tools depot_tools_path = find_depot_tools.add_depot_tools_to_path() python_dir = sorted( glob.glob(os.path.join(depot_tools_path, 'python2*_bin')))[-1] env = os.environ.copy() env['PATH'] = python_dir + os.pathsep + env.get('PATH', '') cmd = [os.path.join(python_dir, 'python.exe')] + sys.argv sys.exit(subprocess.call(cmd, env=env)) # This could give false positives since it doesn't actually do real option # parsing. Oh well. gyp_file_specified = any(arg.endswith('.gyp') for arg in args) gyp_environment.SetEnvironment() # If we didn't get a file, check an env var, and then fall back to # assuming 'all.gyp' from the same directory as the script. if not gyp_file_specified: gyp_file = os.environ.get('CHROMIUM_GYP_FILE') if gyp_file: # Note that CHROMIUM_GYP_FILE values can't have backslashes as # path separators even on Windows due to the use of shlex.split(). args.extend(shlex.split(gyp_file)) else: args.append(os.path.join(script_dir, 'all.gyp')) supplemental_includes = GetSupplementalFiles() gyp_vars_dict = GetGypVars(supplemental_includes) # There shouldn't be a circular dependency relationship between .gyp files, # but in Chromium's .gyp files, on non-Mac platforms, circular relationships # currently exist. The check for circular dependencies is currently # bypassed on other platforms, but is left enabled on iOS, where a violation # of the rule causes Xcode to misbehave badly. # TODO(mark): Find and kill remaining circular dependencies, and remove this # option. http://crbug.com/35878. # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the # list. if gyp_vars_dict.get('OS') != 'ios': args.append('--no-circular-check') # libtool on Mac warns about duplicate basenames in static libraries, so # they're disallowed in general by gyp. We are lax on this point, so disable # this check other than on Mac. GN does not use static libraries as heavily, # so over time this restriction will mostly go away anyway, even on Mac. # https://code.google.com/p/gyp/issues/detail?id=384 if sys.platform != 'darwin': args.append('--no-duplicate-basename-check') # We explicitly don't support the make gyp generator (crbug.com/348686). Be # nice and fail here, rather than choking in gyp. if re.search(r'(^|,|\s)make($|,|\s)', os.environ.get('GYP_GENERATORS', '')): print 'Error: make gyp generator not supported (check GYP_GENERATORS).' sys.exit(1) # We explicitly don't support the native msvs gyp generator. Be nice and # fail here, rather than generating broken projects. if re.search(r'(^|,|\s)msvs($|,|\s)', os.environ.get('GYP_GENERATORS', '')): print 'Error: msvs gyp generator not supported (check GYP_GENERATORS).' print 'Did you mean to use the `msvs-ninja` generator?' sys.exit(1) # We explicitly don't support the native xcode gyp generator. Be nice and # fail here, rather than generating broken projects. if re.search(r'(^|,|\s)xcode($|,|\s)', os.environ.get('GYP_GENERATORS', '')): print 'Error: xcode gyp generator not supported (check GYP_GENERATORS).' print 'Did you mean to use the `xcode-ninja` generator?' sys.exit(1) # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check # to enfore syntax checking. syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') if syntax_check and int(syntax_check): args.append('--check') # TODO(dmikurube): Remove these checks and messages after a while. if ('linux_use_tcmalloc' in gyp_vars_dict or 'android_use_tcmalloc' in gyp_vars_dict): print '*****************************************************************' print '"linux_use_tcmalloc" and "android_use_tcmalloc" are deprecated!' print '-----------------------------------------------------------------' print 'You specify "linux_use_tcmalloc" or "android_use_tcmalloc" in' print 'your GYP_DEFINES. Please switch them into "use_allocator" now.' print 'See http://crbug.com/345554 for the details.' print '*****************************************************************' # Automatically turn on crosscompile support for platforms that need it. # (The Chrome OS build sets CC_host / CC_target which implicitly enables # this mode.) if all(('ninja' in os.environ.get('GYP_GENERATORS', ''), gyp_vars_dict.get('OS') in ['android', 'ios'], 'GYP_CROSSCOMPILE' not in os.environ)): os.environ['GYP_CROSSCOMPILE'] = '1' if gyp_vars_dict.get('OS') == 'android': args.append('--check') args.extend([ '-I' + i for i in additional_include_files(supplemental_includes, args) ]) args.extend(['-D', 'gyp_output_dir=' + GetOutputDirectory()]) mac_toolchain_dir = mac_toolchain.GetToolchainDirectory() if mac_toolchain_dir: args.append('-Gmac_toolchain_dir=' + mac_toolchain_dir) mac_toolchain.SetToolchainEnvironment() running_as_hook = '--running-as-hook' if running_as_hook in args and gyp_chromium_no_action != '0': print 'GYP is now disabled by default in runhooks.\n' print 'If you really want to run this, either run ' print '`python build/gyp_chromium.py` explicitly by hand' print 'or set the environment variable GYP_CHROMIUM_NO_ACTION=0.' sys.exit(0) if running_as_hook in args: args.remove(running_as_hook) if not use_analyzer: print 'Updating projects from gyp files...' sys.stdout.flush() # Off we go... gyp_rc = gyp.main(args) if gyp_rc == 0 and not use_analyzer: vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs( ) if vs2013_runtime_dll_dirs: x64_runtime, x86_runtime = vs2013_runtime_dll_dirs vs_toolchain.CopyVsRuntimeDlls( os.path.join(chrome_src, GetOutputDirectory()), (x86_runtime, x64_runtime)) sys.exit(gyp_rc)
['xcrun', '-sdk', platform, '--show-sdk-path']).strip() settings['sdk_version'] = subprocess.check_output( ['xcrun', '-sdk', platform, '--show-sdk-version']).strip() settings['sdk_platform_path'] = subprocess.check_output( ['xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip() # TODO: unconditionally use --show-sdk-build-version once Xcode 7.2 or # higher is required to build Chrome for iOS or OS X. if xcode_version >= '0720': settings['sdk_build'] = subprocess.check_output( ['xcrun', '-sdk', platform, '--show-sdk-build-version']).strip() else: settings['sdk_build'] = settings['sdk_version'] if __name__ == '__main__': if len(sys.argv) != 2: sys.stderr.write('usage: %s [iphoneos|iphonesimulator|macosx]\n' % os.path.basename(sys.argv[0])) sys.exit(1) # Try using the toolchain in mac_files. mac_toolchain.SetToolchainEnvironment() settings = {} FillMachineOSBuild(settings) FillXcodeVersion(settings) FillSDKPathAndVersion(settings, sys.argv[1], settings['xcode_version']) for key in sorted(settings): print '%s="%s"' % (key, settings[key])