Skip to content

Commit

Permalink
compiler_version: suppress stderr unless command fails
Browse files Browse the repository at this point in the history
gyp considers a shell variable substitution to have failed if it
generates any output to stderr, even if the exit status was zero.
This causes problems when gomacc automatically starts its proxy,
which helpfully reports "GOMA: Starting compiler proxy" to stderr.

Fixed by dropping stderr unless the underlying process returns
a non-zero exit status.

BUG=chromium-os:28670
TEST=Ran hooks normally and inside CrOS chroot, with and without
  $CXX pointing to goma. A $CXX which writes to stderr and then
  exits with failure still prints its output before the exception.


Review URL: http://codereview.chromium.org/10288005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135663 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
cwolfe@chromium.org committed May 7, 2012
1 parent 0bb8fee commit fad554f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions build/compiler_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand All @@ -18,11 +18,17 @@ def GetVersion(compiler):
try:
# Note that compiler could be something tricky like "distcc g++".
compiler = compiler + " -dumpversion"
pipe = subprocess.Popen(compiler, stdout=subprocess.PIPE, shell=True)
gcc_output = pipe.communicate()[0]
pipe = subprocess.Popen(compiler, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
gcc_output, gcc_error = pipe.communicate()
if pipe.returncode:
raise subprocess.CalledProcessError(pipe.returncode, compiler)

result = re.match(r"(\d+)\.(\d+)", gcc_output)
return result.group(1) + result.group(2)
except Exception, e:
if gcc_error:
sys.stderr.write(gcc_error)
print >> sys.stderr, "compiler_version.py failed to execute:", compiler
print >> sys.stderr, e
return ""
Expand Down

0 comments on commit fad554f

Please sign in to comment.