mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[ninjalog_uploader] Add BuildTargetFromCommandLine function
This function extracts build target from command line. Bug: 900161 Change-Id: I38d37689a42437de76933ea3c9afb9def5a1253c Reviewed-on: https://chromium-review.googlesource.com/c/1381911 Commit-Queue: Takuto Ikuta <tikuta@chromium.org> Reviewed-by: Shinya Kawanaka <shinyak@chromium.org>
This commit is contained in:
@@ -46,6 +46,34 @@ def ParseGNArgs(gn_args):
|
|||||||
build_configs[config["name"]] = config["current"]["value"]
|
build_configs[config["name"]] = config["current"]["value"]
|
||||||
return build_configs
|
return build_configs
|
||||||
|
|
||||||
|
def GetBuildTargetFromCommandLine(cmdline):
|
||||||
|
"""Get build targets from commandline."""
|
||||||
|
|
||||||
|
# Skip argv0.
|
||||||
|
idx = 1
|
||||||
|
|
||||||
|
# Skipping all args that involve these flags, and taking all remaining args
|
||||||
|
# as targets.
|
||||||
|
onearg_flags = ('-C', '-f', '-j', '-k', '-l', '-d', '-t', '-w')
|
||||||
|
zeroarg_flags = ('--version', '-n', '-v')
|
||||||
|
|
||||||
|
targets = []
|
||||||
|
|
||||||
|
while idx < len(cmdline):
|
||||||
|
if cmdline[idx] in onearg_flags:
|
||||||
|
idx += 2
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (cmdline[idx][:2] in onearg_flags or
|
||||||
|
cmdline[idx] in zeroarg_flags):
|
||||||
|
idx += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
targets.append(cmdline[idx])
|
||||||
|
idx += 1
|
||||||
|
|
||||||
|
return targets
|
||||||
|
|
||||||
|
|
||||||
def GetMetadata(cmdline, ninjalog):
|
def GetMetadata(cmdline, ninjalog):
|
||||||
"""Get metadata for uploaded ninjalog."""
|
"""Get metadata for uploaded ninjalog."""
|
||||||
|
|||||||
@@ -63,6 +63,28 @@ class NinjalogUploaderTest(unittest.TestCase):
|
|||||||
['ninja', '-C', 'out/Release', '-C', 'out/Debug']),
|
['ninja', '-C', 'out/Release', '-C', 'out/Debug']),
|
||||||
'out/Debug/.ninja_log')
|
'out/Debug/.ninja_log')
|
||||||
|
|
||||||
|
def test_get_build_target_from_command_line(self):
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja', 'chrome']), ['chrome'])
|
||||||
|
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja']), [])
|
||||||
|
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja', '-j', '1000', 'chrome']), ['chrome'])
|
||||||
|
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja', 'chrome', '-j', '1000']), ['chrome'])
|
||||||
|
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja', '-C', 'chrome']), [])
|
||||||
|
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja', '-Cout/Release', 'chrome']), ['chrome'])
|
||||||
|
|
||||||
|
self.assertEqual(ninjalog_uploader.GetBuildTargetFromCommandLine(
|
||||||
|
['ninja', '-C', 'out/Release', 'chrome', 'all']), ['chrome', 'all'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user