From 68d86cbc5906b6821fd2d44080634891fb9f3fab Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Sun, 27 Jan 2019 21:57:28 -0800 Subject: [PATCH] Ported BUILD file fixes for google3 to arrayapi branch. --- BUILD | 167 +++++++++++++++++++++------------------ CMakeLists.txt | 1 + build_defs.bzl | 36 ++++++--- tools/amalgamate.py | 4 +- tools/make_cmakelists.py | 8 +- 5 files changed, 129 insertions(+), 87 deletions(-) diff --git a/BUILD b/BUILD index ea63482ddd..8ef3c79e11 100644 --- a/BUILD +++ b/BUILD @@ -1,15 +1,32 @@ load( ":build_defs.bzl", + "licenses", # copybara:strip_for_google3 "lua_cclibrary", "lua_library", "lua_binary", "lua_test", "generated_file_staleness_test", "make_shell_script", + "map_dep", "upb_amalgamation", "upb_proto_library", ) +licenses(["notice"]) # BSD (Google-authored w/ possible external contributions) + +exports_files([ + "LICENSE", + "build_defs", +]) + +COPTS = [ + # copybara:strip_for_google3_begin + "-std=c89", + "-pedantic", + "-Wno-long-long", + # copybara:strip_end +] + # C/C++ rules ################################################################## cc_library( @@ -46,11 +63,7 @@ cc_library( "upb/sink.h", "upb/upb.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, visibility = ["//visibility:public"], ) @@ -64,11 +77,7 @@ cc_library( "upb/descriptor/descriptor.upbdefs.h", "upb/descriptor/reader.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, deps = [":upb"], ) @@ -83,6 +92,7 @@ cc_library( "upb/pb/textprinter.c", "upb/pb/varint.c", "upb/pb/varint.int.h", + "upb/table.int.h", ], hdrs = [ "upb/pb/decoder.h", @@ -90,11 +100,7 @@ cc_library( "upb/pb/glue.h", "upb/pb/textprinter.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, deps = [ ":upb", ":upb_descriptor", @@ -111,11 +117,7 @@ cc_library( "upb/json/parser.h", "upb/json/printer.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, deps = [ ":upb", ":upb_pb", @@ -130,32 +132,43 @@ cc_library( deps = [":upb"], ) -# Amalgamation ################################################################# +# upb compiler ################################################################# -py_binary( - name = "amalgamate", - srcs = ["tools/amalgamate.py"], +cc_library( + name = "upbc_generator", + srcs = [ + "upbc/generator.cc", + "upbc/message_layout.cc", + "upbc/message_layout.h", + ], + hdrs = ["upbc/generator.h"], + deps = [ + map_dep("@absl//absl/strings"), + map_dep("@com_google_protobuf//:protobuf"), + map_dep("@com_google_protobuf//:protoc_lib"), + ], ) -upb_amalgamation( - name = "gen_amalgamation", - outs = [ - "upb.c", - "upb.h", - ], - amalgamator = ":amalgamate", - libs = [ - ":upb", - ":upb_descriptor", - ":upb_pb", - ":upb_json", +cc_binary( + name = "protoc-gen-upb", + srcs = ["upbc/main.cc"], + deps = [ + ":upbc_generator", + map_dep("@com_google_protobuf//:protoc_lib"), ], ) -cc_library( - name = "amalgamation", - srcs = ["upb.c"], - hdrs = ["upb.h"], +# We strip the tests and remaining rules from google3 until the upb_proto_library() +# and upb_proto_reflection_library() rules are fixed. + +# copybara:strip_for_google3_begin + +lua_binary( + name = "lua_upbc", + luadeps = [ + "lua/upbc_lib", + ], + luamain = "tools/upbc.lua", ) # C/C++ tests ################################################################## @@ -266,11 +279,11 @@ cc_binary( srcs = [ "tests/conformance_upb.c", ], + copts = ["-Ibazel-out/k8-fastbuild/bin"], deps = [ ":conformance_proto_upb", ":upb", ], - copts = ["-Ibazel-out/k8-fastbuild/bin"], ) make_shell_script( @@ -290,6 +303,35 @@ sh_test( ], ) +# Amalgamation ################################################################# + +py_binary( + name = "amalgamate", + srcs = ["tools/amalgamate.py"], +) + +upb_amalgamation( + name = "gen_amalgamation", + outs = [ + "upb.c", + "upb.h", + ], + amalgamator = ":amalgamate", + libs = [ + ":upb", + ":upb_descriptor", + ":upb_pb", + ":upb_json", + ], +) + +cc_library( + name = "amalgamation", + srcs = ["upb.c"], + hdrs = ["upb.h"], + copts = COPTS, +) + # Lua libraries. ############################################################### lua_cclibrary( @@ -375,42 +417,12 @@ lua_test( luamain = "tests/bindings/lua/test_upb.pb.lua", ) -# upb compiler ################################################################# - -lua_binary( - name = "lua_upbc", - luadeps = [ - "lua/upbc_lib", - ], - luamain = "tools/upbc.lua", -) - -cc_library( - name = "upbc_generator", - hdrs = ["upbc/generator.h"], - srcs = ["upbc/generator.cc", "upbc/message_layout.h", "upbc/message_layout.cc"], - deps = [ - "@com_google_protobuf//:protobuf", - "@com_google_protobuf//:protoc_lib", - "@absl//absl/strings", - ], -) - -cc_binary( - name = "protoc-gen-upb", - srcs = ["upbc/main.cc"], - deps = [ - ":upbc_generator", - "@com_google_protobuf//:protoc_lib", - ], -) - # Test the CMake build ######################################################### make_shell_script( name = "gen_run_cmake_build", out = "run_cmake_build.sh", - contents = "mkdir build && cd build && cmake .. && make -j8 && make test" + contents = "mkdir build && cd build && cmake .. && make -j8 && make test", ) sh_test( @@ -464,10 +476,13 @@ py_binary( genrule( name = "gen_cmakelists", + srcs = [ + "BUILD", + "WORKSPACE", + ], outs = ["generated/CMakeLists.txt"], - srcs = ["BUILD", "WORKSPACE"], + cmd = "$(location :make_cmakelists) $@", tools = [":make_cmakelists"], - cmd = "$(location :make_cmakelists) $@" ) genrule( @@ -511,8 +526,8 @@ genrule( ], cmd = "$(location @com_google_protobuf//:protoc) $< --upb_out=$(GENDIR)/generated --plugin=protoc-gen-upb=$(location :protoc-gen-upb)", tools = [ + ":protoc-gen-upb", "@com_google_protobuf//:protoc", - ":protoc-gen-upb" ], ) @@ -564,3 +579,5 @@ generated_file_staleness_test( ], generated_pattern = "generated/%s", ) + +# copybara:strip_end diff --git a/CMakeLists.txt b/CMakeLists.txt index fb887cb0e8..3e1de27aad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ add_library(upb_pb upb/pb/textprinter.c upb/pb/varint.c upb/pb/varint.int.h + upb/table.int.h upb/pb/decoder.h upb/pb/encoder.h upb/pb/glue.h diff --git a/build_defs.bzl b/build_defs.bzl index 7445fce136..a6e5086fe1 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -1,4 +1,3 @@ - _shell_find_runfiles = """ # --- begin runfiles.bash initialization --- # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). @@ -100,7 +99,7 @@ BASE=$(dirname $(rlocation upb/upb_c.so)) export LUA_CPATH="$BASE/?.so" export LUA_PATH="$BASE/?.lua" $(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@" -""" +""", ) rule( @@ -109,10 +108,10 @@ $(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@" data = ["@lua//:lua", "@bazel_tools//tools/bash/runfiles", luamain] + luadeps, ) -def lua_binary(name, luamain, luadeps=[]): +def lua_binary(name, luamain, luadeps = []): _lua_binary_or_test(name, luamain, luadeps, native.sh_binary) -def lua_test(name, luamain, luadeps=[]): +def lua_test(name, luamain, luadeps = []): _lua_binary_or_test(name, luamain, luadeps, native.sh_test) def generated_file_staleness_test(name, outs, generated_pattern): @@ -163,9 +162,9 @@ def generated_file_staleness_test(name, outs, generated_pattern): SrcList = provider( fields = { - 'srcs' : 'list of srcs', - 'hdrs' : 'list of hdrs', - } + "srcs": "list of srcs", + "hdrs": "list of hdrs", + }, ) def _file_list_aspect_impl(target, ctx): @@ -205,9 +204,24 @@ upb_amalgamation = rule( ), "libs": attr.label_list(aspects = [_file_list_aspect]), "outs": attr.output_list(), - } + }, ) +is_bazel = not hasattr(native, "genmpm") + +google3_dep_map = { + "@absl//absl/strings": "//third_party/absl/strings", + "@com_google_protobuf//:protoc": "//third_party/protobuf:protoc", + "@com_google_protobuf//:protobuf": "//third_party/protobuf:protobuf", + "@com_google_protobuf//:protoc_lib": "//third_party/protobuf:libprotoc", +} + +def map_dep(dep): + if is_bazel: + return dep + else: + return google3_dep_map[dep] + # upb_proto_library() rule def _remove_up(string): @@ -223,7 +237,7 @@ def _upb_proto_library_srcs_impl(ctx): outs = [] include_dirs = {} for dep in ctx.attr.deps: - if hasattr(dep, 'proto'): + if hasattr(dep, "proto"): for src in dep.proto.transitive_sources: sources.append(src) include_dirs[_remove_suffix(src.path, _remove_up(src.short_path) + "." + src.extension)] = True @@ -273,3 +287,7 @@ def upb_proto_library(name, deps, upbc): deps = [":upb"], copts = ["-Ibazel-out/k8-fastbuild/bin"], ) + +def licenses(*args): + # No-op (for Google-internal usage). + pass diff --git a/tools/amalgamate.py b/tools/amalgamate.py index 4739a94e5d..038c83fc8a 100755 --- a/tools/amalgamate.py +++ b/tools/amalgamate.py @@ -16,11 +16,11 @@ class Amalgamator: self.output_h = open(output_path + "upb.h", "w") self.output_c = open(output_path + "upb.c", "w") - self.output_c.write("// Amalgamated source file\n") + self.output_c.write("/* Amalgamated source file */\n") self.output_c.write('#include "upb.h"\n') self.output_c.write(open("upb/port_def.inc").read()) - self.output_h.write("// Amalgamated source file\n") + self.output_h.write("/* Amalgamated source file */\n") self.output_h.write(open("upb/port_def.inc").read()) def finish(self): diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index b8f46b9029..d863e7ea33 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -123,9 +123,15 @@ class BuildFileFunctions(object): def genrule(self, **kwargs): pass - def glob(*args): + def glob(self, *args): return [] + def map_dep(self, dep): + return dep + + def licenses(self, *args): + pass + class WorkspaceFileFunctions(object): def __init__(self, converter):