diff options
| author | 0x221E <0x221E@0xinfinity.dev> | 2026-04-12 16:59:40 +0200 |
|---|---|---|
| committer | 0x221E <0x221E@0xinfinity.dev> | 2026-04-12 16:59:40 +0200 |
| commit | a66c7433c2c11b8b6c99142277ed4e16b1a2a465 (patch) | |
| tree | e54bcfb59c303acf6118fd11f06d5c0bd5f24e5d /external/gtest/fake_fuchsia_sdk.bzl | |
Diffstat (limited to 'external/gtest/fake_fuchsia_sdk.bzl')
| -rw-r--r-- | external/gtest/fake_fuchsia_sdk.bzl | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/external/gtest/fake_fuchsia_sdk.bzl b/external/gtest/fake_fuchsia_sdk.bzl new file mode 100644 index 0000000..bc5b927 --- /dev/null +++ b/external/gtest/fake_fuchsia_sdk.bzl @@ -0,0 +1,61 @@ +"""Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available. + +GoogleTest can be used with the [Fuchsia](https://fuchsia.dev/) SDK. However, +because the Fuchsia SDK does not yet support bzlmod, GoogleTest's `MODULE.bazel` +file by default provides a "fake" Fuchsia SDK. + +To override this and use the real Fuchsia SDK, you can add the following to your +project's `MODULE.bazel` file: + + fake_fuchsia_sdk_extension = + use_extension("@com_google_googletest//:fake_fuchsia_sdk.bzl", "fuchsia_sdk") + override_repo(fake_fuchsia_sdk_extension, "fuchsia_sdk") + +NOTE: The `override_repo` built-in is only available in Bazel 8.0 and higher. + +See https://github.com/google/googletest/issues/4472 for more details of why the +fake Fuchsia SDK is needed. +""" + +def _fake_fuchsia_sdk_impl(repo_ctx): + for stub_target in repo_ctx.attr._stub_build_targets: + stub_package = stub_target + stub_target_name = stub_target.split("/")[-1] + repo_ctx.file("%s/BUILD.bazel" % stub_package, """ +filegroup( + name = "%s", +) +""" % stub_target_name) + +fake_fuchsia_sdk = repository_rule( + doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.", + implementation = _fake_fuchsia_sdk_impl, + attrs = { + "_stub_build_targets": attr.string_list( + doc = "The stub build targets to initialize.", + default = [ + "pkg/fdio", + "pkg/syslog", + "pkg/zx", + ], + ), + }, +) + +_create_fake = tag_class() + +def _fuchsia_sdk_impl(module_ctx): + create_fake_sdk = False + for mod in module_ctx.modules: + for _ in mod.tags.create_fake: + create_fake_sdk = True + + if create_fake_sdk: + fake_fuchsia_sdk(name = "fuchsia_sdk") + + return module_ctx.extension_metadata(reproducible = True) + +fuchsia_sdk = module_extension( + implementation = _fuchsia_sdk_impl, + tag_classes = {"create_fake": _create_fake}, +) |
