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

Side by Side Diff: build/android/gyp/util/build_utils.py

Issue 1647353002: Use gn_helpers to [se]serialize GN lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@python_impl
Patch Set: more Created 4 years, 4 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
« no previous file with comments | « build/android/gyp/strip_library_for_device.py ('k') | build/android/gyp/write_build_config.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import ast 5 import ast
6 import contextlib 6 import contextlib
7 import fnmatch 7 import fnmatch
8 import json 8 import json
9 import os 9 import os
10 import pipes 10 import pipes
11 import re 11 import re
12 import shlex 12 import shlex
13 import shutil 13 import shutil
14 import stat 14 import stat
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 import tempfile 17 import tempfile
18 import zipfile 18 import zipfile
19 19
20 # Some clients do not add //build/android/gyp to PYTHONPATH. 20 # Some clients do not add //build/android/gyp to PYTHONPATH.
21 import md5_check # pylint: disable=relative-import 21 import md5_check # pylint: disable=relative-import
22 22
23 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) 23 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
24 from pylib.constants import host_paths 24 from pylib.constants import host_paths
25 25
26 sys.path.append(os.path.join(os.path.dirname(__file__),
27 os.pardir, os.pardir, os.pardir))
28 import gn_helpers
29
26 COLORAMA_ROOT = os.path.join(host_paths.DIR_SOURCE_ROOT, 30 COLORAMA_ROOT = os.path.join(host_paths.DIR_SOURCE_ROOT,
27 'third_party', 'colorama', 'src') 31 'third_party', 'colorama', 'src')
28 # aapt should ignore OWNERS files in addition the default ignore pattern. 32 # aapt should ignore OWNERS files in addition the default ignore pattern.
29 AAPT_IGNORE_PATTERN = ('!OWNERS:!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:' + 33 AAPT_IGNORE_PATTERN = ('!OWNERS:!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:' +
30 '!CVS:!thumbs.db:!picasa.ini:!*~:!*.d.stamp') 34 '!CVS:!thumbs.db:!picasa.ini:!*~:!*.d.stamp')
31 HERMETIC_TIMESTAMP = (2001, 1, 1, 0, 0, 0) 35 HERMETIC_TIMESTAMP = (2001, 1, 1, 0, 0, 0)
32 _HERMETIC_FILE_ATTR = (0644 << 16L) 36 _HERMETIC_FILE_ATTR = (0644 << 16L)
33 37
34 38
35 @contextlib.contextmanager 39 @contextlib.contextmanager
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 75
72 76
73 def FindInDirectories(directories, filename_filter): 77 def FindInDirectories(directories, filename_filter):
74 all_files = [] 78 all_files = []
75 for directory in directories: 79 for directory in directories:
76 all_files.extend(FindInDirectory(directory, filename_filter)) 80 all_files.extend(FindInDirectory(directory, filename_filter))
77 return all_files 81 return all_files
78 82
79 83
80 def ParseGnList(gn_string): 84 def ParseGnList(gn_string):
81 # TODO(brettw) bug 573132: This doesn't handle GN escaping properly, so any 85 """Converts a command-line parameter into a list.
82 # weird characters like $ or \ in the strings will be corrupted.
83 #
84 # The code should import build/gn_helpers.py and then do:
85 # parser = gn_helpers.GNValueParser(gn_string)
86 # return return parser.ParseList()
87 # As of this writing, though, there is a CastShell build script that sends
88 # JSON through this function, and using correct GN parsing corrupts that.
89 #
90 # We need to be consistent about passing either JSON or GN lists through
91 # this function.
92 return ast.literal_eval(gn_string)
93 86
87 If the input starts with a '[' it is assumed to be a GN-formatted list and
88 it will be parsed accordingly. When empty an empty list will be returned.
89 Otherwise, the parameter will be treated as a single raw string (not
90 GN-formatted in that it's not assumed to have literal quotes that must be
91 removed) and a list will be returned containing that string.
94 92
95 def ParseGypList(gyp_string): 93 The common use for this behavior is in the Android build where things can
96 # The ninja generator doesn't support $ in strings, so use ## to 94 take lists of @FileArg references that are expanded via ExpandFileArgs.
97 # represent $. 95 """
98 # TODO(cjhopman): Remove when 96 if gn_string.startswith('['):
99 # https://code.google.com/p/gyp/issues/detail?id=327 97 parser = gn_helpers.GNValueParser(gn_string)
100 # is addressed. 98 return parser.ParseList()
101 gyp_string = gyp_string.replace('##', '$') 99 if len(gn_string):
102 100 return [ gn_string ]
103 if gyp_string.startswith('['): 101 return []
104 return ParseGnList(gyp_string)
105 return shlex.split(gyp_string)
106 102
107 103
108 def CheckOptions(options, parser, required=None): 104 def CheckOptions(options, parser, required=None):
109 if not required: 105 if not required:
110 return 106 return
111 for option_name in required: 107 for option_name in required:
112 if getattr(options, option_name) is None: 108 if getattr(options, option_name) is None:
113 parser.error('--%s is required' % option_name.replace('_', '-')) 109 parser.error('--%s is required' % option_name.replace('_', '-'))
114 110
115 111
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 458
463 lookup_path = match.group(1).split(':') 459 lookup_path = match.group(1).split(':')
464 file_path = lookup_path[0] 460 file_path = lookup_path[0]
465 if not file_path in file_jsons: 461 if not file_path in file_jsons:
466 file_jsons[file_path] = ReadJson(file_path) 462 file_jsons[file_path] = ReadJson(file_path)
467 463
468 expansion = file_jsons[file_path] 464 expansion = file_jsons[file_path]
469 for k in lookup_path[1:]: 465 for k in lookup_path[1:]:
470 expansion = expansion[k] 466 expansion = expansion[k]
471 467
472 new_args[i] = arg[:match.start()] + str(expansion) 468 # This should match ParseGNList. The output is either a GN-formatted list
469 # or a literal (with no quotes).
470 if isinstance(expansion, list):
471 new_args[i] = arg[:match.start()] + gn_helpers.ToGNString(expansion)
472 else:
473 new_args[i] = arg[:match.start()] + str(expansion)
473 474
474 return new_args 475 return new_args
475 476
476 477
477 def ReadSourcesList(sources_list_file_name): 478 def ReadSourcesList(sources_list_file_name):
478 """Reads a GN-written file containing list of file names and returns a list. 479 """Reads a GN-written file containing list of file names and returns a list.
479 480
480 Note that this function should not be used to parse response files. 481 Note that this function should not be used to parse response files.
481 """ 482 """
482 with open(sources_list_file_name) as f: 483 with open(sources_list_file_name) as f:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 529
529 md5_check.CallAndRecordIfStale( 530 md5_check.CallAndRecordIfStale(
530 on_stale_md5, 531 on_stale_md5,
531 record_path=record_path, 532 record_path=record_path,
532 input_paths=input_paths, 533 input_paths=input_paths,
533 input_strings=input_strings, 534 input_strings=input_strings,
534 output_paths=output_paths, 535 output_paths=output_paths,
535 force=force, 536 force=force,
536 pass_changes=True) 537 pass_changes=True)
537 538
OLDNEW
« no previous file with comments | « build/android/gyp/strip_library_for_device.py ('k') | build/android/gyp/write_build_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698