From c3e847dcc5b84d059d330eddc1a4412d0f437b83 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Fri, 20 Dec 2024 14:01:16 -0800 Subject: [PATCH 1/2] Fix cmake installation location of java and go features Fixes #19735, will be backported to 29.x PiperOrigin-RevId: 708420839 --- cmake/install.cmake | 23 +++++++++++++++------- go/BUILD.bazel | 14 ++++++++++++- go/{ => google/protobuf}/go_features.proto | 0 pkg/BUILD.bazel | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) rename go/{ => google/protobuf}/go_features.proto (100%) diff --git a/cmake/install.cmake b/cmake/install.cmake index bf565098443e4..b383a98c50fe3 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -89,6 +89,7 @@ set(protobuf_HEADERS ${descriptor_proto_proto_srcs} ${plugin_proto_proto_srcs} ${java_features_proto_proto_srcs} + ${go_features_proto_proto_srcs} ) if (protobuf_BUILD_LIBUPB) list(APPEND protobuf_HEADERS ${libupb_hdrs}) @@ -101,14 +102,22 @@ if (protobuf_BUILD_LIBUPB) COMPONENT protobuf-headers ) endif () +set(protobuf_STRIP_PREFIXES + "/src" + "/java/core/src/main/resources" + "/go" + "/" +) foreach(_header ${protobuf_HEADERS}) - string(FIND ${_header} "${protobuf_SOURCE_DIR}/src" _find_src) - string(FIND ${_header} "${protobuf_SOURCE_DIR}" _find_nosrc) - if (_find_src GREATER -1) - set(_from_dir "${protobuf_SOURCE_DIR}/src") - elseif (_find_nosrc GREATER -1) - set(_from_dir "${protobuf_SOURCE_DIR}") - endif() + foreach(_strip_prefix ${protobuf_STRIP_PREFIXES}) + string(FIND ${_header} "${protobuf_SOURCE_DIR}${_strip_prefix}" _find_src) + if(_find_src GREATER -1) + set(_from_dir "${protobuf_SOURCE_DIR}${_strip_prefix}") + break() + endif() + endforeach() + message(${_from_dir} "-" ${_header}) + # Escape _from_dir for regex special characters in the directory name. string(REGEX REPLACE "([$^.[|*+?()]|])" "\\\\\\1" _from_dir_regexp "${_from_dir}") # On some platforms `_form_dir` ends up being just "protobuf", which can diff --git a/go/BUILD.bazel b/go/BUILD.bazel index c1cb8d7dba662..d773b29499d04 100644 --- a/go/BUILD.bazel +++ b/go/BUILD.bazel @@ -1,5 +1,17 @@ +load("//bazel:proto_library.bzl", "proto_library") + filegroup( name = "go_features_proto_srcs", - srcs = ["go_features.proto"], + srcs = ["google/protobuf/go_features.proto"], visibility = ["//:__subpackages__"], ) + +proto_library( + name = "go_features_proto", + srcs = ["google/protobuf/go_features.proto"], + strip_import_prefix = "/go", + visibility = [ + "//pkg:__pkg__", + ], + deps = ["//:descriptor_proto"], +) diff --git a/go/go_features.proto b/go/google/protobuf/go_features.proto similarity index 100% rename from go/go_features.proto rename to go/google/protobuf/go_features.proto diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 792f11c155e63..99f0cab0d7270 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -121,6 +121,7 @@ gen_file_lists( "//src/google/protobuf:descriptor_proto": "descriptor_proto", "//src/google/protobuf/compiler:plugin_proto": "plugin_proto", "//java/core:java_features_proto": "java_features_proto,src/google/protobuf/compiler/java/", + "//go:go_features_proto": "go_features_proto,go/", # Test libraries: ":common_test": "common_test", From fae97eb5b2a06a9ff1261a017e0f46fb9e532f30 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Fri, 20 Dec 2024 14:35:13 -0800 Subject: [PATCH 2/2] Regenerate stale files --- src/file_lists.cmake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 559c15fe3cd6b..104a296d11105 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -928,6 +928,26 @@ set(java_features_proto_files ${protobuf_SOURCE_DIR}/java/core/java_features_proto-descriptor-set.proto.bin ) +# @//go:go_features_proto +set(go_features_proto_proto_srcs + ${protobuf_SOURCE_DIR}/go/google/protobuf/go_features.proto +) + +# @//go:go_features_proto +set(go_features_proto_srcs + ${protobuf_SOURCE_DIR}/go/go_features.proto.pb.cc +) + +# @//go:go_features_proto +set(go_features_proto_hdrs + ${protobuf_SOURCE_DIR}/go/go_features.proto.pb.h +) + +# @//go:go_features_proto +set(go_features_proto_files + ${protobuf_SOURCE_DIR}/go/go_features_proto-descriptor-set.proto.bin +) + # @//pkg:common_test set(common_test_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface_tester.cc