OLD | NEW |
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 shlex | 12 import shlex |
12 import shutil | 13 import shutil |
13 import subprocess | 14 import subprocess |
14 import sys | 15 import sys |
15 import tempfile | 16 import tempfile |
16 import zipfile | 17 import zipfile |
17 | 18 |
18 | 19 |
19 CHROMIUM_SRC = os.path.normpath( | 20 CHROMIUM_SRC = os.path.normpath( |
20 os.path.join(os.path.dirname(__file__), | 21 os.path.join(os.path.dirname(__file__), |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 depfile.write(path) | 309 depfile.write(path) |
309 depfile.write(': ') | 310 depfile.write(': ') |
310 depfile.write(' '.join(dependencies)) | 311 depfile.write(' '.join(dependencies)) |
311 depfile.write('\n') | 312 depfile.write('\n') |
312 | 313 |
313 | 314 |
314 def ExpandFileArgs(args): | 315 def ExpandFileArgs(args): |
315 """Replaces file-arg placeholders in args. | 316 """Replaces file-arg placeholders in args. |
316 | 317 |
317 These placeholders have the form: | 318 These placeholders have the form: |
318 @(filename:key1:key2:...:keyn) | 319 @FileArg(filename:key1:key2:...:keyn) |
319 | 320 |
320 The value of such a placeholder is calculated by reading 'filename' as json. | 321 The value of such a placeholder is calculated by reading 'filename' as json. |
321 And then extracting the value at [key1][key2]...[keyn]. | 322 And then extracting the value at [key1][key2]...[keyn]. |
322 | 323 |
323 Note: This intentionally does not return the list of files that appear in such | 324 Note: This intentionally does not return the list of files that appear in such |
324 placeholders. An action that uses file-args *must* know the paths of those | 325 placeholders. An action that uses file-args *must* know the paths of those |
325 files prior to the parsing of the arguments (typically by explicitly listing | 326 files prior to the parsing of the arguments (typically by explicitly listing |
326 them in the action's inputs in build files). | 327 them in the action's inputs in build files). |
327 """ | 328 """ |
328 new_args = list(args) | 329 new_args = list(args) |
329 file_jsons = dict() | 330 file_jsons = dict() |
| 331 r = re.compile('@FileArg\((.*?)\)') |
330 for i, arg in enumerate(args): | 332 for i, arg in enumerate(args): |
331 start = arg.find('@(') | 333 match = r.search(arg) |
332 if start < 0: | 334 if not match: |
333 continue | 335 continue |
334 end = arg[start:].find(')') | |
335 if end < 0: | |
336 continue | |
337 end += start | |
338 | 336 |
339 if '@(' in arg[end:]: | 337 if match.end() != len(arg): |
340 raise Exception('Only one file-lookup-expansion is allowed in each arg.') | 338 raise Exception('Unexpected characters after FileArg: ' + arg) |
341 | 339 |
342 lookup_path = arg[start + 2:end].split(':') | 340 lookup_path = match.group(1).split(':') |
343 file_path = lookup_path[0] | 341 file_path = lookup_path[0] |
344 if not file_path in file_jsons: | 342 if not file_path in file_jsons: |
345 file_jsons[file_path] = ReadJson(file_path) | 343 file_jsons[file_path] = ReadJson(file_path) |
346 | 344 |
347 expansion = file_jsons[file_path] | 345 expansion = file_jsons[file_path] |
348 for k in lookup_path[1:]: | 346 for k in lookup_path[1:]: |
349 expansion = expansion[k] | 347 expansion = expansion[k] |
350 | 348 |
351 new_args[i] = arg[:start] + str(expansion) + arg[end + 1:] | 349 new_args[i] = arg[:match.start()] + str(expansion) |
| 350 |
352 return new_args | 351 return new_args |
353 | 352 |
OLD | NEW |