10 top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
11 chrome_src = os.environ.get('CHROME_SRC')
13 chrome_src = os.path.abspath(chrome_src)
14 if not chrome_src or not os.path.isdir(chrome_src):
15 chrome_src = os.path.join(top_dir, '..')
16 print ('CHROME_SRC not set, falling back to ' + chrome_src)
18 script_dir = os.path.abspath(os.path.join(chrome_src, 'build'))
19 if not os.path.isdir(script_dir):
20 print (script_dir + " is not a valid directory")
23 sys.path.insert(0, script_dir)
27 # Add paths so that pymod_do_main(...) can import files.
28 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers'))
29 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
31 # Remove the above and keep the line below once we require a newer specific
33 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit',
34 'Source', 'build', 'scripts'))
35 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
36 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
38 def GetOutputDirectory():
39 """Returns the output directory that GN will use."""
41 # Handle command line generator flags.
42 parser = argparse.ArgumentParser()
43 parser.add_argument('-G', dest='genflags', default=[], action='append')
44 genflags = parser.parse_known_args()[0].genflags
46 # Handle generator flags from the environment.
47 genflags += shlex.split(os.environ.get('GN_GENERATOR_FLAGS', ''))
49 needle = 'output_dir='
51 if item.startswith(needle):
52 return item[len(needle):]
57 if __name__ == '__main__':
61 for i in range(len(sys.argv)):
63 args[arg] += " " + sys.argv[i];
64 if sys.argv[i] in ('target_os="tizen"'):
67 if sys.argv[i] in ("--args="):
68 args.append(sys.argv[i])
71 args.append(sys.argv[i])
73 # On Mac we want to override CXX and CC that is provided with
74 # the Chromium GYP environment.
75 if sys.platform.startswith('darwin'):
76 os.environ['CXX'] = 'clang++'
77 os.environ['CC'] = 'clang'
79 #gyp_helper.apply_chromium_gyp_env()
81 # args.extend(['-I' + i for i in additional_include_files(args)])
83 # On Mac we want to build in x64 mode. And we want to use libc++.
84 # Even though we are not on linux, it seems we specifically have to disable linux_use_tcmalloc.
85 if sys.platform in ('darwin',):
86 args[arg] += " host_arch=\"x64\" use_libcpp=true linux_use_tcmalloc=false"
88 # There shouldn't be a circular dependency relationship between .gyp files,
89 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
90 # currently exist. The check for circular dependencies is currently
91 # bypassed on other platforms, but is left enabled on the Mac, where a
92 # violation of the rule causes Xcode to misbehave badly.
93 # TODO(mark): Find and kill remaining circular dependencies, and remove this
94 # option. http://crbug.com/35878.
95 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
97 #if sys.platform not in ('darwin',):
98 # args[arg] += " no_circular_check=true"
100 # the top_level source directory is the first common ancestor of our module and the chromium source tree for the build to be sane.
101 # commonprefix works on a character basis, so it might return a phony common prefix (not the common parent directory we expect),
102 toplevel= os.path.commonprefix([top_dir, chrome_src])
104 if not os.path.exists(toplevel):
105 toplevel = os.path.join(toplevel, os.pardir)
106 #args[arg] += " toplevel-dir=\"" + toplevel + "\""
107 # Tweak the output location.
108 #args[arg] += "generator-output=\"" + os.path.abspath(GetOutputDirectory()) + "\""
109 #args[arg] += " Goutput_dir=\"" + os.path.abspath(GetOutputDirectory()) + "\""
110 #args[arg] += " check=true"
112 # gyp on gbs fails with multiprocessing.SemLock() not implemented
113 # disabling parallel gyp for gbs
114 gbs_build = os.environ.get('BUILDING_WITH_GBS')
116 #args[arg] += " no-parallel=true"
118 os.environ["CHROMIUM_BUILDTOOLS_PATH"]=os.path.join(chrome_src, "buildtools")
120 #notifications -> enable_notifications in build/config/features.gni
121 #args[arg] += " ewk_bringup=false notifications=false"
123 args[arg] += " gcc_version=49" # It should be in condition for arm target
125 buildtools_path = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
126 host_arch = os.environ.get('HOST_ARCH')
127 if not buildtools_path:
128 print ("build tool path is empty")
131 if sys.platform.startswith(('cygwin', 'win')):
133 elif sys.platform == 'darwin':
135 elif target_os == 'linux':
137 elif target_os == 'tizen':
138 buildtools_path = os.path.join(buildtools_path, "../tizen_src/")
139 subdir = 'buildtools'
141 raise Error('The subdir is not set.')
143 bin_path = os.path.join(buildtools_path, subdir)
146 if sys.platform.startswith(('cygwin', 'win')):
148 elif target_os == 'linux' or target_os == 'tizen':
151 gn_path = os.path.join(bin_path, 'gn' + exeSuffix)
152 if not os.path.exists(gn_path):
153 print ('Could not find gn executable at: %s' % gn_path)
156 print ('Updating projects from gn files...')
157 sys.exit(subprocess.call([gn_path] + args[1:]))