Skip to content

Commit

Permalink
Add notices.txt with information about our dependencies' license and …
Browse files Browse the repository at this point in the history
…add --notices flag to protoc to print the content of that file.

PiperOrigin-RevId: 723971692
  • Loading branch information
deannagarcia authored and copybara-github committed Feb 7, 2025
1 parent 9f2b36d commit 13ca8cf
Show file tree
Hide file tree
Showing 6 changed files with 331 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map
local:
*;
};")

# Create notices.h from notices.txt
function(notices_as_header input_file output_header)
file(READ "${input_file}" notice_contents)
file(WRITE "${output_header}" "const char* notices_text = R\"(${notice_contents})\";\n")
endfunction()

notices_as_header("src/google/protobuf/compiler/notices.txt" "src/google/protobuf/compiler/notices.h")

# CheckLinkerFlag module available in CMake >=3.18.
if(${CMAKE_VERSION} VERSION_GREATER 3.18 OR ${CMAKE_VERSION} VERSION_EQUAL 3.18)
include(CheckLinkerFlag)
Expand Down
29 changes: 16 additions & 13 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ module(
# Bzlmod follows MVS:
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
# Thus the highest version in their module graph is resolved.

# LINT.IfChange
# protoc dependencies
bazel_dep(name = "abseil-cpp", version = "20240722.0", repo_name = "com_google_absl")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "jsoncpp", version = "1.9.6")
bazel_dep(name = "rules_apple", version = "3.13.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "apple_support", version = "1.15.1", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_jvm_external", version = "6.3")
bazel_dep(name = "rules_kotlin", version = "1.9.6")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "1.0.0")
bazel_dep(name = "rules_rust", version = "0.51.0")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
# LINT.ThenChange(//depot/google3/third_party/protobuf/compiler/notices.txt)

# other dependencies
bazel_dep(name = "rules_apple", version = "3.13.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "apple_support", version = "1.15.1", repo_name = "build_bazel_apple_support")
bazel_dep(name = "bazel_features", version = "1.23.0", repo_name = "proto_bazel_features")
bazel_dep(
name = "rules_shell",
version = "0.2.0",
)
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "jsoncpp", version = "1.9.6")
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_jvm_external", version = "6.3")
bazel_dep(name = "rules_kotlin", version = "1.9.6")
bazel_dep(name = "rules_rust", version = "0.51.0")
bazel_dep(name = "rules_shell", version = "0.2.0")

# Proto toolchains
register_toolchains("//bazel/private/toolchains:all")
Expand Down
1 change: 1 addition & 0 deletions cmake/installed_include_golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ google/protobuf/compiler/java/java_features.pb.h
google/protobuf/compiler/java/name_resolver.h
google/protobuf/compiler/java/names.h
google/protobuf/compiler/java/options.h
google/protobuf/compiler/notices.h
google/protobuf/compiler/objectivec/line_consumer.h
google/protobuf/compiler/objectivec/names.h
google/protobuf/compiler/objectivec/nsobject_methods.h
Expand Down
13 changes: 13 additions & 0 deletions src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ proto_library(
deps = ["//:descriptor_proto"],
)

# Generate notices.h from notices.txt to import in cli.
genrule(
name = "notices_header",
srcs = ["notices.txt"],
outs = ["notices.h"],
cmd = """
echo 'const char* notices_text = R"(' > $@
cat $< >> $@
echo ')";' >> $@
""",
)

cc_proto_library(
name = "plugin_cc_proto",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -179,6 +191,7 @@ cc_library(
"command_line_interface.h",
"subprocess.h",
"zip_writer.h",
":notices_header",
],
copts = COPTS,
strip_include_prefix = "/src",
Expand Down
10 changes: 8 additions & 2 deletions src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "absl/types/span.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/importer.h"
#include "google/protobuf/compiler/notices.h"
#include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/compiler/retention.h"
#include "google/protobuf/compiler/subprocess.h"
Expand Down Expand Up @@ -2004,7 +2005,8 @@ bool CommandLineInterface::ParseArgument(const char* arg, std::string* name,
*name == "--experimental_editions" ||
*name == "--print_free_field_numbers" ||
*name == "--experimental_allow_proto3_optional" ||
*name == "--deterministic_output" || *name == "--fatal_warnings") {
*name == "--deterministic_output" || *name == "--fatal_warnings" ||
*name == "--notices") {
// HACK: These are the only flags that don't take a value.
// They probably should not be hard-coded like this but for now it's
// not worth doing better.
Expand Down Expand Up @@ -2322,6 +2324,9 @@ CommandLineInterface::InterpretArgument(const std::string& name,
// life-ruining bugs *anyways*. As such, there is a reasonable probability
// that there isn't another thread kicking environment variables at this
// moment.
} else if (name == "--notices") {
std::cout << notices_text << std::endl;
return PARSE_ARGUMENT_DONE_AND_EXIT;

#ifdef _WIN32
::_putenv(absl::StrCat(io::Printer::kProtocCodegenTrace, "=yes").c_str());
Expand Down Expand Up @@ -2502,7 +2507,8 @@ Parse PROTO_FILES and generate output based on the options given:
are counted as occupied fields numbers.
--enable_codegen_trace Enables tracing which parts of protoc are
responsible for what codegen output. Not supported
by all backends or on all platforms.)";
by all backends or on all platforms.
--notices Show notice file and exit.)";
if (!plugin_prefix_.empty()) {
std::cout << R"(
--plugin=EXECUTABLE Specifies a plugin executable to use.
Expand Down
Loading

0 comments on commit 13ca8cf

Please sign in to comment.