Commit 2d4a5ab6 authored by cjhopman@chromium.org's avatar cjhopman@chromium.org

Change FileArg syntax

This changes the syntax from:
 @(filepath:key0:key1)
to:
 @FileArg(filepath:key0:key1)

This should make it much easier for someone who encounters this syntax
to figure out what it is (currently a `git grep FileArg` returns only
results about/using this feature).

Also changes it to use a simple regex search instead of adhoc stuff.

BUG=359249

Review URL: https://codereview.chromium.org/377803003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283484 0039d316-1c4b-4281-b951-d872f2087c98
parent 7ee85d62
...@@ -8,6 +8,7 @@ import fnmatch ...@@ -8,6 +8,7 @@ import fnmatch
import json import json
import os import os
import pipes import pipes
import re
import shlex import shlex
import shutil import shutil
import subprocess import subprocess
...@@ -315,7 +316,7 @@ def ExpandFileArgs(args): ...@@ -315,7 +316,7 @@ def ExpandFileArgs(args):
"""Replaces file-arg placeholders in args. """Replaces file-arg placeholders in args.
These placeholders have the form: These placeholders have the form:
@(filename:key1:key2:...:keyn) @FileArg(filename:key1:key2:...:keyn)
The value of such a placeholder is calculated by reading 'filename' as json. The value of such a placeholder is calculated by reading 'filename' as json.
And then extracting the value at [key1][key2]...[keyn]. And then extracting the value at [key1][key2]...[keyn].
...@@ -327,19 +328,16 @@ def ExpandFileArgs(args): ...@@ -327,19 +328,16 @@ def ExpandFileArgs(args):
""" """
new_args = list(args) new_args = list(args)
file_jsons = dict() file_jsons = dict()
r = re.compile('@FileArg\((.*?)\)')
for i, arg in enumerate(args): for i, arg in enumerate(args):
start = arg.find('@(') match = r.search(arg)
if start < 0: if not match:
continue continue
end = arg[start:].find(')')
if end < 0:
continue
end += start
if '@(' in arg[end:]: if match.end() != len(arg):
raise Exception('Only one file-lookup-expansion is allowed in each arg.') raise Exception('Unexpected characters after FileArg: ' + arg)
lookup_path = arg[start + 2:end].split(':') lookup_path = match.group(1).split(':')
file_path = lookup_path[0] file_path = lookup_path[0]
if not file_path in file_jsons: if not file_path in file_jsons:
file_jsons[file_path] = ReadJson(file_path) file_jsons[file_path] = ReadJson(file_path)
...@@ -348,6 +346,7 @@ def ExpandFileArgs(args): ...@@ -348,6 +346,7 @@ def ExpandFileArgs(args):
for k in lookup_path[1:]: for k in lookup_path[1:]:
expansion = expansion[k] expansion = expansion[k]
new_args[i] = arg[:start] + str(expansion) + arg[end + 1:] new_args[i] = arg[:match.start()] + str(expansion)
return new_args return new_args
...@@ -20,7 +20,7 @@ Android build scripts should not refer to the build_config directly, and the ...@@ -20,7 +20,7 @@ Android build scripts should not refer to the build_config directly, and the
build specification should instead pass information in using the special build specification should instead pass information in using the special
file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing
of values in a json dict in a file and looks like this: of values in a json dict in a file and looks like this:
--python-arg=@(build_config_path:javac:classpath) --python-arg=@FileArg(build_config_path:javac:classpath)
Note: If paths to input files are passed in this way, it is important that: Note: If paths to input files are passed in this way, it is important that:
1. inputs/deps of the action ensure that the files are available the first 1. inputs/deps of the action ensure that the files are available the first
......
...@@ -17,7 +17,7 @@ rebased_android_sdk_build_tools = rebase_path(android_sdk_build_tools, root_buil ...@@ -17,7 +17,7 @@ rebased_android_sdk_build_tools = rebase_path(android_sdk_build_tools, root_buil
# require knowledge about this target's dependencies and cannot be calculated # require knowledge about this target's dependencies and cannot be calculated
# at gn-time). There is a special syntax to add a value in that dictionary to # at gn-time). There is a special syntax to add a value in that dictionary to
# an action/action_foreachs args: # an action/action_foreachs args:
# --python-arg=@($rebased_build_config_path:key0:key1) # --python-arg=@FileArg($rebased_build_config_path:key0:key1)
# At runtime, such an arg will be replaced by the value in the build_config. # At runtime, such an arg will be replaced by the value in the build_config.
# See build/android/gyp/write_build_config.py and # See build/android/gyp/write_build_config.py and
# build/android/gyp/util/build_utils.py:ExpandFileArgs # build/android/gyp/util/build_utils.py:ExpandFileArgs
...@@ -182,10 +182,10 @@ template("java_library") { ...@@ -182,10 +182,10 @@ template("java_library") {
args = [ args = [
"--depfile=$rebase_depfile", "--depfile=$rebase_depfile",
"--classpath=$rebase_system_jars", "--classpath=$rebase_system_jars",
"--classpath=@($rebase_build_config:javac:classpath)", "--classpath=@FileArg($rebase_build_config:javac:classpath)",
"--jar-path=$rebase_jar_path", "--jar-path=$rebase_jar_path",
"--java-srcjars=$rebase_java_srcjars", "--java-srcjars=$rebase_java_srcjars",
"--java-srcjars=@($rebase_build_config:javac:srcjars)", "--java-srcjars=@FileArg($rebase_build_config:javac:srcjars)",
"--jar-excluded-classes=$jar_excluded_patterns", "--jar-excluded-classes=$jar_excluded_patterns",
] ]
if (chromium_code) { if (chromium_code) {
...@@ -300,7 +300,7 @@ template("process_resources") { ...@@ -300,7 +300,7 @@ template("process_resources") {
"--srcjar-out", rebase_path(srcjar_path, root_build_dir), "--srcjar-out", rebase_path(srcjar_path, root_build_dir),
"--resource-zip-out", rebase_path(zip_path, root_build_dir), "--resource-zip-out", rebase_path(zip_path, root_build_dir),
"--dependencies-res-zips=@($rebase_build_config:resources:dependency_zips)", "--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)",
] ]
if (defined(invoker.custom_package)) { if (defined(invoker.custom_package)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment