From e2c6e76dd71859e1f9e28673c4c9e7c6f0e29631 Mon Sep 17 00:00:00 2001 From: Taras Tsugrii Date: Tue, 5 Jun 2018 15:18:53 -0700 Subject: [PATCH] Make read_config function available from native module. Summary: This is to make its usage consistent with other native functions. Reviewed By: philipjameson fbshipit-source-id: 8356519 --- python-dsl/buck_parser/buck.py | 2 ++ python-dsl/buck_parser/processor_test.py | 26 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/python-dsl/buck_parser/buck.py b/python-dsl/buck_parser/buck.py index 3a7a7e4fa43..edd04eef97b 100644 --- a/python-dsl/buck_parser/buck.py +++ b/python-dsl/buck_parser/buck.py @@ -786,8 +786,10 @@ def _create_native_module(self): self._install_builtins(native_globals, force_native_rules=True) assert 'glob' not in native_globals assert 'host_info' not in native_globals + assert 'read_config' not in native_globals native_globals['glob'] = self._glob native_globals['host_info'] = self._host_info + native_globals['read_config'] = self._read_config native_module_type = collections.namedtuple('native', native_globals.keys()) return native_module_type(**native_globals) diff --git a/python-dsl/buck_parser/processor_test.py b/python-dsl/buck_parser/processor_test.py index 7cd503f36a2..2a8fb5dba5c 100644 --- a/python-dsl/buck_parser/processor_test.py +++ b/python-dsl/buck_parser/processor_test.py @@ -783,6 +783,32 @@ def test_native_module_is_available(self): build_file.root, build_file.prefix, build_file.path, diagnostics) self.assertEqual(rules[0].get('srcs'), ['BUCK', 'ext.bzl']) + def test_can_access_read_config_via_native_module(self): + extension_file = ProjectFile( + self.project_root, + path='ext.bzl', + contents=( + 'def get_name():' + ' return native.read_config("foo", "bar", "baz")', + ) + ) + build_file = ProjectFile( + self.project_root, + path='BUCK', + contents=( + 'load("//:ext.bzl", "get_name")', + 'foo_rule(', + ' name=get_name(),' + ')' + )) + self.write_files(extension_file, build_file) + build_file_processor = self.create_build_file_processor(extra_funcs=[foo_rule]) + diagnostics = [] + with build_file_processor.with_builtins(__builtin__.__dict__): + rules = build_file_processor.process( + build_file.root, build_file.prefix, build_file.path, diagnostics) + self.assertEqual(rules[0].get('name'), 'baz') + def test_rule_does_not_exist_if_not_defined(self): package_dir = os.path.join(self.project_root, 'pkg') os.makedirs(package_dir)