ninja: error if trying to build for use_remoteexec=true
Change-Id: Ia32dd3cba1d1874401c6614f792f212b2cfa60a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5660200 Commit-Queue: Joanna Wang <jojwang@chromium.org> Reviewed-by: Junji Watanabe <jwata@google.com> Reviewed-by: Takuto Ikuta <tikuta@chromium.org> Auto-Submit: Fumitoshi Ukai <ukai@google.com> Reviewed-by: Joanna Wang <jojwang@chromium.org>changes/00/5660200/8
parent
f4e8e13e8b
commit
356ef0324e
@ -0,0 +1,60 @@
|
||||
# Copyright 2024 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
"""This provides an easy way to access args.gn."""
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def _gn_lines(output_dir, path):
|
||||
"""
|
||||
Generator function that returns args.gn lines one at a time, following
|
||||
import directives as needed.
|
||||
"""
|
||||
import_re = re.compile(r'\s*import\("(.*)"\)')
|
||||
with open(path, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
match = import_re.match(line)
|
||||
if match:
|
||||
raw_import_path = match.groups()[0]
|
||||
if raw_import_path[:2] == "//":
|
||||
import_path = os.path.normpath(
|
||||
os.path.join(output_dir, "..", "..",
|
||||
raw_import_path[2:]))
|
||||
else:
|
||||
import_path = os.path.normpath(
|
||||
os.path.join(os.path.dirname(path), raw_import_path))
|
||||
yield from _gn_lines(output_dir, import_path)
|
||||
else:
|
||||
yield line
|
||||
|
||||
|
||||
def _path(output_dir):
|
||||
return os.path.join(output_dir, "args.gn")
|
||||
|
||||
|
||||
def exists(output_dir):
|
||||
"""Checks args.gn exists in output_dir."""
|
||||
return os.path.exists(_path(output_dir))
|
||||
|
||||
|
||||
def lines(output_dir):
|
||||
"""Generator of args.gn lines. comment is removed."""
|
||||
if not exists(output_dir):
|
||||
return
|
||||
for line in _gn_lines(output_dir, _path(output_dir)):
|
||||
line_without_comment = line.split("#")[0]
|
||||
yield line_without_comment
|
||||
|
||||
|
||||
_gn_arg_pattern = re.compile(r"(^|\s)([^=\s]*)\s*=\s*(\S*)\s*$")
|
||||
|
||||
|
||||
def args(output_dir):
|
||||
"""Generator of args.gn's key,value pair."""
|
||||
for line in lines(output_dir):
|
||||
m = _gn_arg_pattern.match(line)
|
||||
if not m:
|
||||
continue
|
||||
yield (m.group(2), m.group(3))
|
@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env vpython3
|
||||
# Copyright (c) 2024 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, ROOT_DIR)
|
||||
|
||||
import gn_helper
|
||||
from testing_support import trial_dir
|
||||
|
||||
|
||||
def write(filename, content):
|
||||
"""Writes the content of a file and create the directories as needed."""
|
||||
filename = os.path.abspath(filename)
|
||||
dirname = os.path.dirname(filename)
|
||||
if not os.path.isdir(dirname):
|
||||
os.makedirs(dirname)
|
||||
with open(filename, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
class GnHelperTest(trial_dir.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.previous_dir = os.getcwd()
|
||||
os.chdir(self.root_dir)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.previous_dir)
|
||||
super().tearDown()
|
||||
|
||||
def test_lines(self):
|
||||
out_dir = os.path.join('out', 'dir')
|
||||
# Make sure nested import directives work. This is based on the
|
||||
# reclient test.
|
||||
write(os.path.join(out_dir, 'args.gn'), 'import("//out/common.gni")')
|
||||
write(os.path.join('out', 'common.gni'), 'import("common_2.gni")')
|
||||
write(os.path.join('out', 'common_2.gni'), 'use_remoteexec=true')
|
||||
|
||||
lines = list(gn_helper.lines(out_dir))
|
||||
|
||||
# The test will only pass if both imports work and
|
||||
# 'use_remoteexec=true' is seen.
|
||||
self.assertListEqual(lines, [
|
||||
'use_remoteexec=true',
|
||||
])
|
||||
|
||||
def test_args(self):
|
||||
out_dir = os.path.join('out', 'dir')
|
||||
# Make sure nested import directives work. This is based on the
|
||||
# reclient test.
|
||||
write(os.path.join(out_dir, 'args.gn'), 'import("//out/common.gni")')
|
||||
write(os.path.join('out', 'common.gni'), 'import("common_2.gni")')
|
||||
write(os.path.join('out', 'common_2.gni'), 'use_remoteexec=true')
|
||||
|
||||
lines = list(gn_helper.args(out_dir))
|
||||
|
||||
# The test will only pass if both imports work and
|
||||
# 'use_remoteexec=true' is seen.
|
||||
self.assertListEqual(lines, [
|
||||
('use_remoteexec', 'true'),
|
||||
])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue