Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: pylib/gyp/generator/make.py

Issue 2122004: Add a flag to generate the Makefile in a different directory than... (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pylib/gyp/__init__.py ('k') | test/toplevel-dir/gyptest-toplevel-dir.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2009 Google Inc. All rights reserved. 3 # Copyright (c) 2009 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Notes: 7 # Notes:
8 # 8 #
9 # This is all roughly based on the Makefile system used by the Linux 9 # This is all roughly based on the Makefile system used by the Linux
10 # kernel, but is a non-recursive make -- we put the entire dependency 10 # kernel, but is a non-recursive make -- we put the entire dependency
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 # Paths in gyp files are relative to the .gyp file, but we want 1151 # Paths in gyp files are relative to the .gyp file, but we want
1152 # paths relative to the source root for the master makefile. Grab 1152 # paths relative to the source root for the master makefile. Grab
1153 # the path of the .gyp file as the base to relativize against. 1153 # the path of the .gyp file as the base to relativize against.
1154 # E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp". 1154 # E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp".
1155 base_path = gyp.common.RelativePath(os.path.dirname(build_file), 1155 base_path = gyp.common.RelativePath(os.path.dirname(build_file),
1156 options.depth) 1156 options.depth)
1157 # We write the file in the base_path directory. 1157 # We write the file in the base_path directory.
1158 output_file = os.path.join(options.depth, base_path, base_name) 1158 output_file = os.path.join(options.depth, base_path, base_name)
1159 if options.generator_output: 1159 if options.generator_output:
1160 output_file = os.path.join(options.generator_output, output_file) 1160 output_file = os.path.join(options.generator_output, output_file)
1161 return (base_path, output_file) 1161 base_path = gyp.common.RelativePath(os.path.dirname(build_file),
1162 options.toplevel_dir)
1163 return base_path, output_file
1162 1164
1163 # TODO: search for the first non-'Default' target. This can go 1165 # TODO: search for the first non-'Default' target. This can go
1164 # away when we add verification that all targets have the 1166 # away when we add verification that all targets have the
1165 # necessary configurations. 1167 # necessary configurations.
1166 default_configuration = None 1168 default_configuration = None
1167 toolsets = set([target_dicts[target]['toolset'] for target in target_list]) 1169 toolsets = set([target_dicts[target]['toolset'] for target in target_list])
1168 for target in target_list: 1170 for target in target_list:
1169 spec = target_dicts[target] 1171 spec = target_dicts[target]
1170 if spec['default_configuration'] != 'Default': 1172 if spec['default_configuration'] != 'Default':
1171 default_configuration = spec['default_configuration'] 1173 default_configuration = spec['default_configuration']
1172 break 1174 break
1173 if not default_configuration: 1175 if not default_configuration:
1174 default_configuration = 'Default' 1176 default_configuration = 'Default'
1175 1177
1176 srcdir = '.' 1178 srcdir = '.'
1177 makefile_name = 'Makefile' + options.suffix 1179 makefile_name = 'Makefile' + options.suffix
1178 makefile_path = os.path.join(options.depth, makefile_name) 1180 makefile_path = os.path.join(options.toplevel_dir, makefile_name)
1179 if options.generator_output: 1181 if options.generator_output:
1180 global srcdir_prefix 1182 global srcdir_prefix
1181 makefile_path = os.path.join(options.generator_output, makefile_path) 1183 makefile_path = os.path.join(options.generator_output, makefile_path)
1182 srcdir = gyp.common.RelativePath(srcdir, options.generator_output) 1184 srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
1183 srcdir_prefix = '$(srcdir)/' 1185 srcdir_prefix = '$(srcdir)/'
1184 ensure_directory_exists(makefile_path) 1186 ensure_directory_exists(makefile_path)
1185 root_makefile = open(makefile_path, 'w') 1187 root_makefile = open(makefile_path, 'w')
1186 root_makefile.write(SHARED_HEADER_SRCDIR % srcdir) 1188 root_makefile.write(SHARED_HEADER_SRCDIR % srcdir)
1187 root_makefile.write(SHARED_HEADER_BUILDDIR_NAME % builddir_name) 1189 root_makefile.write(SHARED_HEADER_BUILDDIR_NAME % builddir_name)
1188 root_makefile.write(SHARED_HEADER.replace('__default_configuration__', 1190 root_makefile.write(SHARED_HEADER.replace('__default_configuration__',
1189 default_configuration)) 1191 default_configuration))
1190 for toolset in toolsets: 1192 for toolset in toolsets:
1191 root_makefile.write('TOOLSET := %s\n' % toolset) 1193 root_makefile.write('TOOLSET := %s\n' % toolset)
1192 root_makefile.write(ROOT_HEADER_SUFFIX_RULES) 1194 root_makefile.write(ROOT_HEADER_SUFFIX_RULES)
1193 1195
1194 # Find the list of targets that derive from the gyp file(s) being built. 1196 # Find the list of targets that derive from the gyp file(s) being built.
1195 needed_targets = set() 1197 needed_targets = set()
1196 for build_file in params['build_files']: 1198 for build_file in params['build_files']:
1197 for target in gyp.common.AllTargets(target_list, target_dicts, build_file): 1199 for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
1198 needed_targets.add(target) 1200 needed_targets.add(target)
1199 1201
1200 build_files = set() 1202 build_files = set()
1201 include_list = set() 1203 include_list = set()
1202 for qualified_target in target_list: 1204 for qualified_target in target_list:
1203 build_file, target, toolset = gyp.common.ParseQualifiedTarget( 1205 build_file, target, toolset = gyp.common.ParseQualifiedTarget(
1204 qualified_target) 1206 qualified_target)
1205 build_files.add(gyp.common.RelativePath(build_file, options.depth)) 1207 build_files.add(gyp.common.RelativePath(build_file, options.toplevel_dir))
1206 included_files = data[build_file]['included_files'] 1208 included_files = data[build_file]['included_files']
1207 for included_file in included_files: 1209 for included_file in included_files:
1208 # The included_files entries are relative to the dir of the build file 1210 # The included_files entries are relative to the dir of the build file
1209 # that included them, so we have to undo that and then make them relative 1211 # that included them, so we have to undo that and then make them relative
1210 # to the root dir. 1212 # to the root dir.
1211 relative_include_file = gyp.common.RelativePath( 1213 relative_include_file = gyp.common.RelativePath(
1212 gyp.common.UnrelativePath(included_file, build_file), options.depth) 1214 gyp.common.UnrelativePath(included_file, build_file),
1215 options.toplevel_dir)
1213 abs_include_file = os.path.abspath(relative_include_file) 1216 abs_include_file = os.path.abspath(relative_include_file)
1214 # If the include file is from the ~/.gyp dir, we should use absolute path 1217 # If the include file is from the ~/.gyp dir, we should use absolute path
1215 # so that relocating the src dir doesn't break the path. 1218 # so that relocating the src dir doesn't break the path.
1216 if (params['home_dot_gyp'] and 1219 if (params['home_dot_gyp'] and
1217 abs_include_file.startswith(params['home_dot_gyp'])): 1220 abs_include_file.startswith(params['home_dot_gyp'])):
1218 build_files.add(abs_include_file) 1221 build_files.add(abs_include_file)
1219 else: 1222 else:
1220 build_files.add(relative_include_file) 1223 build_files.add(relative_include_file)
1221 1224
1222 (base_path, output_file) = CalculateMakefilePath(build_file, 1225 base_path, output_file = CalculateMakefilePath(build_file,
1223 target + '.' + toolset + options.suffix + '.mk') 1226 target + '.' + toolset + options.suffix + '.mk')
1224 1227
1225 spec = target_dicts[qualified_target] 1228 spec = target_dicts[qualified_target]
1226 configs = spec['configurations'] 1229 configs = spec['configurations']
1227 1230
1228 writer = MakefileWriter() 1231 writer = MakefileWriter()
1229 writer.Write(qualified_target, base_path, output_file, spec, configs, 1232 writer.Write(qualified_target, base_path, output_file, spec, configs,
1230 part_of_all=qualified_target in needed_targets) 1233 part_of_all=qualified_target in needed_targets)
1231 1234
1232 # Our root_makefile lives at the source root. Compute the relative path 1235 # Our root_makefile lives at the source root. Compute the relative path
1233 # from there to the output_file for including. 1236 # from there to the output_file for including.
1234 mkfile_rel_path = gyp.common.RelativePath(output_file, 1237 mkfile_rel_path = gyp.common.RelativePath(output_file,
1235 os.path.dirname(makefile_path)) 1238 os.path.dirname(makefile_path))
1236 include_list.add('include ' + mkfile_rel_path + '\n') 1239 include_list.add('include ' + mkfile_rel_path + '\n')
1237 1240
1238 # Write out per-gyp (sub-project) Makefiles. 1241 # Write out per-gyp (sub-project) Makefiles.
1239 depth_rel_path = gyp.common.RelativePath(options.depth, os.getcwd()) 1242 depth_rel_path = gyp.common.RelativePath(options.depth, os.getcwd())
1240 for build_file in build_files: 1243 for build_file in build_files:
1241 # The paths in build_files were relativized above, so undo that before 1244 # The paths in build_files were relativized above, so undo that before
1242 # testing against the non-relativized items in target_list and before 1245 # testing against the non-relativized items in target_list and before
1243 # calculating the Makefile path. 1246 # calculating the Makefile path.
1244 build_file = os.path.join(depth_rel_path, build_file) 1247 build_file = os.path.join(depth_rel_path, build_file)
1245 gyp_targets = [target_dicts[target]['target_name'] for target in target_list 1248 gyp_targets = [target_dicts[target]['target_name'] for target in target_list
1246 if target.startswith(build_file) and 1249 if target.startswith(build_file) and
1247 target in needed_targets] 1250 target in needed_targets]
1248 # Only generate Makefiles for gyp files with targets. 1251 # Only generate Makefiles for gyp files with targets.
1249 if not gyp_targets: 1252 if not gyp_targets:
1250 continue 1253 continue
1251 (base_path, output_file) = CalculateMakefilePath(build_file, 1254 base_path, output_file = CalculateMakefilePath(build_file,
1252 os.path.splitext(os.path.basename(build_file))[0] + '.Makefile') 1255 os.path.splitext(os.path.basename(build_file))[0] + '.Makefile')
1253 makefile_rel_path = gyp.common.RelativePath(os.path.dirname(makefile_path), 1256 makefile_rel_path = gyp.common.RelativePath(os.path.dirname(makefile_path),
1254 os.path.dirname(output_file)) 1257 os.path.dirname(output_file))
1255 writer.WriteSubMake(output_file, makefile_rel_path, gyp_targets, 1258 writer.WriteSubMake(output_file, makefile_rel_path, gyp_targets,
1256 builddir_name) 1259 builddir_name)
1257 1260
1258 1261
1259 # Write out the sorted list of includes. 1262 # Write out the sorted list of includes.
1260 root_makefile.write('\n') 1263 root_makefile.write('\n')
1261 for include in sorted(include_list): 1264 for include in sorted(include_list):
1262 root_makefile.write(include) 1265 root_makefile.write(include)
1263 root_makefile.write('\n') 1266 root_makefile.write('\n')
1264 1267
1265 # Write the target to regenerate the Makefile. 1268 # Write the target to regenerate the Makefile.
1266 if generator_flags.get('auto_regeneration', True): 1269 if generator_flags.get('auto_regeneration', True):
1267 build_files_args = [gyp.common.RelativePath(filename, options.depth) 1270 build_files_args = [gyp.common.RelativePath(filename, options.toplevel_dir)
1268 for filename in params['build_files_arg']] 1271 for filename in params['build_files_arg']]
1269 gyp_binary = gyp.common.FixIfRelativePath(params['gyp_binary'], 1272 gyp_binary = gyp.common.FixIfRelativePath(params['gyp_binary'],
1270 options.depth) 1273 options.toplevel_dir)
1271 if not gyp_binary.startswith(os.sep): 1274 if not gyp_binary.startswith(os.sep):
1272 gyp_binary = os.path.join('.', gyp_binary) 1275 gyp_binary = os.path.join('.', gyp_binary)
1273 root_makefile.write("%s: %s\n\t%s\n" % ( 1276 root_makefile.write("%s: %s\n\t%s\n" % (
1274 makefile_name, 1277 makefile_name,
1275 ' '.join(map(Sourceify, build_files)), 1278 ' '.join(map(Sourceify, build_files)),
1276 gyp.common.EncodePOSIXShellList( 1279 gyp.common.EncodePOSIXShellList(
1277 [gyp_binary, '-fmake'] + 1280 [gyp_binary, '-fmake'] +
1278 gyp.RegenerateFlags(options) + 1281 gyp.RegenerateFlags(options) +
1279 build_files_args))) 1282 build_files_args)))
1280 1283
1281 root_makefile.write(SHARED_FOOTER) 1284 root_makefile.write(SHARED_FOOTER)
1282 1285
1283 root_makefile.close() 1286 root_makefile.close()
OLDNEW
« no previous file with comments | « pylib/gyp/__init__.py ('k') | test/toplevel-dir/gyptest-toplevel-dir.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698