Skip to content

Commit

Permalink
Migrated upb to use Copybara-standard stripping.
Browse files Browse the repository at this point in the history
This CL is mostly a no-op, except that now google3-only code is actually stripped from OSS, instead of being preserved in `# begin:google_only` blocks.

This follows the conventions of the greater Copybara ecosystem.

PiperOrigin-RevId: 669513564
  • Loading branch information
haberman authored and copybara-github committed Aug 31, 2024
1 parent e4449ba commit 8422e97
Show file tree
Hide file tree
Showing 50 changed files with 38 additions and 1,245 deletions.
6 changes: 0 additions & 6 deletions bazel/private/upb_proto_library_internal/aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ load("//bazel/common:proto_info.bzl", "ProtoInfo")
load(":upb_proto_library_internal/cc_library_func.bzl", "cc_library_func")
load(":upb_proto_library_internal/copts.bzl", "UpbProtoLibraryCoptsInfo")

# begin:github_only
_is_google3 = False
# end:github_only

# begin:google_only
# _is_google3 = True
# end:google_only

GeneratedSrcsInfo = provider(
"Provides generated headers and sources",
Expand Down
26 changes: 0 additions & 26 deletions bazel/private/upb_proto_library_internal/cc_library_func.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,9 @@

load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")

# begin:google_only
#
# def upb_use_cpp_toolchain():
# # TODO: We shouldn't need to add this to the result of use_cpp_toolchain().
# return [
# config_common.toolchain_type(
# "@bazel_tools//tools/cpp:cc_runtimes_toolchain_type",
# mandatory = False,
# ),
# ] + use_cpp_toolchain()
#
# end:google_only

# begin:github_only
def upb_use_cpp_toolchain():
return use_cpp_toolchain()

# end:github_only

def cc_library_func(ctx, name, hdrs, srcs, copts, includes, dep_ccinfos):
"""Like cc_library(), but callable from rules.
Expand All @@ -37,16 +21,6 @@ def cc_library_func(ctx, name, hdrs, srcs, copts, includes, dep_ccinfos):
CcInfo provider for this compilation.
"""

# begin:google_only
# cc_runtimes_toolchain = ctx.toolchains["@bazel_tools//tools/cpp:cc_runtimes_toolchain_type"]
# if cc_runtimes_toolchain:
# dep_ccinfos += [
# target[CcInfo]
# for target in cc_runtimes_toolchain.cc_runtimes_info.runtimes
# ]
#
# end:google_only

compilation_contexts = [info.compilation_context for info in dep_ccinfos]
linking_contexts = [info.linking_context for info in dep_ccinfos]
toolchain = find_cpp_toolchain(ctx)
Expand Down
6 changes: 0 additions & 6 deletions benchmarks/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
load("//bazel:proto_library.bzl", "proto_library")

# begin:google_only
# _is_google3 = True
# end:google_only

# begin:github_only
_is_google3 = False
# end:github_only

def tmpl_cc_binary(name, gen, args, replacements = [], **kwargs):
srcs = [name + ".cc"]
Expand Down
4 changes: 1 addition & 3 deletions hpb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ load(
"UPB_DEFAULT_CPPOPTS",
)

# begin:google_only
# package(default_applicable_licenses = ["//:license"])
# end:google_only
package(default_applicable_licenses = ["//:license"])

licenses(["notice"])

Expand Down
4 changes: 1 addition & 3 deletions hpb/backend/upb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

# begin:google_only
# package(default_applicable_licenses = ["//:license"])
# end:google_only
package(default_applicable_licenses = ["//:license"])

cc_library(
name = "upb",
Expand Down
26 changes: 0 additions & 26 deletions hpb/bazel/upb_cc_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,9 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
load("//bazel:upb_proto_library.bzl", "GeneratedSrcsInfo", "UpbWrappedCcInfo", "upb_proto_library_aspect")

# begin:google_only
#
# def upb_use_cpp_toolchain():
# # TODO: We shouldn't need to add this to the result of use_cpp_toolchain().
# return [
# config_common.toolchain_type(
# "@bazel_tools//tools/cpp:cc_runtimes_toolchain_type",
# mandatory = False,
# ),
# ] + use_cpp_toolchain()
#
# end:google_only

# begin:github_only
def upb_use_cpp_toolchain():
return use_cpp_toolchain()

# end:github_only

# Generic support code #########################################################

def _get_real_short_path(file):
Expand Down Expand Up @@ -80,16 +64,6 @@ def _cc_library_func(ctx, name, hdrs, srcs, copts, dep_ccinfos):
CcInfo provider for this compilation.
"""

# begin:google_only
# cc_runtimes_toolchain = ctx.toolchains["@bazel_tools//tools/cpp:cc_runtimes_toolchain_type"]
# if cc_runtimes_toolchain:
# dep_ccinfos += [
# target[CcInfo]
# for target in cc_runtimes_toolchain.cc_runtimes_info.runtimes
# ]
#
# end:google_only

compilation_contexts = [info.compilation_context for info in dep_ccinfos]
linking_contexts = [info.linking_context for info in dep_ccinfos]
toolchain = find_cpp_toolchain(ctx)
Expand Down
48 changes: 8 additions & 40 deletions hpb/hpb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,25 @@

namespace hpb {

// begin:google_only
absl::Status MessageAllocationError(SourceLocation loc) {
return absl::Status(absl::StatusCode::kInternal,
"Upb message allocation error", loc);
return absl::Status(absl::StatusCode::kUnknown,
"Upb message allocation error");
}

absl::Status ExtensionNotFoundError(int extension_number, SourceLocation loc) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrFormat("Extension %d not found", extension_number), loc);
absl::Status ExtensionNotFoundError(int ext_number, SourceLocation loc) {
return absl::Status(absl::StatusCode::kUnknown,
absl::StrFormat("Extension %d not found", ext_number));
}

absl::Status MessageEncodeError(upb_EncodeStatus status, SourceLocation loc) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrFormat("Upb message encoding error %d", status),
loc

);
absl::Status MessageEncodeError(upb_EncodeStatus s, SourceLocation loc) {
return absl::Status(absl::StatusCode::kUnknown, "Encoding error");
}

absl::Status MessageDecodeError(upb_DecodeStatus status, SourceLocation loc

) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrFormat("Upb message parse error %d", status), loc

);
return absl::Status(absl::StatusCode::kUnknown, "Upb message parse error");
}
// end:google_only

// begin:github_only
// absl::Status MessageAllocationError(SourceLocation loc) {
// return absl::Status(absl::StatusCode::kUnknown,
// "Upb message allocation error");
// }
//
// absl::Status ExtensionNotFoundError(int ext_number, SourceLocation loc) {
// return absl::Status(absl::StatusCode::kUnknown,
// absl::StrFormat("Extension %d not found", ext_number));
// }
//
// absl::Status MessageEncodeError(upb_EncodeStatus s, SourceLocation loc) {
// return absl::Status(absl::StatusCode::kUnknown, "Encoding error");
// }
//
// absl::Status MessageDecodeError(upb_DecodeStatus status, SourceLocation loc
//
// ) {
// return absl::Status(absl::StatusCode::kUnknown, "Upb message parse error");
// }
// end:github_only

namespace internal {

Expand Down
20 changes: 7 additions & 13 deletions hpb/hpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ inline upb_StringView UpbStrFromStringView(absl::string_view str,
return upb_StringView_FromDataAndSize(buffer, str_size);
}

// begin:github_only
// // This type exists to work around an absl type that has not yet been
// // released.
// struct SourceLocation {
// static SourceLocation current() { return {}; }
// absl::string_view file_name() { return "<unknown>"; }
// int line() { return 0; }
// };
// end:github_only

// begin:google_only
using SourceLocation = absl::SourceLocation;
// end:google_only
// This type exists to work around an absl type that has not yet been
// released.
struct SourceLocation {
static SourceLocation current() { return {}; }
absl::string_view file_name() { return "<unknown>"; }
int line() { return 0; }
};

absl::Status MessageAllocationError(
SourceLocation loc = SourceLocation::current());
Expand Down
4 changes: 1 addition & 3 deletions hpb/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ load(
"UPB_DEFAULT_CPPOPTS",
)

# begin:google_only
# package(default_applicable_licenses = ["//:license"])
# end:google_only
package(default_applicable_licenses = ["//:license"])

cc_library(
name = "template_help",
Expand Down
4 changes: 1 addition & 3 deletions hpb_generator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ load(
"UPB_DEFAULT_CPPOPTS",
)

# begin:google_only
# package(default_applicable_licenses = ["//:license"])
# end:google_only
package(default_applicable_licenses = ["//:license"])

licenses(["notice"])

Expand Down
Loading

0 comments on commit 8422e97

Please sign in to comment.