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

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

Issue 6469005: make generator: refactor shared headers together... (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 10 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 | « no previous file | no next file » | 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 # This should go into the build tree, but it's easier to keep it here for now. 65 # This should go into the build tree, but it's easier to keep it here for now.
66 SHARED_HEADER = ("""\ 66 SHARED_HEADER = ("""\
67 # We borrow heavily from the kernel build setup, though we are simpler since 67 # We borrow heavily from the kernel build setup, though we are simpler since
68 # we don't have Kconfig tweaking settings on us. 68 # we don't have Kconfig tweaking settings on us.
69 69
70 # The implicit make rules have it looking for RCS files, among other things. 70 # The implicit make rules have it looking for RCS files, among other things.
71 # We instead explicitly write all the rules we care about. 71 # We instead explicitly write all the rules we care about.
72 # It's even quicker (saves ~200ms) to pass -r on the command line. 72 # It's even quicker (saves ~200ms) to pass -r on the command line.
73 MAKEFLAGS=-r 73 MAKEFLAGS=-r
74 74
75 # The source directory tree.
76 srcdir := %(srcdir)s
77
78 # The name of the builddir.
79 builddir_name ?= %(builddir)s
80
75 # The V=1 flag on command line makes us verbosely print command lines. 81 # The V=1 flag on command line makes us verbosely print command lines.
76 ifdef V 82 ifdef V
77 quiet= 83 quiet=
78 else 84 else
79 quiet=quiet_ 85 quiet=quiet_
80 endif 86 endif
81 87
82 # Specify BUILDTYPE=Release on the command line for a release build. 88 # Specify BUILDTYPE=Release on the command line for a release build.
83 BUILDTYPE ?= __default_configuration__ 89 BUILDTYPE ?= %(default_configuration)s
84 90
85 # Directory all our build output goes into. 91 # Directory all our build output goes into.
86 # Note that this must be two directories beneath src/ for unit tests to pass, 92 # Note that this must be two directories beneath src/ for unit tests to pass,
87 # as they reach into the src/ directory for data with relative paths. 93 # as they reach into the src/ directory for data with relative paths.
88 builddir ?= $(builddir_name)/$(BUILDTYPE) 94 builddir ?= $(builddir_name)/$(BUILDTYPE)
89 abs_builddir := $(abspath $(builddir)) 95 abs_builddir := $(abspath $(builddir))
90 depsdir := $(builddir)/.deps 96 depsdir := $(builddir)/.deps
91 97
92 # Object output directory. 98 # Object output directory.
93 obj := $(builddir)/obj 99 obj := $(builddir)/obj
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 # - cmd_foo is the actual command to run; 215 # - cmd_foo is the actual command to run;
210 # - quiet_cmd_foo is the brief-output summary of the command. 216 # - quiet_cmd_foo is the brief-output summary of the command.
211 217
212 quiet_cmd_cc = CC($(TOOLSET)) $@ 218 quiet_cmd_cc = CC($(TOOLSET)) $@
213 cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $ @ $< 219 cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $ @ $<
214 220
215 quiet_cmd_cxx = CXX($(TOOLSET)) $@ 221 quiet_cmd_cxx = CXX($(TOOLSET)) $@
216 cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) - c -o $@ $< 222 cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) - c -o $@ $<
217 223
218 quiet_cmd_alink = AR($(TOOLSET)) $@ 224 quiet_cmd_alink = AR($(TOOLSET)) $@
219 cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) $(ARFLAGS.$(TOOLSET)) $@ $(filter %.o,$ ^) 225 cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) $(ARFLAGS.$(TOOLSET)) $@ $(filter %%.o, $^)
220 226
221 quiet_cmd_touch = TOUCH $@ 227 quiet_cmd_touch = TOUCH $@
222 cmd_touch = touch $@ 228 cmd_touch = touch $@
223 229
224 quiet_cmd_copy = COPY $@ 230 quiet_cmd_copy = COPY $@
225 # send stderr to /dev/null to ignore messages when linking directories. 231 # send stderr to /dev/null to ignore messages when linking directories.
226 cmd_copy = ln -f $< $@ 2>/dev/null || cp -af $< $@ 232 cmd_copy = ln -f $< $@ 2>/dev/null || cp -af $< $@
227 233
228 # Due to circular dependencies between libraries :(, we wrap the 234 # Due to circular dependencies between libraries :(, we wrap the
229 # special "figure out circular dependencies" flags around the entire 235 # special "figure out circular dependencies" flags around the entire
(...skipping 15 matching lines...) Expand all
245 escape_quotes = $(subst ','\'',$(1)) 251 escape_quotes = $(subst ','\'',$(1))
246 # This comment is here just to include a ' to unconfuse syntax highlighting. 252 # This comment is here just to include a ' to unconfuse syntax highlighting.
247 # Define an escape_vars function to escape '$' variable syntax. 253 # Define an escape_vars function to escape '$' variable syntax.
248 # This allows us to read/write command lines with shell variables (e.g. 254 # This allows us to read/write command lines with shell variables (e.g.
249 # $LD_LIBRARY_PATH), without triggering make substitution. 255 # $LD_LIBRARY_PATH), without triggering make substitution.
250 escape_vars = $(subst $$,$$$$,$(1)) 256 escape_vars = $(subst $$,$$$$,$(1))
251 # Helper that expands to a shell command to echo a string exactly as it is in 257 # Helper that expands to a shell command to echo a string exactly as it is in
252 # make. This uses printf instead of echo because printf's behaviour with respect 258 # make. This uses printf instead of echo because printf's behaviour with respect
253 # to escape sequences is more portable than echo's across different shells 259 # to escape sequences is more portable than echo's across different shells
254 # (e.g., dash, bash). 260 # (e.g., dash, bash).
255 exact_echo = printf '%s\n' '$(call escape_quotes,$(1))' 261 exact_echo = printf '%%s\n' '$(call escape_quotes,$(1))'
256 """ 262 """
257 """ 263 """
258 # Helper to compare the command we're about to run against the command 264 # Helper to compare the command we're about to run against the command
259 # we logged the last time we ran the command. Produces an empty 265 # we logged the last time we ran the command. Produces an empty
260 # string (false) when the commands match. 266 # string (false) when the commands match.
261 # Tricky point: Make has no string-equality test function. 267 # Tricky point: Make has no string-equality test function.
262 # The kernel uses the following, but it seems like it would have false 268 # The kernel uses the following, but it seems like it would have false
263 # positives, where one string reordered its arguments. 269 # positives, where one string reordered its arguments.
264 # arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \\ 270 # arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \\
265 # $(filter-out $(cmd_$@), $(cmd_$(1)))) 271 # $(filter-out $(cmd_$@), $(cmd_$(1))))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 415 }
410 416
411 SHARED_HEADER_SUFFIX_RULES = ( 417 SHARED_HEADER_SUFFIX_RULES = (
412 SHARED_HEADER_SUFFIX_RULES_COMMENT1 + 418 SHARED_HEADER_SUFFIX_RULES_COMMENT1 +
413 ''.join(SHARED_HEADER_SUFFIX_RULES_SRCDIR.values()) + 419 ''.join(SHARED_HEADER_SUFFIX_RULES_SRCDIR.values()) +
414 SHARED_HEADER_SUFFIX_RULES_COMMENT2 + 420 SHARED_HEADER_SUFFIX_RULES_COMMENT2 +
415 ''.join(SHARED_HEADER_SUFFIX_RULES_OBJDIR1.values()) + 421 ''.join(SHARED_HEADER_SUFFIX_RULES_OBJDIR1.values()) +
416 ''.join(SHARED_HEADER_SUFFIX_RULES_OBJDIR2.values()) 422 ''.join(SHARED_HEADER_SUFFIX_RULES_OBJDIR2.values())
417 ) 423 )
418 424
419 # This gets added to the very beginning of the Makefile.
420 SHARED_HEADER_SRCDIR = ("""\
421 # The source directory tree.
422 srcdir := %s
423
424 """)
425
426 SHARED_HEADER_BUILDDIR_NAME = ("""\
427 # The name of the builddir.
428 builddir_name ?= %s
429
430 """)
431
432 SHARED_FOOTER = """\ 425 SHARED_FOOTER = """\
433 # "all" is a concatenation of the "all" targets from all the included 426 # "all" is a concatenation of the "all" targets from all the included
434 # sub-makefiles. This is just here to clarify. 427 # sub-makefiles. This is just here to clarify.
435 all: 428 all:
436 429
437 # Add in dependency-tracking rules. $(all_deps) is the list of every single 430 # Add in dependency-tracking rules. $(all_deps) is the list of every single
438 # target in our tree. First, only consider targets that already have been 431 # target in our tree. First, only consider targets that already have been
439 # built, as unbuilt targets will be built regardless of dependency info: 432 # built, as unbuilt targets will be built regardless of dependency info:
440 all_deps := $(wildcard $(sort $(all_deps))) 433 all_deps := $(wildcard $(sort $(all_deps)))
441 # Of those, only consider the ones with .d (dependency) info: 434 # Of those, only consider the ones with .d (dependency) info:
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 srcdir = '.' 1281 srcdir = '.'
1289 makefile_name = 'Makefile' + options.suffix 1282 makefile_name = 'Makefile' + options.suffix
1290 makefile_path = os.path.join(options.toplevel_dir, makefile_name) 1283 makefile_path = os.path.join(options.toplevel_dir, makefile_name)
1291 if options.generator_output: 1284 if options.generator_output:
1292 global srcdir_prefix 1285 global srcdir_prefix
1293 makefile_path = os.path.join(options.generator_output, makefile_path) 1286 makefile_path = os.path.join(options.generator_output, makefile_path)
1294 srcdir = gyp.common.RelativePath(srcdir, options.generator_output) 1287 srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
1295 srcdir_prefix = '$(srcdir)/' 1288 srcdir_prefix = '$(srcdir)/'
1296 ensure_directory_exists(makefile_path) 1289 ensure_directory_exists(makefile_path)
1297 root_makefile = open(makefile_path, 'w') 1290 root_makefile = open(makefile_path, 'w')
1298 root_makefile.write(SHARED_HEADER_SRCDIR % srcdir) 1291 root_makefile.write(SHARED_HEADER % {
1299 root_makefile.write(SHARED_HEADER_BUILDDIR_NAME % builddir_name) 1292 'srcdir': srcdir,
1300 root_makefile.write(SHARED_HEADER.replace('__default_configuration__', 1293 'builddir': builddir_name,
1301 default_configuration)) 1294 'default_configuration': default_configuration
1295 })
1302 for toolset in toolsets: 1296 for toolset in toolsets:
1303 root_makefile.write('TOOLSET := %s\n' % toolset) 1297 root_makefile.write('TOOLSET := %s\n' % toolset)
1304 root_makefile.write(ROOT_HEADER_SUFFIX_RULES) 1298 root_makefile.write(ROOT_HEADER_SUFFIX_RULES)
1305 1299
1306 # Find the list of targets that derive from the gyp file(s) being built. 1300 # Find the list of targets that derive from the gyp file(s) being built.
1307 needed_targets = set() 1301 needed_targets = set()
1308 for build_file in params['build_files']: 1302 for build_file in params['build_files']:
1309 for target in gyp.common.AllTargets(target_list, target_dicts, build_file): 1303 for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
1310 needed_targets.add(target) 1304 needed_targets.add(target)
1311 1305
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 # Add a check to make sure we tried to process all the .d files. 1395 # Add a check to make sure we tried to process all the .d files.
1402 all_deps += """ 1396 all_deps += """
1403 ifneq ($(word %(last)d,$(d_files)),) 1397 ifneq ($(word %(last)d,$(d_files)),)
1404 $(error Found unprocessed dependency files (gyp didn't generate enough rules !)) 1398 $(error Found unprocessed dependency files (gyp didn't generate enough rules !))
1405 endif 1399 endif
1406 """ % { 'last': ((num_outputs / 1000) + 1) * 1000 + 1 } 1400 """ % { 'last': ((num_outputs / 1000) + 1) * 1000 + 1 }
1407 1401
1408 root_makefile.write(SHARED_FOOTER % { 'generate_all_deps': all_deps }) 1402 root_makefile.write(SHARED_FOOTER % { 'generate_all_deps': all_deps })
1409 1403
1410 root_makefile.close() 1404 root_makefile.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698