Commit 72bec66e authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

Make feature_compiler support non-default toolchains

This CL makes the feature_compiler support non-default toolchains by
avoiding assuming that the gen directory is always gen/.

Bug: 1129223
Change-Id: I2a361cbb1ce4a220fca03c8db6457f2fb03d81d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419815
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#808636}
parent 62c286d1
......@@ -717,7 +717,7 @@ class FeatureCompiler(object):
"""A compiler to load, parse, and generate C++ code for a number of
features.json files."""
def __init__(self, chrome_root, source_files, feature_type,
method_name, out_root, out_base_filename):
method_name, out_root, gen_dir_relpath, out_base_filename):
# See __main__'s ArgumentParser for documentation on these properties.
self._chrome_root = chrome_root
self._source_files = source_files
......@@ -725,6 +725,7 @@ class FeatureCompiler(object):
self._method_name = method_name
self._out_root = out_root
self._out_base_filename = out_base_filename
self._gen_dir_relpath = gen_dir_relpath
# The json value for the feature files.
self._json = {}
......@@ -860,10 +861,7 @@ class FeatureCompiler(object):
header_file = self._out_base_filename + '.h'
cc_file = self._out_base_filename + '.cc'
include_file_root = self._out_root
GEN_DIR_PREFIX = 'gen/'
if include_file_root.startswith(GEN_DIR_PREFIX):
include_file_root = include_file_root[len(GEN_DIR_PREFIX):]
include_file_root = self._out_root[len(self._gen_dir_relpath)+1:]
header_file_path = '%s/%s' % (include_file_root, header_file)
cc_file_path = '%s/%s' % (include_file_root, cc_file)
substitutions = ({
......@@ -906,6 +904,9 @@ if __name__ == '__main__':
help='The name of the method to populate the provider')
parser.add_argument('out_root', type=str,
help='The root directory to generate the C++ files into')
parser.add_argument('gen_dir_relpath', default='gen', help='Path of the '
'gen directory relative to the out/. If running in the default '
'toolchain, the path is gen, otherwise $toolchain_name/gen')
parser.add_argument(
'out_base_filename', type=str,
help='The base filename for the C++ files (.h and .cc will be appended)')
......@@ -915,7 +916,7 @@ if __name__ == '__main__':
if args.feature_type not in FEATURE_TYPES:
raise NameError('Unknown feature type: %s' % args.feature_type)
c = FeatureCompiler(args.chrome_root, args.source_files, args.feature_type,
args.method_name, args.out_root,
args.method_name, args.out_root, args.gen_dir_relpath,
args.out_base_filename)
c.Load()
c.Compile()
......
......@@ -22,7 +22,7 @@ class FeatureCompilerTest(unittest.TestCase):
def _createTestFeatureCompiler(self, feature_class):
return feature_compiler.FeatureCompiler('chrome_root', [], feature_class,
'provider_class', 'out_root', 'out_base_filename')
'provider_class', 'out_root', 'gen', 'out_base_filename')
def _hasError(self, f, error):
"""Asserts that |error| is present somewhere in the given feature's
......@@ -349,7 +349,7 @@ class FeatureCompilerTest(unittest.TestCase):
def testComplexParentWithoutDefaultParent(self):
c = feature_compiler.FeatureCompiler(
None, None, 'APIFeature', None, None, None)
None, None, 'APIFeature', None, None, None, None)
c._CompileFeature('bookmarks',
[{
'contexts': ['blessed_extension'],
......@@ -382,7 +382,7 @@ class FeatureCompilerTest(unittest.TestCase):
def testHostedAppsCantUseAllowlistedFeatures_ComplexFeature(self):
c = feature_compiler.FeatureCompiler(
None, None, 'PermissionFeature', None, None, None)
None, None, 'PermissionFeature', None, None, None, None)
c._CompileFeature('invalid_feature',
[{
'extension_types': ['extension'],
......@@ -414,7 +414,7 @@ class FeatureCompilerTest(unittest.TestCase):
def testHostedAppsCantUseAllowlistedFeatures_ChildFeature(self):
c = feature_compiler.FeatureCompiler(
None, None, 'PermissionFeature', None, None, None)
None, None, 'PermissionFeature', None, None, None, None)
c._CompileFeature('parent',
{
'extension_types': ['hosted_app'],
......
......@@ -42,6 +42,7 @@ template("json_features") {
"$feature_type",
"$method_name",
rebase_path(target_gen_dir, root_build_dir),
rebase_path(root_gen_dir, root_build_dir),
"$base_filename",
] + rebased
......
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