Permalink
Browse files

ninja windows: emulate msvs generator behaviour for msvs_error_on_mis…

…sing_sources=1

BUG=chromium:158651
Review URL: https://codereview.chromium.org/11347053

git-svn-id: http://gyp.googlecode.com/svn/trunk@1527 78cadc50-ecff-11dd-a971-7dbc132099af
  • Loading branch information...
1 parent 1617bae commit 1bbc312e7c271e037242102d3cba22e2166f71c0 scottmg@chromium.org committed Oct 31, 2012
Showing with 45 additions and 25 deletions.
  1. +2 −0 pylib/gyp/generator/ninja.py
  2. +16 −0 pylib/gyp/msvs_emulation.py
  3. +27 −25 test/msvs/missing_sources/gyptest-missing.py
@@ -425,6 +425,8 @@ def WriteSpec(self, spec, config_name, generator_flags,
if sources:
pch = None
if self.flavor == 'win':
+ gyp.msvs_emulation.VerifyMissingSources(
+ sources, self.abs_build_dir, generator_flags, self.GypPathToNinja)
pch = gyp.msvs_emulation.PrecompiledHeader(
self.msvs_settings, config_name, self.GypPathToNinja)
else:
@@ -691,3 +691,19 @@ def GenerateEnvironmentFiles(toplevel_build_dir, generator_flags, open_out):
f = open_out(os.path.join(toplevel_build_dir, 'environment.' + arch), 'wb')
f.write(env_block)
f.close()
+
+def VerifyMissingSources(sources, build_dir, generator_flags, gyp_to_ninja):
+ """Emulate behavior of msvs_error_on_missing_sources present in the msvs
+ generator: Check that all regular source files, i.e. not created at run time,
+ exist on disk. Missing files cause needless recompilation when building via
+ VS, and we want this check to match for people/bots that build using ninja,
+ so they're not surprised when the VS build fails."""
+ if int(generator_flags.get('msvs_error_on_missing_sources', 0)):
+ no_specials = filter(lambda x: '$' not in x, sources)
+ relative = [os.path.join(build_dir, gyp_to_ninja(s)) for s in no_specials]
+ missing = filter(lambda x: not os.path.exists(x), relative)
+ if missing:
+ # They'll look like out\Release\..\..\stuff\things.cc, so normalize the
+ # path for a slightly less crazy looking output.
+ cleaned_up = [os.path.normpath(x) for x in missing]
+ raise Exception('Missing input files:\n%s' % '\n'.join(cleaned_up))
@@ -11,31 +11,33 @@
import TestGyp
import os
+import sys
-test = TestGyp.TestGyp(formats=['msvs'], workdir='workarea_all')
+if sys.platform == 'win32':
+ test = TestGyp.TestGyp(formats=['msvs', 'ninja'], workdir='workarea_all')
-# With the flag not set
-test.run_gyp('hello_missing.gyp')
-
-# With the flag explicitly set to 0
-try:
- os.environ['GYP_GENERATOR_FLAGS'] = 'msvs_error_on_missing_sources=0'
+ # With the flag not set
test.run_gyp('hello_missing.gyp')
-finally:
- del os.environ['GYP_GENERATOR_FLAGS']
-
-# With the flag explicitly set to 1
-try:
- os.environ['GYP_GENERATOR_FLAGS'] = 'msvs_error_on_missing_sources=1'
- # Test to make sure GYP raises an exception (exit status 1). Since this will
- # also print a backtrace, ensure that TestGyp is not checking that stderr is
- # empty by specifying None, which means do not perform any checking.
- # Instead, stderr is checked below to ensure it contains the expected
- # output.
- test.run_gyp('hello_missing.gyp', status=1, stderr=None)
-finally:
- del os.environ['GYP_GENERATOR_FLAGS']
-test.must_contain_any_line(test.stderr(),
- ["Missing input files:"])
-
-test.pass_test()
+
+ # With the flag explicitly set to 0
+ try:
+ os.environ['GYP_GENERATOR_FLAGS'] = 'msvs_error_on_missing_sources=0'
+ test.run_gyp('hello_missing.gyp')
+ finally:
+ del os.environ['GYP_GENERATOR_FLAGS']
+
+ # With the flag explicitly set to 1
+ try:
+ os.environ['GYP_GENERATOR_FLAGS'] = 'msvs_error_on_missing_sources=1'
+ # Test to make sure GYP raises an exception (exit status 1). Since this will
+ # also print a backtrace, ensure that TestGyp is not checking that stderr is
+ # empty by specifying None, which means do not perform any checking.
+ # Instead, stderr is checked below to ensure it contains the expected
+ # output.
+ test.run_gyp('hello_missing.gyp', status=1, stderr=None)
+ finally:
+ del os.environ['GYP_GENERATOR_FLAGS']
+ test.must_contain_any_line(test.stderr(),
+ ["Missing input files:"])
+
+ test.pass_test()

0 comments on commit 1bbc312

Please sign in to comment.