From 5bda46c02caea9dca23fab8adc0b50ba184124e7 Mon Sep 17 00:00:00 2001 From: maleo Date: Mon, 16 Dec 2024 18:15:53 +0000 Subject: [PATCH] Improve use_languages extension tag This obeys requested bindings from any module. --- .../MODULE.bazel | 28 ++++++ .../patches/add_module_bazel.patch | 88 +++++++++++++++++++ .../presubmit.yml | 9 ++ .../source.json | 9 ++ modules/googleapis/metadata.json | 3 +- 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/MODULE.bazel create mode 100644 modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/patches/add_module_bazel.patch create mode 100644 modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/presubmit.yml create mode 100644 modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/source.json diff --git a/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/MODULE.bazel b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/MODULE.bazel new file mode 100644 index 00000000000..7456c0cc505 --- /dev/null +++ b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/MODULE.bazel @@ -0,0 +1,28 @@ +module( + name = "googleapis", + version = "0.0.0-20240819-fe8ba054a.bcr.1", + repo_name = "com_google_googleapis", +) + +bazel_dep(name = "grpc", version = "1.66.0.bcr.2", repo_name = "com_github_grpc_grpc") +bazel_dep(name = "grpc-java", version = "1.66.0", repo_name = "io_grpc_grpc_java") +bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf") +bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go") +bazel_dep(name = "rules_proto", version = "5.3.0-21.7") +bazel_dep(name = "rules_python", version = "0.31.0") + +switched_rules = use_extension("//:extensions.bzl", "switched_rules") +switched_rules.use_languages( + cc = True, + # csharp = True, + # gapic = True, + go = True, + grpc = True, + java = True, + # nodejs = True, + # php = True, + python = True, + # ruby = True, + dev_dependency = True, +) +use_repo(switched_rules, "com_google_googleapis_imports") diff --git a/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/patches/add_module_bazel.patch b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/patches/add_module_bazel.patch new file mode 100644 index 00000000000..3fe3dc469f3 --- /dev/null +++ b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/patches/add_module_bazel.patch @@ -0,0 +1,88 @@ +diff --git a/MODULE.bazel b/MODULE.bazel +new file mode 100644 +index 000000000..7456c0cc5 +--- /dev/null ++++ b/MODULE.bazel +@@ -0,0 +1,28 @@ ++module( ++ name = "googleapis", ++ version = "0.0.0-20240819-fe8ba054a.bcr.1", ++ repo_name = "com_google_googleapis", ++) ++ ++bazel_dep(name = "grpc", version = "1.66.0.bcr.2", repo_name = "com_github_grpc_grpc") ++bazel_dep(name = "grpc-java", version = "1.66.0", repo_name = "io_grpc_grpc_java") ++bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf") ++bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go") ++bazel_dep(name = "rules_proto", version = "5.3.0-21.7") ++bazel_dep(name = "rules_python", version = "0.31.0") ++ ++switched_rules = use_extension("//:extensions.bzl", "switched_rules") ++switched_rules.use_languages( ++ cc = True, ++ # csharp = True, ++ # gapic = True, ++ go = True, ++ grpc = True, ++ java = True, ++ # nodejs = True, ++ # php = True, ++ python = True, ++ # ruby = True, ++ dev_dependency = True, ++) ++use_repo(switched_rules, "com_google_googleapis_imports") +diff --git a/extensions.bzl b/extensions.bzl +new file mode 100644 +index 000000000..fbf3936cb +--- /dev/null ++++ b/extensions.bzl +@@ -0,0 +1,48 @@ ++load(":repository_rules.bzl", "switched_rules_by_language") ++ ++_use_languages_tag = tag_class( ++ attrs = { ++ "cc": attr.bool(default = False), ++ "csharp": attr.bool(default = False), ++ "gapic": attr.bool(default = False), ++ "go": attr.bool(default = False), ++ "go_test": attr.bool(default = False), ++ "grpc": attr.bool(default = False), ++ "java": attr.bool(default = False), ++ "nodejs": attr.bool(default = False), ++ "php": attr.bool(default = False), ++ "python": attr.bool(default = False), ++ "ruby": attr.bool(default = False), ++ "dev_dependency": attr.bool(default = False), ++ }, ++) ++ ++def _switched_rules_impl(ctx): ++ attrs = {} ++ for module in ctx.modules: ++ for t in module.tags.use_languages: ++ if t.dev_dependency and not module.is_root: ++ continue ++ attrs["cc"] = attrs.get("cc", False) or t.cc ++ attrs["csharp"] = attrs.get("csharp", False) or t.csharp ++ attrs["gapic"] = attrs.get("gapic", False) or t.gapic ++ attrs["go"] = attrs.get("go", False) or t.go ++ attrs["go_test"] = attrs.get("go_test", False) or t.go_test ++ attrs["grpc"] = attrs.get("grpc", False) or t.grpc ++ attrs["java"] = attrs.get("java", False) or t.java ++ attrs["nodejs"] = attrs.get("nodejs", False) or t.nodejs ++ attrs["php"] = attrs.get("php", False) or t.php ++ attrs["python"] = attrs.get("python", False) or t.python ++ attrs["ruby"] = attrs.get("ruby", False) or t.ruby ++ ++ switched_rules_by_language( ++ name = "com_google_googleapis_imports", ++ **attrs ++ ) ++ ++switched_rules = module_extension( ++ implementation = _switched_rules_impl, ++ tag_classes = { ++ "use_languages": _use_languages_tag, ++ }, ++) diff --git a/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/presubmit.yml b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/presubmit.yml new file mode 100644 index 00000000000..cc0d04ed6d6 --- /dev/null +++ b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/presubmit.yml @@ -0,0 +1,9 @@ +matrix: + platform: ["debian10", "macos", "ubuntu2004", "windows"] + bazel: ["7.x", "8.x"] +tasks: + verify_targets: + platform: ${{ platform }} + bazel: ${{ bazel }} + build_targets: + - '@googleapis//google/devtools/source/v1:source_proto' diff --git a/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/source.json b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/source.json new file mode 100644 index 00000000000..5ee5e062800 --- /dev/null +++ b/modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/source.json @@ -0,0 +1,9 @@ +{ + "integrity": "sha256-BRPw9Ar2O9Bdx4nKzDNKts7CfMidtZZVfLLf6JGUY+Q=", + "strip_prefix": "googleapis-fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0", + "url": "https://github.com/googleapis/googleapis/archive/fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0.tar.gz", + "patch_strip": 1, + "patches": { + "add_module_bazel.patch": "sha256-F5aJnkwjhnlSqq5CBiRMucjAGkNXzf2R59F2hbupLrQ=" + } +} diff --git a/modules/googleapis/metadata.json b/modules/googleapis/metadata.json index 49396c3abc7..d96d7fe57bf 100644 --- a/modules/googleapis/metadata.json +++ b/modules/googleapis/metadata.json @@ -11,7 +11,8 @@ ], "versions": [ "0.0.0-20240326-1c8d509c5", - "0.0.0-20240819-fe8ba054a" + "0.0.0-20240819-fe8ba054a", + "0.0.0-20240819-fe8ba054a.bcr.1" ], "yanked_versions": {} }