1"""Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available. 2 3This is needed since bazel queries on targets that depend on //:gtest (eg: 4`bazel query "deps(set(//googletest/test:gtest_all_test))"`) will fail if @fuchsia_sdk is not 5defined when bazel is evaluating the transitive closure of the query target. 6 7See https://github.com/google/googletest/issues/4472. 8""" 9 10def _fake_fuchsia_sdk_impl(repo_ctx): 11 for stub_target in repo_ctx.attr._stub_build_targets: 12 stub_package = stub_target 13 stub_target_name = stub_target.split("/")[-1] 14 repo_ctx.file("%s/BUILD.bazel" % stub_package, """ 15filegroup( 16 name = "%s", 17) 18""" % stub_target_name) 19 20fake_fuchsia_sdk = repository_rule( 21 doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.", 22 implementation = _fake_fuchsia_sdk_impl, 23 attrs = { 24 "_stub_build_targets": attr.string_list( 25 doc = "The stub build targets to initialize.", 26 default = [ 27 "pkg/fdio", 28 "pkg/syslog", 29 "pkg/zx", 30 ], 31 ), 32 }, 33) 34