Skip to content

Commit

Permalink
Improve error messages when <!(commands) fail
Browse files Browse the repository at this point in the history
Make gyp report both the failing command and the gyp file name when a
<!(command) is not successful. Handle non-zero exit status and Popen
exception (usually file not found) error cases.

Patch from tsniatowski@opera.com.

R=scottmg@chromium.org, thakis@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1322643002 .
  • Loading branch information
sgraham committed Sep 1, 2015
1 parent bae26e8 commit 008cf1c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pylib/gyp/input.py
Expand Up @@ -893,20 +893,24 @@ def ExpandVariables(input, phase, variables, build_file):
else:
# Fix up command with platform specific workarounds.
contents = FixupPlatformCommand(contents)
p = subprocess.Popen(contents, shell=use_shell,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
cwd=build_file_dir)
try:
p = subprocess.Popen(contents, shell=use_shell,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
cwd=build_file_dir)
except Exception, e:
raise GypError("%s while executing command '%s' in %s" %
(e, contents, build_file))

p_stdout, p_stderr = p.communicate('')

if p.wait() != 0 or p_stderr:
sys.stderr.write(p_stderr)
# Simulate check_call behavior, since check_call only exists
# in python 2.5 and later.
raise GypError("Call to '%s' returned exit status %d." %
(contents, p.returncode))
raise GypError("Call to '%s' returned exit status %d while in %s." %
(contents, p.returncode, build_file))
replacement = p_stdout.rstrip()

cached_command_results[cache_key] = replacement
Expand Down
12 changes: 12 additions & 0 deletions test/errors/error_command.gyp
@@ -0,0 +1,12 @@
# Copyright (c) 2015 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': 'foo',
'type': '<!(["python", "-c", "import sys; sys.exit(3)"])',
},
]
}
12 changes: 12 additions & 0 deletions test/errors/gyptest-errors.py
Expand Up @@ -65,4 +65,16 @@
test.run_gyp('missing_dep.gyp', status=1, stderr=stderr,
match=TestCmd.match_re)

# Make sure invalid <!() command invocations say what command it was and
# mention the gyp file name. Use a "random" command name to trigger an ENOENT.
stderr = (".*invalid-command-name-egtyevNif3.*netDurj9.*missing_command.gyp.*")
test.run_gyp('missing_command.gyp', status=1, stderr=stderr,
match=TestCmd.match_re_dotall)

# Make sure <!() commands that error out result in a message that mentions
# the command and gyp file name
stderr = (".*python.*-c.*import sys.*sys.exit.*3.*error_command.gyp.*")
test.run_gyp('error_command.gyp', status=1, stderr=stderr,
match=TestCmd.match_re_dotall)

test.pass_test()
12 changes: 12 additions & 0 deletions test/errors/missing_command.gyp
@@ -0,0 +1,12 @@
# Copyright (c) 2015 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': 'foo',
'type': '<!(["invalid-command-name-egtyevNif3", "netDurj9"])',
},
]
}

0 comments on commit 008cf1c

Please sign in to comment.