Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: pylib/gyp/input.py

Issue 7034007: Teach gyp about configurable filter commands, add "pymod_do_main" filter (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/input.py
===================================================================
--- pylib/gyp/input.py (revision 917)
+++ pylib/gyp/input.py (working copy)
@@ -21,7 +21,14 @@
import subprocess
import sys
+# Try to import grit.
+try:
+ import grit_info # TODO: make optional
Mark Mentovai 2011/05/16 16:51:34 What does “TODO: make optional” mean when this is
+ grit_available = True
+except Exception, e:
+ grit_available = False
tony 2011/05/16 16:24:05 The python idiom for this is on Exception to just
+
# A list of types that are treated as linkable.
linkable_types = ['executable', 'shared_library', 'loadable_module']
@@ -634,24 +641,38 @@
"Executing command '%s' in directory '%s'" %
(contents,build_file_dir))
- # 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)
+ replacement = ''
- (p_stdout, p_stderr) = p.communicate('')
+ parsed_contents = contents.split()
Mark Mentovai 2011/05/16 16:51:34 Can you refactor this whole block into its own fun
Mark Mentovai 2011/05/16 16:51:34 shlex instead?
+ if (grit_available and
+ parsed_contents[0] == 'python' and
+ parsed_contents[1].endswith('grit_info.py')):
tony 2011/05/16 16:24:05 Will parsed_contents always have at least 2 valeus
bradn 2011/05/16 16:35:50 Maybe raise an exception with a more specific erro
Mark Mentovai 2011/05/16 16:51:34 It certainly seems like you can tighten up the saf
+ # Invoke grit_info directly, without spawning a subprocess. Do
+ # this in |build_file_dir|.
+ oldwd = os.getcwd() # Python doesn't like os.open('.'): no fchdir.
+ os.chdir(build_file_dir)
+ replacement = str(grit_info.DoMain(contents.split()[2:]).rstrip())
tony 2011/05/16 16:24:05 The extra str() seems unnecessary (doesn't rstrip(
Mark Mentovai 2011/05/16 16:51:34 You already have parsed_contents, why are you goin
+ os.chdir(oldwd)
+ assert replacement != None
+ 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)
- 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 Exception("Call to '%s' returned exit status %d." %
- (contents, p.returncode))
- replacement = p_stdout.rstrip()
+ (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 Exception("Call to '%s' returned exit status %d." %
+ (contents, p.returncode))
+ replacement = p_stdout.rstrip()
+
cached_command_results[cache_key] = replacement
else:
gyp.DebugOutput(gyp.DEBUG_VARIABLES,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698