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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 from compiler.ast import Const 7 from compiler.ast import Const
8 from compiler.ast import Dict 8 from compiler.ast import Dict
9 from compiler.ast import Discard 9 from compiler.ast import Discard
10 from compiler.ast import List 10 from compiler.ast import List
11 from compiler.ast import Module 11 from compiler.ast import Module
12 from compiler.ast import Node 12 from compiler.ast import Node
13 from compiler.ast import Stmt 13 from compiler.ast import Stmt
14 import compiler 14 import compiler
15 import copy 15 import copy
16 import gyp.common 16 import gyp.common
17 import optparse 17 import optparse
18 import os.path 18 import os.path
19 import re 19 import re
20 import shlex 20 import shlex
21 import subprocess 21 import subprocess
22 import sys 22 import sys
23 23
24 # Try to import grit.
25 try:
26 import grit_info # TODO: make optional
Mark Mentovai 2011/05/16 16:51:34 What does “TODO: make optional” mean when this is
27 grit_available = True
28 except Exception, e:
29 grit_available = False
tony 2011/05/16 16:24:05 The python idiom for this is on Exception to just
30
24 31
25 # A list of types that are treated as linkable. 32 # A list of types that are treated as linkable.
26 linkable_types = ['executable', 'shared_library', 'loadable_module'] 33 linkable_types = ['executable', 'shared_library', 'loadable_module']
27 34
28 # A list of sections that contain links to other targets. 35 # A list of sections that contain links to other targets.
29 dependency_sections = ['dependencies', 'export_dependent_settings'] 36 dependency_sections = ['dependencies', 'export_dependent_settings']
30 37
31 # base_path_sections is a list of sections defined by GYP that contain 38 # base_path_sections is a list of sections defined by GYP that contain
32 # pathnames. The generators can provide more keys, the two lists are merged 39 # pathnames. The generators can provide more keys, the two lists are merged
33 # into path_sections, but you should call IsPathSection instead of using either 40 # into path_sections, but you should call IsPathSection instead of using either
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 # is invoked it produces different output by design. When the need 634 # is invoked it produces different output by design. When the need
628 # arises, the syntax should be extended to support no caching off a 635 # arises, the syntax should be extended to support no caching off a
629 # command's output so it is run every time. 636 # command's output so it is run every time.
630 cache_key = str(contents) 637 cache_key = str(contents)
631 cached_value = cached_command_results.get(cache_key, None) 638 cached_value = cached_command_results.get(cache_key, None)
632 if cached_value is None: 639 if cached_value is None:
633 gyp.DebugOutput(gyp.DEBUG_VARIABLES, 640 gyp.DebugOutput(gyp.DEBUG_VARIABLES,
634 "Executing command '%s' in directory '%s'" % 641 "Executing command '%s' in directory '%s'" %
635 (contents,build_file_dir)) 642 (contents,build_file_dir))
636 643
637 # Fix up command with platform specific workarounds. 644 replacement = ''
638 contents = FixupPlatformCommand(contents)
639 p = subprocess.Popen(contents, shell=use_shell,
640 stdout=subprocess.PIPE,
641 stderr=subprocess.PIPE,
642 stdin=subprocess.PIPE,
643 cwd=build_file_dir)
644 645
645 (p_stdout, p_stderr) = p.communicate('') 646 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?
647 if (grit_available and
648 parsed_contents[0] == 'python' and
649 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
650 # Invoke grit_info directly, without spawning a subprocess. Do
651 # this in |build_file_dir|.
652 oldwd = os.getcwd() # Python doesn't like os.open('.'): no fchdir.
653 os.chdir(build_file_dir)
654 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
655 os.chdir(oldwd)
656 assert replacement != None
657 else:
658 # Fix up command with platform specific workarounds.
659 contents = FixupPlatformCommand(contents)
660 p = subprocess.Popen(contents, shell=use_shell,
661 stdout=subprocess.PIPE,
662 stderr=subprocess.PIPE,
663 stdin=subprocess.PIPE,
664 cwd=build_file_dir)
646 665
647 if p.wait() != 0 or p_stderr: 666 (p_stdout, p_stderr) = p.communicate('')
648 sys.stderr.write(p_stderr) 667
649 # Simulate check_call behavior, since check_call only exists 668 if p.wait() != 0 or p_stderr:
650 # in python 2.5 and later. 669 sys.stderr.write(p_stderr)
651 raise Exception("Call to '%s' returned exit status %d." % 670 # Simulate check_call behavior, since check_call only exists
652 (contents, p.returncode)) 671 # in python 2.5 and later.
653 replacement = p_stdout.rstrip() 672 raise Exception("Call to '%s' returned exit status %d." %
673 (contents, p.returncode))
674 replacement = p_stdout.rstrip()
654 675
655 cached_command_results[cache_key] = replacement 676 cached_command_results[cache_key] = replacement
656 else: 677 else:
657 gyp.DebugOutput(gyp.DEBUG_VARIABLES, 678 gyp.DebugOutput(gyp.DEBUG_VARIABLES,
658 "Had cache value for command '%s' in directory '%s'" % 679 "Had cache value for command '%s' in directory '%s'" %
659 (contents,build_file_dir)) 680 (contents,build_file_dir))
660 replacement = cached_value 681 replacement = cached_value
661 682
662 else: 683 else:
663 if not contents in variables: 684 if not contents in variables:
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 ValidateRunAsInTarget(target, target_dict, build_file) 2262 ValidateRunAsInTarget(target, target_dict, build_file)
2242 ValidateActionsInTarget(target, target_dict, build_file) 2263 ValidateActionsInTarget(target, target_dict, build_file)
2243 2264
2244 # Generators might not expect ints. Turn them into strs. 2265 # Generators might not expect ints. Turn them into strs.
2245 TurnIntIntoStrInDict(data) 2266 TurnIntIntoStrInDict(data)
2246 2267
2247 # TODO(mark): Return |data| for now because the generator needs a list of 2268 # TODO(mark): Return |data| for now because the generator needs a list of
2248 # build files that came in. In the future, maybe it should just accept 2269 # build files that came in. In the future, maybe it should just accept
2249 # a list, and not the whole data dict. 2270 # a list, and not the whole data dict.
2250 return [flat_list, targets, data] 2271 return [flat_list, targets, data]
OLDNEW
« 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