Skip to content

Commit 20a0cda

Browse files
JwataLUCI CQ
authored andcommitted
ninjalog_uploader: Distinguish between explicit and default build configs
This CL adds `explicit_build_config_keys` to the metadata for the server to distinguish between explicit and default configs. This CL excludes the configs set in `//.gn` from the list, so that the configs specified by users will be considered as explicit. Bug: 364971744 Change-Id: I6a3d289d8ca6e054dac691051b53c92ad1ec23c5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5853009 Commit-Queue: Junji Watanabe <[email protected]> Reviewed-by: Takuto Ikuta <[email protected]>
1 parent 17226d7 commit 20a0cda

File tree

2 files changed

+68
-52
lines changed

2 files changed

+68
-52
lines changed

ninjalog_uploader.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ def ParseGNArgs(gn_args):
5050
"""Parse gn_args as json and return config dictionary."""
5151
configs = json.loads(gn_args)
5252
build_configs = {}
53+
explicit_keys = []
5354
user = getpass.getuser()
5455

5556
for config in configs:
5657
key = config["name"]
5758
if "current" in config:
5859
value = config["current"]["value"]
60+
# Record configs specified in args.gn as explicit configs.
61+
if config["current"]["file"] != "//.gn":
62+
explicit_keys.append(key)
5963
else:
6064
value = config["default"]["value"]
6165
value = value.strip('"')
@@ -68,7 +72,7 @@ def ParseGNArgs(gn_args):
6872
])
6973
build_configs[key] = value
7074

71-
return build_configs
75+
return build_configs, explicit_keys
7276

7377

7478
def GetBuildTargetFromCommandLine(cmdline):
@@ -132,15 +136,16 @@ def GetMetadata(cmdline, ninjalog, exit_code, build_duration, user):
132136
build_dir = os.path.dirname(ninjalog)
133137

134138
build_configs = {}
139+
explicit_keys = []
135140

136141
try:
137-
args = ["gn", "args", build_dir, "--list", "--short", "--json"]
142+
args = ["gn", "args", build_dir, "--list", "--json"]
138143
if sys.platform == "win32":
139144
# gn in PATH is bat file in windows environment (except cygwin).
140145
args = ["cmd", "/c"] + args
141146

142147
gn_args = subprocess.check_output(args)
143-
build_configs = ParseGNArgs(gn_args)
148+
build_configs, explicit_keys = ParseGNArgs(gn_args)
144149
except subprocess.CalledProcessError as e:
145150
logging.error("Failed to call gn %s", e)
146151
build_configs = {}
@@ -156,6 +161,7 @@ def GetMetadata(cmdline, ninjalog, exit_code, build_duration, user):
156161
"platform": platform.system(),
157162
"cpu_core": multiprocessing.cpu_count(),
158163
"build_configs": build_configs,
164+
"explicit_build_config_keys": explicit_keys,
159165
"targets": GetBuildTargetFromCommandLine(cmdline),
160166
}
161167

tests/ninjalog_uploader_test.py

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,74 @@
1818
class NinjalogUploaderTest(unittest.TestCase):
1919

2020
def test_parse_gn_args(self):
21-
self.assertEqual(ninjalog_uploader.ParseGNArgs(json.dumps([])), {})
21+
gn_args, explicit_keys = ninjalog_uploader.ParseGNArgs(json.dumps([]))
22+
self.assertEqual(gn_args, {})
23+
self.assertEqual(explicit_keys, [])
2224

2325
# Extract current configs from GN's output json.
24-
self.assertEqual(
25-
ninjalog_uploader.ParseGNArgs(
26-
json.dumps([
27-
{
28-
'current': {
29-
'value': 'true'
30-
},
31-
'default': {
32-
'value': 'false'
33-
},
34-
'name': 'is_component_build'
26+
gn_args, explicit_keys = ninjalog_uploader.ParseGNArgs(
27+
json.dumps([
28+
{
29+
'current': {
30+
'value': 'true',
31+
'file': '//path/to/args.gn',
3532
},
36-
{
37-
'default': {
38-
'value': '"x64"'
39-
},
40-
'name': 'host_cpu'
33+
'default': {
34+
'value': 'false'
4135
},
42-
])), {
43-
'is_component_build': 'true',
44-
'host_cpu': 'x64',
45-
})
46-
47-
self.assertEqual(
48-
ninjalog_uploader.ParseGNArgs(
49-
json.dumps([
50-
{
51-
'current': {
52-
'value': 'true'
53-
},
54-
'default': {
55-
'value': 'false'
56-
},
57-
'name': 'is_component_build'
36+
'name': 'is_component_build'
37+
},
38+
{
39+
'default': {
40+
'value': '"x64"'
5841
},
59-
{
60-
'current': {
61-
'value': 'false'
62-
},
63-
'default': {
64-
'value': 'false'
65-
},
66-
'name': 'use_remoteexec'
42+
'name': 'host_cpu'
43+
},
44+
]))
45+
46+
self.assertEqual(gn_args, {
47+
'is_component_build': 'true',
48+
'host_cpu': 'x64',
49+
})
50+
self.assertEqual(explicit_keys, ['is_component_build'])
51+
52+
gn_args, explicit_keys = ninjalog_uploader.ParseGNArgs(
53+
json.dumps([
54+
{
55+
'current': {
56+
'value': 'true',
57+
'file': '//.gn',
6758
},
68-
])), {
69-
'is_component_build': 'true',
70-
'use_remoteexec': 'false'
71-
})
59+
'default': {
60+
'value': 'false'
61+
},
62+
'name': 'is_component_build'
63+
},
64+
{
65+
'current': {
66+
'value': 'false',
67+
'file': '//path/to/args.gn',
68+
},
69+
'default': {
70+
'value': 'false'
71+
},
72+
'name': 'use_remoteexec'
73+
},
74+
]))
75+
self.assertEqual(gn_args, {
76+
'is_component_build': 'true',
77+
'use_remoteexec': 'false'
78+
})
79+
self.assertEqual(explicit_keys, ['use_remoteexec'])
7280

7381
# Do not include sensitive information.
7482
with unittest.mock.patch('getpass.getuser', return_value='bob'):
75-
args = ninjalog_uploader.ParseGNArgs(
83+
gn_args, explicit_keys = ninjalog_uploader.ParseGNArgs(
7684
json.dumps([
7785
{
7886
'current': {
79-
'value': 'xyz'
87+
'value': 'xyz',
88+
'file': '//path/to/args.gn',
8089
},
8190
'default': {
8291
'value': ''
@@ -85,7 +94,8 @@ def test_parse_gn_args(self):
8594
},
8695
{
8796
'current': {
88-
'value': '/home/bob/bobo'
97+
'value': '/home/bob/bobo',
98+
'file': '//path/to/args.gn',
8999
},
90100
'default': {
91101
'value': ''
@@ -94,7 +104,7 @@ def test_parse_gn_args(self):
94104
},
95105
]))
96106
self.assertEqual(
97-
args, {
107+
gn_args, {
98108
'google_api_key': '<omitted>',
99109
'path_with_homedir': '/home/$USER/bobo',
100110
})

0 commit comments

Comments
 (0)