def test_go_binary_parses(self, root): buckfile = "testing/BUCK" root.addFile( buckfile, dedent(""" load("@fbcode_macros//build_defs:go_binary.bzl", "go_binary") go_binary( name = "foo", deps = [":otherArtifact"], licenses = ["LICENSE"], visibility = None, ) """), ) expected = { buckfile: dedent(r""" go_binary( name = "foo", licenses = [ "LICENSE", ], platform = "default-gcc", deps = [ "//testing:otherArtifact", ], visibility = [ "PUBLIC", ], ) """) } self.validateAudit(expected, root.runAudit([buckfile]))
def test_helper_util_runs_properly(self, root): platform_overrides = dedent( """\ platform_overrides = {"fbcode": { "foo/bar": ["gcc5-other", "gcc5"], "foo/bar-other": ["gcc5-other"], "foo": ["gcc6"], "": ["gcc7"], }} """ ) root.project.cells["fbcode_macros"].addFile( "build_defs/platform_overrides.bzl", platform_overrides ) result = root.run([ "buck", "run", "fbcode_macros//tools:get_platform", "foo/bar", "foo/bar-other", "foo/baz", "foo", "foobar", ], {}, {}) self.assertSuccess(result) expected = dedent(""" foo/bar:gcc5 foo/bar-other:gcc6 foo/baz:gcc6 foo:gcc6 foobar:gcc7 """) + "\n" self.assertEqual(expected, result.stdout)
def test_copy_genrule_output_file_creates_correct_rule(self, root): root.addFile("other/BUCK", dedent(""" genrule( name="main", cmd='mkdir -p "$OUT" && echo 1 > $OUT/out1; echo 2 > $OUT/out2', out="outdir", visibility=["PUBLIC"], ) """)) root.addFile("BUCK", dedent(""" load("@fbcode_macros//build_defs:custom_rule.bzl", "copy_genrule_output_file") copy_genrule_output_file( name_prefix="main", genrule_target="//other:main", filename="out1", visibility=["PUBLIC"], ) """)) result = root.run(["buck", "build", "--show-output", "//:"], {}, {}) self.assertSuccess(result) outputs = {} for line in result.stdout.strip().split("\n"): parts = line.split(None, 1) outputs[parts[0]] = os.path.join(root.fullPath(), parts[1]) self.assertTrue(os.path.exists(outputs["//:main=out1"])) with open(outputs["//:main=out1"]) as fin: self.assertEqual("1", fin.read().decode('utf-8').strip())
def test_export_files_exports_multiple_files(self, root): root.add_file("file1.sh", "echo file1") root.add_file("file2.sh", "echo file2") root.add_file("file3.sh", "echo file3") root.add_file("file4.sh", "echo file4") root.add_file("file5.sh", "echo file5") root.add_file("file6.sh", "echo file6") root.add_file( "BUCK", dedent( """\ load("@fbcode_macros//build_defs:export_files.bzl", "export_files") export_files(["file1.sh", "file2.sh"]) export_files(["file3.sh", "file4.sh"], visibility=[]) export_files(["file5.sh", "file6.sh"], visibility=[], mode="copy") """ ) ) expected = dedent( """\ export_file( name = "file1.sh", mode = "reference", visibility = [ "PUBLIC", ], ) export_file( name = "file2.sh", mode = "reference", visibility = [ "PUBLIC", ], ) export_file( name = "file3.sh", mode = "reference", ) export_file( name = "file4.sh", mode = "reference", ) export_file( name = "file5.sh", mode = "copy", ) export_file( name = "file6.sh", mode = "copy", ) """ ) result = root.run_audit(["BUCK"]) self.validateAudit({"BUCK": expected}, result)
def test_output_can_be_used(self, root): # Quick integration test root.addFile("gen.sh", dedent(""" cat > $INSTALL_DIR/main.h <<EOF #pragma once struct Printer { static void print(); }; EOF cat > $INSTALL_DIR/main.cpp <<EOF #include "main.h" #include <iostream> using namespace std; void Printer::print() { cout << "Hello, world" << endl; } int main() { Printer::print(); return 0; } EOF """), executable=True) root.addFile("BUCK", dedent(""" load("@fbcode_macros//build_defs:custom_rule.bzl", "custom_rule") load("@fbcode_macros//build_defs:native_rules.bzl", "buck_sh_binary") buck_sh_binary(name = "gen.sh", main = "gen.sh") custom_rule( name = "foo", build_script_dep = ":gen.sh", output_gen_files = ["main.h", "main.cpp"], ) cxx_binary( name = "main", srcs = [":foo=main.cpp"], headers = [":foo=main.h"], ) """)) result = root.run(["buck", "run", "//:main"], {}, {}) self.assertSuccess(result) self.assertEquals("Hello, world", result.stdout.decode('utf-8').strip())
def test_copy_rule_creates_genrules(self, root): root.addFile( "BUCK", dedent( """ load("@fbcode_macros//build_defs/lib:copy_rule.bzl", "copy_rule") copy_rule( "$(location :foo)", "simple", ) copy_rule( "$(location :foo)", "simple_with_out", out="some_out", ) copy_rule( "$(location :foo)", "propagates_versions", propagate_versions=True, ) """ ), ) expected = dedent( r""" cxx_genrule( name = "propagates_versions", cmd = "mkdir -p `dirname $OUT` && cp $(location :foo) $OUT", labels = [ "is_fully_translated", ], out = "propagates_versions", ) genrule( name = "simple", cmd = "mkdir -p `dirname $OUT` && cp $(location :foo) $OUT", labels = [ "is_fully_translated", ], out = "simple", ) genrule( name = "simple_with_out", cmd = "mkdir -p `dirname $OUT` && cp $(location :foo) $OUT", labels = [ "is_fully_translated", ], out = "some_out", ) """ ) result = root.runAudit(["BUCK"]) self.validateAudit({"BUCK": expected}, result)
def test_default_headers_library_works(self, root): buckfile = "subdir/BUCK" root.addFile( buckfile, dedent(""" load("@fbcode_macros//build_defs/lib:cpp_common.bzl", "cpp_common") cpp_common.default_headers_library() cpp_common.default_headers_library() """), ) files = [ "subdir/foo.cpp", "subdir/foo.h", "subdir/foo.hh", "subdir/foo.tcc", "subdir/foo.hpp", "subdir/foo.cuh", "subdir/foo/bar.cpp", "subdir/foo/bar.h", "subdir/foo/bar.hh", "subdir/foo/bar.tcc", "subdir/foo/bar.hpp", "subdir/foo/bar.cuh", ] for file in files: root.addFile(file, "") expected = { buckfile: dedent(r""" cxx_library( name = "__default_headers__", default_platform = "default-gcc", defaults = { "platform": "default-gcc", }, exported_headers = [ "foo.cuh", "foo.h", "foo.hh", "foo.hpp", "foo.tcc", "foo/bar.cuh", "foo/bar.h", "foo/bar.hh", "foo/bar.hpp", "foo/bar.tcc", ], labels = [ "is_fully_translated", ], ) """) } self.validateAudit(expected, root.runAudit([buckfile]))
def test_ocaml_external_library_parses(self, root): buckfile = "third-party-buck/default/build/foo/BUCK" root.addFile( buckfile, dedent(""" load("@fbcode_macros//build_defs:ocaml_external_library.bzl", "ocaml_external_library") ocaml_external_library( name = "re2", bytecode_libs = [ "share/dotopam/default/lib/re2/re2.cma", ], c_libs = [ "share/dotopam/default/lib/re2/libre2_stubs.a", ], include_dirs = [ "share/dotopam/default/lib/re2", ], native_libs = [ "share/dotopam/default/lib/re2/re2.cmxa", ], external_deps = [ ("bar", None, "baz"), ("foo", None, "bar"), ], native = False, ) """), ) expected = { buckfile: dedent(r""" prebuilt_ocaml_library( name = "re2", bytecode_lib = "share/dotopam/default/lib/re2/re2.cma", bytecode_only = True, c_libs = [ "share/dotopam/default/lib/re2/libre2_stubs.a", ], include_dir = "share/dotopam/default/lib/re2", lib_dir = "", lib_name = "re2", native_lib = "share/dotopam/default/lib/re2/re2.cmxa", deps = [ "//third-party-buck/default/build/bar:baz", "//third-party-buck/default/build/foo:bar", "//third-party-buck/default/build/foo:__project__", ], visibility = [ "PUBLIC", ], ) """) } self.validateAudit(expected, root.runAudit([buckfile]))
def test_build_args_work_with_unicode_strings(self, root): root.addFile("BUCK", dedent(""" load("@fbcode_macros//build_defs:custom_rule.bzl", "custom_rule") custom_rule( name="foobar", build_script_dep="//:main_script", build_args=u"foo", output_gen_files=["out1"], no_remote=True, ) """)) expected_cmd = ( 'mkdir -p \\"$OUT\\" && ' 'env ' 'BUCK_PLATFORM=default-gcc ' 'FBCODE_BUILD_MODE=dev ' 'FBCODE_BUILD_TOOL=buck ' 'FBCODE_PLATFORM=default ' 'FBCODE_THIRD_PARTY_TOOLS= ' 'INSTALL_DIR=\\"$OUT\\" ' 'PATH=\\"$PATH\\" ' 'SRCDIR=\\"$SRCDIR\\" ' '$(exe //:main_script) ' '--install_dir=\\"$OUT\\" ' 'foo' ) expected = dedent(''' genrule( name = "foobar", cmd = "''' + self._getCopyCommand("foobar", "out1") + '''", out = "out1", visibility = [ "PUBLIC", ], ) genrule( name = "foobar-outputs", cmd = \"''' + expected_cmd + '''\", no_remote = True, out = "foobar-outputs", ) genrule( name = "foobar=out1", cmd = "''' + self._getCopyCommand("foobar", "out1") + '''", out = "out1", visibility = [ "PUBLIC", ], ) ''') result = root.runAudit(["BUCK"]) self.validateAudit({"BUCK": expected}, result)
def test_creates_typing_rule_if_enabled_in_config_and_params(self, root): root.addFile("file1.sh", "echo file1") root.addFile("file2.sh", "echo file2") root.updateBuckconfig("python", "typing_config", "//python:typing") root.addFile( "BUCK", dedent("""\ load("@fbcode_macros//build_defs:export_files.bzl", "export_file") export_file(name="file1.sh") export_file(name="file2.sh", create_typing_rule=False) """), ) expected = dedent("""\ export_file( name = "file1.sh", labels = [ "is_fully_translated", ], mode = "reference", visibility = [ "PUBLIC", ], ) genrule( name = "file1.sh-typing", cmd = "mkdir -p \\"$OUT\\"", labels = [ "is_fully_translated", ], out = "root", visibility = [ "PUBLIC", ], ) export_file( name = "file2.sh", labels = [ "is_fully_translated", ], mode = "reference", visibility = [ "PUBLIC", ], ) """) result = root.runAudit(["BUCK"]) self.validateAudit({"BUCK": expected}, result)
def test_buck_export_file_exports_copy_mode_by_default(self, root): root.addFile("file1.sh", "echo file1") root.addFile("file2.sh", "echo file2") root.addFile("file3.sh", "echo file3") root.addFile( "BUCK", dedent("""\ load("@fbcode_macros//build_defs:export_files.bzl", "buck_export_file") buck_export_file(name="file1.sh") buck_export_file(name="file2.sh", mode="reference") buck_export_file(name="file3.sh", mode="copy") """), ) expected = dedent("""\ export_file( name = "file1.sh", labels = [ "is_fully_translated", ], visibility = [ "PUBLIC", ], ) export_file( name = "file2.sh", labels = [ "is_fully_translated", ], mode = "reference", visibility = [ "PUBLIC", ], ) export_file( name = "file3.sh", labels = [ "is_fully_translated", ], mode = "copy", visibility = [ "PUBLIC", ], ) """) result = root.runAudit(["BUCK"]) self.validateAudit({"BUCK": expected}, result)
def test_export_file_handles_visibility(self, root): root.addFile("file1.sh", "echo file1") root.addFile("file2.sh", "echo file2") root.addFile("file3.sh", "echo file3") root.addFile( "BUCK", dedent("""\ load("@fbcode_macros//build_defs:export_files.bzl", "export_file") export_file(name="file1.sh") export_file(name="file2.sh", visibility=["//..."]) export_file(name="file3.sh", visibility=None) """), ) expected = dedent("""\ export_file( name = "file1.sh", labels = [ "is_fully_translated", ], mode = "reference", visibility = [ "PUBLIC", ], ) export_file( name = "file2.sh", labels = [ "is_fully_translated", ], mode = "reference", visibility = [ "//...", ], ) export_file( name = "file3.sh", labels = [ "is_fully_translated", ], mode = "reference", visibility = [ "PUBLIC", ], ) """) result = root.runAudit(["BUCK"]) self.validateAudit({"BUCK": expected}, result)
def test_rust_external_library_parses(self, root): buckfile = "third-party-buck/default/build/foo/BUCK" root.addFile( buckfile, dedent( """ load("@fbcode_macros//build_defs:rust_external_library.bzl", "rust_external_library") rust_external_library( name = "libsqlite3-sys-0.9.3", crate = "libsqlite3_sys", # MIT licenses = ["licenses/MIT/MIT.txt"], rlib = "rlib/liblibsqlite3_sys-104f194a162d4a87.rlib", visibility = None, deps = [ ":pkg-config-0.3.14", ], external_deps = [ ("foo", None, "bar"), ], ) """ ), ) expected = { buckfile: dedent( r""" prebuilt_rust_library( name = "libsqlite3-sys-0.9.3", crate = "libsqlite3_sys", licenses = [ "licenses/MIT/MIT.txt", ], rlib = "rlib/liblibsqlite3_sys-104f194a162d4a87.rlib", deps = [ "//third-party-buck/default/build/foo:pkg-config-0.3.14", "//third-party-buck/default/build/foo:bar", ], visibility = [ "PUBLIC", ], ) """ ) } self.validateAudit(expected, root.runAudit([buckfile]))
def test_transform_platform_overrides_fails_with_invalid_platform( self, root ): # This should be a load time error platform_overrides = dedent( """\ platform_overrides = { "fbcode": { "foo/bar": ["gcc5", "invalid-platform"], }, } """ ) root.project.cells["fbcode_macros"].addFile( "build_defs/third_party_config.bzl", self.third_party_config ) root.project.cells["fbcode_macros"].addFile( "build_defs/platform_overrides.bzl", platform_overrides ) result = root.runUnitTests( self.includes, ["platform_utils.get_platform_overrides()"] ) self.assertFailureWithMessage( result, "Path foo/bar has invalid platform invalid-platform. Must be one " "of gcc5, gcc5-other, gcc6, gcc7" )
def test_transform_platform_overrides(self, root): # This should be a load time error platform_overrides = dedent( """\ platform_overrides = { "fbcode": { "foo/bar": ["gcc5", "gcc5-other"], "foo": ["gcc7"], }, } """ ) root.project.cells["fbcode_macros"].addFile( "build_defs/third_party_config.bzl", self.third_party_config ) root.project.cells["fbcode_macros"].addFile( "build_defs/platform_overrides.bzl", platform_overrides ) expected = { "fbcode": { "foo/bar": { self.other_arch: "gcc5-other", self.current_arch: "gcc5" }, "foo": { self.current_arch: "gcc7" } } } result = root.runUnitTests( self.includes, ["platform_utils.get_platform_overrides()"] ) self.assertSuccess(result, expected)
def test_swig_library_parses(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:swig_library.bzl", "swig_library") swig_library( name = "foo_module", cpp_deps = [ ":some_cpp_dep", ], interface = "Foo.i", java_library_name = "FooLib", java_package = "org.example.foo", languages = [ "py", "java", "go", ], module = "Foo", py_base_module = "", go_package_name = "swig", ) """), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_base_name_gets_correct_platform_for_various_directories_and_archs( self, root ): platform_overrides = dedent( """\ platform_overrides = {"fbcode": { "foo/bar": ["gcc5-other", "gcc5"], "foo/bar-other": ["gcc5-other"], "foo": ["gcc6"], "": ["gcc7"], }} """ ) root.project.cells["fbcode_macros"].addFile( "build_defs/third_party_config.bzl", self.third_party_config ) root.project.cells["fbcode_macros"].addFile( "build_defs/platform_overrides.bzl", platform_overrides ) statements = [ 'platform_utils.get_platform_for_base_path("foo/bar")', 'platform_utils.get_platform_for_base_path("foo/bar-other")', 'platform_utils.get_platform_for_base_path("foo/baz")', 'platform_utils.get_platform_for_base_path("foo")', 'platform_utils.get_platform_for_base_path("foobar")', ] result = root.runUnitTests(self.includes, statements) self.assertSuccess(result, "gcc5", "gcc6", "gcc6", "gcc6", "gcc7")
def test_transform_platform_overrides_fails_with_duplicate_platforms_for_arch( self, root ): # This should be a load time error platform_overrides = dedent( """\ platform_overrides = { "fbcode": { "foo/bar": ["gcc5", "gcc7"], }, } """ ) root.project.cells["fbcode_macros"].addFile( "build_defs/third_party_config.bzl", self.third_party_config ) root.project.cells["fbcode_macros"].addFile( "build_defs/platform_overrides.bzl", platform_overrides ) result = root.runUnitTests( self.includes, ["platform_utils.get_platform_overrides()"] ) self.assertFailureWithMessage( result, "Path foo/bar has both platform gcc5 and gcc7 for architecture %s" % self.current_arch )
def test_cpp_java_extension_parses(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:cpp_java_extension.bzl", "cpp_java_extension") cpp_java_extension( name = "AgentCpp", srcs = [ "Agent.cpp", "AgentHelpers.cpp", ], headers = [ "AgentHelpers.h", ], lib_name = "agent", deps = [ "//folly:string", ], external_deps = [ ("glog", None, "glog"), ], ) """), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_d_unittest_parses(self, root): root.addFile( "BUCK", dedent( """ load("@fbcode_macros//build_defs:d_unittest.bzl", "d_unittest") d_unittest( name = "MainBin", srcs = [ "MainBin.d", ], linker_flags = [ "--script=$(location :linker_script)", ], deps = [ "//folly:singleton", ], tags = ["some_tag"], ) """ ), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_get_correct_build_mode_for_base_path(self, root): build_mode_override = dedent(""" load( "@fbcode_macros//build_defs:create_build_mode.bzl", "create_build_mode", ) def dev(): return { "dev": create_build_mode(c_flags=["-DDEBUG"]), } def dbg(): return { "dbg": create_build_mode(c_flags=["-DDEBUG"]), } def opt(): return { "opt": create_build_mode(c_flags=["-DDEBUG"]), } build_mode_overrides = {"fbcode": { "foo/bar": dev, "foo/bar-other": dbg, "foo": opt, }} """) root.project.cells["fbcode_macros"].add_file( "build_defs/build_mode_overrides.bzl", build_mode_override) result = root.run_unittests(self.includes, [ 'build_mode.get_build_modes_for_base_path("foo/bar/baz")', 'build_mode.get_build_modes_for_base_path("foo/bar")', 'build_mode.get_build_modes_for_base_path("foo/bar-other")', 'build_mode.get_build_modes_for_base_path("foo/baz")', 'build_mode.get_build_modes_for_base_path("foo")', 'build_mode.get_build_modes_for_base_path("foobar")', ]) expected = self.struct(aspp_flags=(), cpp_flags=(), cxxpp_flags=(), c_flags=["-DDEBUG"], cxx_flags=(), ld_flags=(), clang_flags=(), gcc_flags=(), java_flags=(), dmd_flags=(), gdc_flags=(), ldc_flags=(), par_flags=(), ghc_flags=()) self.assertSuccess( result, {'dev': expected}, {'dev': expected}, {'dbg': expected}, {'opt': expected}, {'opt': expected}, {}, )
def test_python_library_parses(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:python_library.bzl", "python_library") python_library( name = "my_python_lib", base_module = "terrible.feature", cpp_deps = ["//:cpp_lib"], deps = ["//:python_lib"], external_deps = [ "pyyaml", ("six", None, "six"), ], gen_srcs = ["//:deprecated=feature.py"], py_flavor = "", resources = {"src.py": "dest.py"}, srcs = [ "not_a_python_source", "src.py", ], tags = ["foo"], tests = ["//:python_lib_test"], typing = True, typing_options = "pyre", versioned_srcs = [(">2", ["new.py"])], ) """), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_haskell_ghci_parses(self, root): root.addFile( "BUCK", dedent( """ load("@fbcode_macros//build_defs:haskell_ghci.bzl", "haskell_ghci") haskell_ghci( name = "ghci", srcs = [ "Foo.hs", ], compiler_flags = [ "-fexternal-interpreter", ], packages = [ "ghc", "split", ], warnings_flags = [ "-Wwarn", ], deps = [ ":dep", ], ) """ ), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_cpp2_options_copy_to_py3_options_in_py3_rules(self, root): root.updateBuckconfig("thrift", "compiler", "//:compiler") root.updateBuckconfig("thrift", "compiler2", "//:compiler") root.updateBuckconfig("cython", "cython_compiler", "//:compiler") root.updateBuckconfig("thrift", "templates", "//:templates") contents = dedent(""" load("@fbcode_macros//build_defs:thrift_library.bzl", "thrift_library") sh_binary(name="compiler", main="compiler.sh") filegroup(name="templates", srcs=glob(["*"])) thrift_library( name = "name", thrift_srcs={"service.thrift": []}, languages=[ "py3", "cpp2", ], thrift_cpp2_options="BLAH", ) """) root.addFile("BUCK", contents) root.addFile("compiler.sh", "", executable=True) root.addFile("service.thrift", "") result = root.run( ["buck", "query", "--json", "--output-attribute=cmd", "//:"], {}, {}) self.assertSuccess(result) self.assertIn( "BLAH", json.loads(result.stdout)["//:name-py3-service.thrift"]["cmd"])
def test_go_bindgen_library_parses(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:go_bindgen_library.bzl", "go_bindgen_library") go_bindgen_library( name = "client", package_name = "c", srcs = [ "client.go", ], go_external_deps = [ "github.com/pkg/errors", ], header_includes = [ "//c/foo_c.h", ], manifest = "manifest.yml", deps = [ "//c:c_api", ], ) """), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_prints_error_message(self, root): buckfile = dedent(r""" load( "@fbcode_macros//build_defs:missing_tp2_project.bzl", "missing_tp2_project", ) missing_tp2_project( name="foo_some_long_project_name", project="really_long_project", platform="random_platform", ) cxx_binary( name = "main", srcs = ["main.cpp"], deps = [":foo_some_long_project_name"], ) """) root.addFile("BUCK", buckfile) root.addFile("main.cpp", "int main() { return 0; }") result = root.run(["buck", "build", "//:main"], {}, {}) self.assertFailureWithMessage( result, ('ERROR: foo_some_long_project_name: project ' + '"really_long_project" does\n not exist for ' + 'platform "random_platform"')) self.assertFalse("java.nio.file.NoSuchFileException" in result.stderr, msg="Found NoSuchFileException in %s" % result.stderr)
def test_gated_rules_reject_on_non_whitelisted(self, root): whitelist = ("cxx_library=foo:bar_lib," "cxx_library=foo:bar_bin," "cxx_test=foo:bar_test") root.updateBuckconfig("fbcode", "forbid_raw_buck_rules", "true") root.updateBuckconfig("fbcode", "whitelisted_raw_buck_rules", whitelist) prefix = dedent(""" load( "@fbcode_macros//build_defs:native_rules.bzl", "buck_cxx_binary", "buck_cxx_library", "buck_cxx_test" ) """) target1 = prefix + '\nbuck_cxx_binary(name="bin", srcs=["main.cpp"])' target2 = prefix + '\nbuck_cxx_library(name="lib", srcs=["lib.cpp"])' target3 = prefix + '\nbuck_cxx_test(name="test", srcs=["test.cpp"])' root.addFile("target1/BUCK", target1) root.addFile("target2/BUCK", target2) root.addFile("target3/BUCK", target3) result1 = root.runAudit(["target1/BUCK"]) result2 = root.runAudit(["target2/BUCK"]) result3 = root.runAudit(["target3/BUCK"]) self.assertFailureWithMessage( result1, "Unsupported access to Buck rules!", "cxx_binary(): native rule target1:bin is not whitelisted") self.assertFailureWithMessage( result2, "Unsupported access to Buck rules!", "cxx_library(): native rule target2:bin is not whitelisted") self.assertFailureWithMessage( result3, "Unsupported access to Buck rules!", "cxx_test(): native rule target3:bin is not whitelisted")
def test_sphinx_wiki_parses(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:sphinx_wiki.bzl", "sphinx_wiki") sphinx_wiki( name = "docs", srcs = [ "README.rst", ], config = { "conf.py": { "default_role": "fb:wut", #T32942441 "extlinks": { "sphinx-doc": "http://www.sphinx-doc.org/en/master/%s;", }, }, "sphinx-build": { "treat_warnings_as_errors": True, }, }, genrule_srcs = { "//fbsphinx:commands_documentor": "guide/commands", "//fbsphinx:extensions_documentor": "guide/reStructuredText", }, python_library_deps = [ "//fbsphinx:lib", "//fbsphinx:bin", ], wiki_root_path = "fbsphinx", ) """), ) self.assertSuccess(root.runAudit(["BUCK"]))
def test_fails_if_tool_rule_does_not_exist(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:custom_rule.bzl", "custom_rule") load("@fbcode_macros//build_defs:native_rules.bzl", "buck_sh_binary") buck_sh_binary(name="main.sh", main="main.sh") custom_rule( name="foobar", build_script_dep="//:main.sh", tools=["cc"], output_gen_files=["out1"], ) """), ) root.addFile("main.sh", 'touch "$OUT"; exit 0;', executable=True) result = root.run(["buck", "build", "//:foobar"], {}, {}) self.assertFailureWithMessage( result, "No build file at third-party-buck/default/tools/BUCK when " "resolving target //third-party-buck/default/tools:cc/bin", "This error happened while trying to get dependency " "'//third-party-buck/default/tools:cc/bin' of target " "'//:foobar-outputs'", )
def test_cpp_benchmark_parses(self, root): root.addFile( "BUCK", dedent(""" load("@fbcode_macros//build_defs:cpp_benchmark.bzl", "cpp_benchmark") cpp_benchmark( name = "benchmark", srcs = [ "bench.cpp", ], headers = [ "bench.h", ], deps = [ ":some_dep", ], ) cpp_benchmark( name = "benchmark2", srcs = [ "bench2.cpp", ], headers = { "bench2.h": "subdir/bench2.h", }, deps = [ ":some_dep", ], ) """), ) self.assertSuccess(root.runAudit(["BUCK"]))