diff options
author | scottmg@chromium.org <scottmg@chromium.org@78cadc50-ecff-11dd-a971-7dbc132099af> | 2014-06-20 17:42:59 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@78cadc50-ecff-11dd-a971-7dbc132099af> | 2014-06-20 17:42:59 +0000 |
commit | c5c01bbc72f44eecce85a2d135ade364e552d067 (patch) | |
tree | 6fe1db6bd2413e4ae7e3326cba236dd2d3a810d4 | |
parent | 63a1f78eb0ec6c4ddcc23e920230bdb0b14f7855 (diff) | |
download | gyp-c5c01bbc72f44eecce85a2d135ade364e552d067.tar.gz |
msvs: ensure that failing actions make the build fail with multiple actions
The old way of joining multiple commands would take care of failing correctly
when there are multiple actions associated with a single file. However, for
multiple actions associated with different files (but within the same target),
Visual Studio will still create just one .bat file for them all, so we must
make sure that each command errors out correctly when it fails.
Strictly speaking, the %errorlevel% check is unnecessary for the last command
in a target (because the .bat file created by VS contains it already); but it
doesn't hurt either, and makes the logic much simpler.
Patch from Stefan Haller <stk.haller@googlemail.com>.
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/335273006
git-svn-id: http://gyp.googlecode.com/svn/trunk@1945 78cadc50-ecff-11dd-a971-7dbc132099af
5 files changed, 82 insertions, 2 deletions
diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py index b18bff18..f548bb0e 100644 --- a/pylib/gyp/generator/msvs.py +++ b/pylib/gyp/generator/msvs.py @@ -3287,8 +3287,8 @@ def _GenerateActionsForMSBuild(spec, actions_to_add): # get too long. See also _AddActions: cygwin's setup_env mustn't be called # for every invocation or the command that sets the PATH will grow too # long. - command = ( - '\r\nif %errorlevel% neq 0 exit /b %errorlevel%\r\n'.join(commands)) + command = '\r\n'.join([c + '\r\nif %errorlevel% neq 0 exit /b %errorlevel%' + for c in commands]) _AddMSBuildAction(spec, primary_input, inputs, diff --git a/test/msvs/multiple_actions_error_handling/action_fail.py b/test/msvs/multiple_actions_error_handling/action_fail.py new file mode 100644 index 00000000..286fc4e1 --- /dev/null +++ b/test/msvs/multiple_actions_error_handling/action_fail.py @@ -0,0 +1,7 @@ +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import sys + +sys.exit(1) diff --git a/test/msvs/multiple_actions_error_handling/action_succeed.py b/test/msvs/multiple_actions_error_handling/action_succeed.py new file mode 100644 index 00000000..35543731 --- /dev/null +++ b/test/msvs/multiple_actions_error_handling/action_succeed.py @@ -0,0 +1,7 @@ +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import sys + +sys.exit(0) diff --git a/test/msvs/multiple_actions_error_handling/actions.gyp b/test/msvs/multiple_actions_error_handling/actions.gyp new file mode 100644 index 00000000..ab99e929 --- /dev/null +++ b/test/msvs/multiple_actions_error_handling/actions.gyp @@ -0,0 +1,40 @@ +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'targets': [ + { + 'target_name': 'actions-test', + 'type': 'none', + 'actions': [ + { + 'action_name': 'first action (fails)', + 'inputs': [ + 'action_fail.py', + ], + 'outputs': [ + 'ALWAYS_OUT_OF_DATE', + ], + 'action': [ + 'python', '<@(_inputs)' + ], + 'msvs_cygwin_shell': 0, + }, + { + 'action_name': 'second action (succeeds)', + 'inputs': [ + 'action_succeed.py', + ], + 'outputs': [ + 'ALWAYS_OUT_OF_DATE', + ], + 'action': [ + 'python', '<@(_inputs)' + ], + 'msvs_cygwin_shell': 0, + }, + ], + }, + ], +} diff --git a/test/msvs/multiple_actions_error_handling/gyptest.py b/test/msvs/multiple_actions_error_handling/gyptest.py new file mode 100644 index 00000000..3aa6b8fd --- /dev/null +++ b/test/msvs/multiple_actions_error_handling/gyptest.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +# Copyright (c) 2014 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Verifies that failing actions make the build fail reliably, even when there +are multiple actions in one project. +""" + +import os +import sys +import TestGyp +import TestCmd + +test = TestGyp.TestGyp(formats=['msvs'], workdir='workarea_all') + +test.run_gyp('actions.gyp') +test.build('actions.gyp', + target='actions-test', + status=1, + stdout=r'.*"cmd\.exe" exited with code 1\..*', + match=TestCmd.match_re_dotall) + +test.pass_test() |