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

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

Issue 269943005: Add android_library template (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « build/android/gyp/javac.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 contextlib 6 import contextlib
6 import fnmatch 7 import fnmatch
7 import json 8 import json
8 import os 9 import os
9 import pipes 10 import pipes
10 import shlex 11 import shlex
11 import shutil 12 import shutil
12 import subprocess 13 import subprocess
13 import sys 14 import sys
14 import tempfile 15 import tempfile
15 import zipfile 16 import zipfile
16 17
18
17 CHROMIUM_SRC = os.path.normpath( 19 CHROMIUM_SRC = os.path.normpath(
18 os.path.join(os.path.dirname(__file__), 20 os.path.join(os.path.dirname(__file__),
19 os.pardir, os.pardir, os.pardir, os.pardir)) 21 os.pardir, os.pardir, os.pardir, os.pardir))
20 COLORAMA_ROOT = os.path.join(CHROMIUM_SRC, 22 COLORAMA_ROOT = os.path.join(CHROMIUM_SRC,
21 'third_party', 'colorama', 'src') 23 'third_party', 'colorama', 'src')
22 24
23 25
24 @contextlib.contextmanager 26 @contextlib.contextmanager
25 def TempDir(): 27 def TempDir():
26 dirname = tempfile.mkdtemp() 28 dirname = tempfile.mkdtemp()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return files 61 return files
60 62
61 63
62 def FindInDirectories(directories, filename_filter): 64 def FindInDirectories(directories, filename_filter):
63 all_files = [] 65 all_files = []
64 for directory in directories: 66 for directory in directories:
65 all_files.extend(FindInDirectory(directory, filename_filter)) 67 all_files.extend(FindInDirectory(directory, filename_filter))
66 return all_files 68 return all_files
67 69
68 70
71 def ParseGnList(gn_string):
72 return ast.literal_eval(gn_string)
73
74
69 def ParseGypList(gyp_string): 75 def ParseGypList(gyp_string):
70 # The ninja generator doesn't support $ in strings, so use ## to 76 # The ninja generator doesn't support $ in strings, so use ## to
71 # represent $. 77 # represent $.
72 # TODO(cjhopman): Remove when 78 # TODO(cjhopman): Remove when
73 # https://code.google.com/p/gyp/issues/detail?id=327 79 # https://code.google.com/p/gyp/issues/detail?id=327
74 # is addressed. 80 # is addressed.
75 gyp_string = gyp_string.replace('##', '$') 81 gyp_string = gyp_string.replace('##', '$')
82
83 if gyp_string.startswith('['):
84 return ParseGnList(gyp_string)
76 return shlex.split(gyp_string) 85 return shlex.split(gyp_string)
77 86
78 87
79 def CheckOptions(options, parser, required=None): 88 def CheckOptions(options, parser, required=None):
80 if not required: 89 if not required:
81 return 90 return
82 for option_name in required: 91 for option_name in required:
83 if getattr(options, option_name) is None: 92 if getattr(options, option_name) is None:
84 parser.error('--%s is required' % option_name.replace('_', '-')) 93 parser.error('--%s is required' % option_name.replace('_', '-'))
85 94
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 help='Path to depfile. This must be specified as the ' 254 help='Path to depfile. This must be specified as the '
246 'action\'s first output.') 255 'action\'s first output.')
247 256
248 257
249 def WriteDepfile(path, dependencies): 258 def WriteDepfile(path, dependencies):
250 with open(path, 'w') as depfile: 259 with open(path, 'w') as depfile:
251 depfile.write(path) 260 depfile.write(path)
252 depfile.write(': ') 261 depfile.write(': ')
253 depfile.write(' '.join(dependencies)) 262 depfile.write(' '.join(dependencies))
254 depfile.write('\n') 263 depfile.write('\n')
264
265
266 def ExpandFileArgs(args):
267 """Replaces file-arg placeholders in args.
268
269 These placeholders have the form:
270 @(filename:key1:key2:...:keyn)
271
272 The value of such a placeholder is calculated by reading 'filename' as json.
273 And then extracting the value at [key1][key2]...[keyn].
274
275 Note: This intentionally does not return the list of files that appear in such
276 placeholders. An action that uses file-args *must* know the paths of those
277 files prior to the parsing of the arguments (typically by explicitly listing
278 them in the action's inputs in build files).
279 """
280 new_args = list(args)
281 file_jsons = dict()
282 for i, arg in enumerate(args):
283 start = arg.find('@(')
284 if start < 0:
285 continue
286 end = arg[start:].find(')')
287 if end < 0:
288 continue
289 end += start
290
291 if '@(' in arg[end:]:
292 raise Exception('Only one file-lookup-expansion is allowed in each arg.')
293
294 lookup_path = arg[start + 2:end].split(':')
295 file_path = lookup_path[0]
296 if not file_path in file_jsons:
297 file_jsons[file_path] = ReadJson(file_path)
298
299 expansion = file_jsons[file_path]
300 for k in lookup_path[1:]:
301 expansion = expansion[k]
302
303 new_args[i] = arg[:start] + str(expansion) + arg[end + 1:]
304 return new_args
305
OLDNEW
« no previous file with comments | « build/android/gyp/javac.py ('k') | build/android/gyp/write_build_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698