fake_fuchsia_sdk.bzl (1974B)
1 """Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available. 2 3 GoogleTest can be used with the [Fuchsia](https://fuchsia.dev/) SDK. However, 4 because the Fuchsia SDK does not yet support bzlmod, GoogleTest's `MODULE.bazel` 5 file by default provides a "fake" Fuchsia SDK. 6 7 To override this and use the real Fuchsia SDK, you can add the following to your 8 project's `MODULE.bazel` file: 9 10 fake_fuchsia_sdk_extension = 11 use_extension("@com_google_googletest//:fake_fuchsia_sdk.bzl", "fuchsia_sdk") 12 override_repo(fake_fuchsia_sdk_extension, "fuchsia_sdk") 13 14 NOTE: The `override_repo` built-in is only available in Bazel 8.0 and higher. 15 16 See https://github.com/google/googletest/issues/4472 for more details of why the 17 fake Fuchsia SDK is needed. 18 """ 19 20 def _fake_fuchsia_sdk_impl(repo_ctx): 21 for stub_target in repo_ctx.attr._stub_build_targets: 22 stub_package = stub_target 23 stub_target_name = stub_target.split("/")[-1] 24 repo_ctx.file("%s/BUILD.bazel" % stub_package, """ 25 filegroup( 26 name = "%s", 27 ) 28 """ % stub_target_name) 29 30 fake_fuchsia_sdk = repository_rule( 31 doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.", 32 implementation = _fake_fuchsia_sdk_impl, 33 attrs = { 34 "_stub_build_targets": attr.string_list( 35 doc = "The stub build targets to initialize.", 36 default = [ 37 "pkg/fdio", 38 "pkg/syslog", 39 "pkg/zx", 40 ], 41 ), 42 }, 43 ) 44 45 _create_fake = tag_class() 46 47 def _fuchsia_sdk_impl(module_ctx): 48 create_fake_sdk = False 49 for mod in module_ctx.modules: 50 for _ in mod.tags.create_fake: 51 create_fake_sdk = True 52 53 if create_fake_sdk: 54 fake_fuchsia_sdk(name = "fuchsia_sdk") 55 56 return module_ctx.extension_metadata(reproducible = True) 57 58 fuchsia_sdk = module_extension( 59 implementation = _fuchsia_sdk_impl, 60 tag_classes = {"create_fake": _create_fake}, 61 )