#!/usr/bin/env python import argparse import glob import os import shlex import subprocess import sys top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if '--xwalk' in sys.argv: xwalk_dir = os.path.join(top_dir, '..', 'xwalk') sys.argv.remove('--xwalk') else: xwalk_dir = None chrome_src = os.environ.get('CHROME_SRC') if chrome_src: chrome_src = os.path.abspath(chrome_src) if not chrome_src or not os.path.isdir(chrome_src): chrome_src = os.path.join(top_dir, '..') print 'CHROME_SRC not set, falling back to ' + chrome_src script_dir = os.path.abspath(os.path.join(chrome_src, 'build')) if not os.path.isdir(script_dir): print script_dir + " is not a valid directory" sys.exit(1) sys.path.insert(0, script_dir) import gyp_helper sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) import gyp import gyp.generator.ninja def gyp_ninja_override_CalculateVariables(default_variables, params): """Calculate additional variables for use in the build (called by gyp).""" default_variables.setdefault('OS', 'linux') default_variables.setdefault('gcc_version', '49') default_variables.setdefault('SHARED_LIB_SUFFIX', '.so') default_variables.setdefault('SHARED_LIB_DIR', os.path.join('$!PRODUCT_DIR', 'lib')) # Take into account the fact that toplevel_dir might not be equal to depth toplevel_offset = '' if 'options' in params: options = params['options'] toplevel_offset = os.path.relpath(options.depth, options.toplevel_dir) default_variables.setdefault('LIB_DIR', os.path.join('$!PRODUCT_DIR', 'obj', toplevel_offset)) # Override CalculateVariables functions in gyp ninja generator instead of patching gyp. gyp.generator.ninja.CalculateVariables = gyp_ninja_override_CalculateVariables # Add paths so that pymod_do_main(...) can import files. sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers')) sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit')) sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', 'Source', 'core', 'core.gyp', 'scripts')) # Remove the above and keep the line below once we require a newer specific # Chromium revision. sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', 'Source', 'build', 'scripts')) sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build')) sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build')) import repack_locales def additional_include_files(args=[]): """ Returns a list of additional (.gypi) files to include, without duplicating ones that are already specified on the command line. """ # Determine the include files specified on the command line. # This doesn't cover all the different option formats you can use, # but it's mainly intended to avoid duplicating flags on the automatic # makefile regeneration which only uses this format. specified_includes = set() for arg in args: if arg.startswith('-I') and len(arg) > 2: specified_includes.add(os.path.realpath(arg[2:])) result = [] def AddInclude(path): if os.path.realpath(path) not in specified_includes: result.append(path) # Include xwalk common.gypi to effect chromium source tree. if xwalk_dir: AddInclude(os.path.join(xwalk_dir, 'build', 'common.gypi')) # Always include common.gypi. AddInclude(os.path.join(script_dir, 'common.gypi')) # Optionally add supplemental .gypi files if present. supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) for supplement in supplements: AddInclude(supplement) return result def GetOutputDirectory(): """Returns the output directory that GYP will use.""" # Handle command line generator flags. parser = argparse.ArgumentParser() parser.add_argument('-G', dest='genflags', default=[], action='append') genflags = parser.parse_known_args()[0].genflags # Handle generator flags from the environment. genflags += shlex.split(os.environ.get('GYP_GENERATOR_FLAGS', '')) needle = 'output_dir=' for item in genflags: if item.startswith(needle): return item[len(needle):] return 'out' if __name__ == '__main__': args = sys.argv[1:] # On Mac we want to override CXX and CC that is provided with # the Chromium GYP environment. if sys.platform.startswith('darwin'): os.environ['CXX'] = 'clang++' os.environ['CC'] = 'clang' gyp_helper.apply_chromium_gyp_env() # 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 not gyp_file_specified: args.append(os.path.join(top_dir, 'ewk', 'chromium-ewk.gyp')) if xwalk_dir: args.append(os.path.join(xwalk_dir, 'xwalk.gyp')) args.extend(['-I' + i for i in additional_include_files(args)]) # On Mac we want to build in x64 mode. And we want to use libc++. # Even though we are not on linux, it seems we specifically have to disable linux_use_tcmalloc. if sys.platform in ('darwin',): args.extend(['-D', 'host_arch=x64', '-D', 'use_libcpp=1', '-D', 'linux_use_tcmalloc=0']) # 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 the Mac, 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 sys.platform not in ('darwin',): args.append('--no-circular-check') # the top_level source directory is the first common ancestor of our module and the chromium source tree for the build to be sane. # commonprefix works on a character basis, so it might return a phony common prefix (not the common parent directory we expect), toplevel= os.path.commonprefix([top_dir, chrome_src]) if not os.path.exists(toplevel): toplevel = os.path.join(toplevel, os.pardir) args.extend(["--toplevel-dir=" + toplevel]) # Tweak the output location. args.extend(['--generator-output', os.path.abspath(GetOutputDirectory())]) args.extend(['-Goutput_dir='+ os.path.abspath(GetOutputDirectory())]) args.append("--check") # gyp on gbs fails with multiprocessing.SemLock() not implemented # disabling parallel gyp for gbs gbs_build = os.environ.get('BUILDING_WITH_GBS') if gbs_build: args.append("--no-parallel") # TODO(b.kelemen): remove the condition once gyp_trunk.py has landed. if os.path.exists(os.path.join(script_dir, 'gyp_trunk.py')): # gyp_trunk works on sys.argv so we merge |args| back. sys.argv = [sys.argv[0]] + args import gyp_trunk gyp_trunk.overwrite_arguments() args = sys.argv[1:] print 'Updating projects from gyp files...' # Off we go... sys.exit(gyp.main(args))