Skip to content

Commit

Permalink
Make read_config function available from native module.
Browse files Browse the repository at this point in the history
Summary: This is to make its usage consistent with other native functions.

Reviewed By: philipjameson

fbshipit-source-id: 8356519
  • Loading branch information
ttsugriy authored and facebook-github-bot committed Jun 5, 2018
1 parent 521e841 commit e2c6e76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python-dsl/buck_parser/buck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions python-dsl/buck_parser/processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e2c6e76

Please sign in to comment.