From c5c01bbc72f44eecce85a2d135ade364e552d067 Mon Sep 17 00:00:00 2001 From: "scottmg@chromium.org" Date: Fri, 20 Jun 2014 17:42:59 +0000 Subject: 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 . 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 --- pylib/gyp/generator/msvs.py | 4 +-- .../multiple_actions_error_handling/action_fail.py | 7 ++++ .../action_succeed.py | 7 ++++ .../multiple_actions_error_handling/actions.gyp | 40 ++++++++++++++++++++++ .../multiple_actions_error_handling/gyptest.py | 26 ++++++++++++++ 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 test/msvs/multiple_actions_error_handling/action_fail.py create mode 100644 test/msvs/multiple_actions_error_handling/action_succeed.py create mode 100644 test/msvs/multiple_actions_error_handling/actions.gyp create mode 100644 test/msvs/multiple_actions_error_handling/gyptest.py 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() -- cgit v1.2.3