Added script to generate CMake build. Bazel tests it.

pull/13171/head
Josh Haberman 7 years ago
parent 966d9d89e6
commit 23fa64f10c
  1. 180
      BUILD
  2. 367
      CMakeLists.txt
  3. 2
      build_defs.bzl
  4. 234
      tools/make_cmakelists.py
  5. 2
      tools/staleness_test.py
  6. 0
      tools/staleness_test_lib.py
  7. 5
      tools/upbc

180
BUILD

@ -45,7 +45,11 @@ cc_library(
"upb/sink.h",
"upb/upb.h",
],
copts = ["-std=c89", "-pedantic", "-Wno-long-long"],
copts = [
"-std=c89",
"-pedantic",
"-Wno-long-long",
],
)
cc_library(
@ -58,8 +62,12 @@ cc_library(
"upb/descriptor/descriptor.upbdefs.h",
"upb/descriptor/reader.h",
],
copts = [
"-std=c89",
"-pedantic",
"-Wno-long-long",
],
deps = [":upb"],
copts = ["-std=c89", "-pedantic", "-Wno-long-long"],
)
cc_library(
@ -80,11 +88,15 @@ cc_library(
"upb/pb/glue.h",
"upb/pb/textprinter.h",
],
copts = [
"-std=c89",
"-pedantic",
"-Wno-long-long",
],
deps = [
":upb",
":upb_descriptor",
],
copts = ["-std=c89", "-pedantic", "-Wno-long-long"],
)
cc_library(
@ -97,8 +109,12 @@ cc_library(
"upb/json/parser.h",
"upb/json/printer.h",
],
copts = [
"-std=c89",
"-pedantic",
"-Wno-long-long",
],
deps = [":upb"],
copts = ["-std=c89", "-pedantic", "-Wno-long-long"],
)
cc_library(
@ -118,6 +134,10 @@ py_binary(
upb_amalgamation(
name = "gen_amalgamation",
outs = [
"upb.c",
"upb.h",
],
amalgamator = ":amalgamate",
libs = [
":upb",
@ -125,92 +145,115 @@ upb_amalgamation(
":upb_pb",
":upb_json",
],
outs = [
"upb.h",
"upb.c",
],
)
cc_library(
name = "amalgamation",
hdrs = ["upb.h"],
srcs = ["upb.c"],
hdrs = ["upb.h"],
)
# C/C++ tests ##################################################################
cc_library(
testonly = 1,
name = "upb_test",
hdrs = [
"tests/upb_test.h",
"tests/test_util.h",
],
testonly = 1,
srcs = [
"tests/testmain.cc",
],
hdrs = [
"tests/test_util.h",
"tests/upb_test.h",
],
)
cc_test(
name = "test_varint",
srcs = ["tests/pb/test_varint.c"],
deps = [":upb_pb", ":upb_test"],
deps = [
":upb_pb",
":upb_test",
],
)
cc_test(
name = "test_def",
srcs = ["tests/test_def.c"],
deps = [":upb_pb", ":upb_test"],
deps = [
":upb_pb",
":upb_test",
],
)
cc_test(
name = "test_handlers",
srcs = ["tests/test_handlers.c"],
deps = [":upb_pb", ":upb_test"],
deps = [
":upb_pb",
":upb_test",
],
)
cc_test(
name = "test_decoder",
srcs = ["tests/pb/test_decoder.cc"],
deps = [":upb_pb", ":upb_test"],
deps = [
":upb_pb",
":upb_test",
],
)
cc_test(
name = "test_encoder",
srcs = ["tests/pb/test_encoder.cc"],
deps = [":upb_pb", ":upb_test", ":upb_cc_bindings"],
data = ["upb/descriptor/descriptor.pb"],
deps = [
":upb_cc_bindings",
":upb_pb",
":upb_test",
],
)
cc_test(
name = "test_cpp",
srcs = ["tests/test_cpp.cc"],
deps = [":upb_descriptor", ":upb", ":upb_pb", ":upb_test"],
deps = [
":upb",
":upb_descriptor",
":upb_pb",
":upb_test",
],
)
cc_test(
name = "test_table",
srcs = ["tests/test_table.cc"],
deps = [":upb", ":upb_test"],
deps = [
":upb",
":upb_test",
],
)
cc_test(
name = "test_json",
srcs = [
"tests/json/test_json.cc",
"tests/json/test.upbdefs.h",
"tests/json/test.upbdefs.c",
"tests/json/test.upbdefs.h",
"tests/json/test_json.cc",
],
deps = [
":upb_json",
":upb_test",
],
deps = [":upb_json", ":upb_test"],
)
upb_proto_library(
name = "conformance_proto_upb",
upbc = ":upbc",
deps = [
"@com_google_protobuf//:conformance_proto",
"@com_google_protobuf//:test_messages_proto3_proto",
],
upbc = ":upbc",
)
cc_binary(
@ -219,8 +262,8 @@ cc_binary(
"tests/conformance_upb.c",
],
deps = [
":upb",
":conformance_proto_upb",
":upb",
],
)
@ -234,11 +277,11 @@ sh_test(
name = "test_conformance_upb",
srcs = ["test_conformance_upb.sh"],
data = [
"tests/conformance_upb_failures.txt",
":conformance_upb",
"@bazel_tools//tools/bash/runfiles",
"@com_google_protobuf//:conformance_test_runner",
"tests/conformance_upb_failures.txt",
"@bazel_tools//tools/bash/runfiles"
]
],
)
# Lua libraries. ###############################################################
@ -262,8 +305,8 @@ lua_cclibrary(
lua_library(
name = "lua/upb",
srcs = ["upb/bindings/lua/upb.lua"],
strip_prefix = "upb/bindings/lua",
luadeps = ["lua/upb_c"],
strip_prefix = "upb/bindings/lua",
)
lua_cclibrary(
@ -276,11 +319,11 @@ lua_cclibrary(
lua_library(
name = "lua/upb/table",
srcs = ["upb/bindings/lua/upb/table.lua"],
strip_prefix = "upb/bindings/lua",
luadeps = [
"lua/upb",
"lua/upb/table_c",
],
strip_prefix = "upb/bindings/lua",
)
lua_cclibrary(
@ -293,11 +336,11 @@ lua_cclibrary(
lua_library(
name = "lua/upb/pb",
srcs = ["upb/bindings/lua/upb/pb.lua"],
strip_prefix = "upb/bindings/lua",
luadeps = [
"lua/upb",
"lua/upb/pb_c",
],
strip_prefix = "upb/bindings/lua",
)
lua_library(
@ -306,25 +349,25 @@ lua_library(
"tools/dump_cinit.lua",
"tools/make_c_api.lua",
],
strip_prefix = "tools",
luadeps = [
"lua/upb",
"lua/upb/table",
],
strip_prefix = "tools",
)
# Lua tests. ###################################################################
lua_test(
name = "lua/test_upb",
luamain = "tests/bindings/lua/test_upb.lua",
luadeps = ["lua/upb"],
luamain = "tests/bindings/lua/test_upb.lua",
)
lua_test(
name = "lua/test_upb_pb",
luamain = "tests/bindings/lua/test_upb.pb.lua",
luadeps = ["lua/upb/pb"],
luamain = "tests/bindings/lua/test_upb.pb.lua",
)
# upb compiler #################################################################
@ -337,14 +380,35 @@ lua_binary(
luamain = "tools/upbc.lua",
)
# 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"
)
sh_test(
name = "cmake_build",
srcs = ["run_cmake_build.sh"],
data = glob([
"CMakeLists.txt",
"google/**/*",
"upb/**/*",
"tests/**/*",
]) + [
"@bazel_tools//tools/bash/runfiles",
],
)
# Generated files ##############################################################
exports_files(["staleness_test.py"])
exports_files(["tools/staleness_test.py"])
py_library(
name = "staleness_test_lib",
testonly = 1,
srcs = ["staleness_test_lib.py"],
srcs = ["tools/staleness_test_lib.py"],
)
genrule(
@ -363,51 +427,64 @@ genrule(
proto_library(
name = "upb_descriptor_proto",
srcs = [
"upb/descriptor/descriptor.proto"
"upb/descriptor/descriptor.proto",
],
)
py_binary(
name = "make_cmakelists",
srcs = ["tools/make_cmakelists.py"],
)
genrule(
name = "gen_cmakelists",
outs = ["generated/CMakeLists.txt"],
srcs = ["BUILD", "WORKSPACE"],
tools = [":make_cmakelists"],
cmd = "$(location :make_cmakelists) $@"
)
genrule(
name = "copy_upb_descriptor_pb",
outs = ["generated/upb/descriptor/descriptor.pb"],
srcs = [":upb_descriptor_proto"],
outs = ["generated/upb/descriptor/descriptor.pb"],
cmd = "cp $< $@",
)
genrule(
name = "generate_old_upbdefs",
srcs = ["generated/upb/descriptor/descriptor.pb"],
tools = [":upbc"],
outs = [
"generated/upb/descriptor/descriptor.upbdefs.h",
"generated/upb/descriptor/descriptor.upbdefs.c",
],
cmd = "UPBC=$$PWD/$(location :upbc); INFILE=$$PWD/$<; cd $(GENDIR)/generated && $$UPBC --generate-upbdefs $$INFILE",
tools = [":upbc"],
)
proto_library(
name = "google_descriptor_proto",
srcs = [
"google/protobuf/descriptor.proto"
"google/protobuf/descriptor.proto",
],
)
genrule(
name = "copy_google_descriptor_pb",
outs = ["generated/google/protobuf/descriptor.pb"],
srcs = [":google_descriptor_proto"],
outs = ["generated/google/protobuf/descriptor.pb"],
cmd = "cp $< $@",
)
genrule(
name = "generate_descriptor_c",
srcs = ["generated/google/protobuf/descriptor.pb"],
tools = [":upbc"],
outs = [
"generated/google/protobuf/descriptor.upb.h",
"generated/google/protobuf/descriptor.upb.c",
],
cmd = "UPBC=$$PWD/$(location :upbc); INFILE=$$PWD/$<; cd $(GENDIR)/generated && $$UPBC $$INFILE",
tools = [":upbc"],
)
proto_library(
@ -425,35 +502,36 @@ genrule(
genrule(
name = "generated_json_test_proto_upbdefs",
srcs = ["generated/tests/json/test.proto.pb"],
tools = [":upbc"],
outs = [
"generated/tests/json/test.upbdefs.h",
"generated/tests/json/test.upbdefs.c",
],
cmd = "UPBC=$$PWD/$(location :upbc); INFILE=$$PWD/$<; cd $(GENDIR)/generated && $$UPBC --generate-upbdefs $$INFILE",
tools = [":upbc"],
)
genrule(
name = "generate_json_ragel",
srcs = ["upb/json/parser.rl"],
outs = ["generated/upb/json/parser.c"],
tools = ["@ragel//:ragel"],
cmd = "$(location @ragel//:ragel) -C -o upb/json/parser.c $< && mv upb/json/parser.c $@",
tools = ["@ragel"],
)
generated_file_staleness_test(
name = "test_generated_files",
outs = [
"google/protobuf/descriptor.upb.h",
"CMakeLists.txt",
"google/protobuf/descriptor.upb.c",
"upb/pb/compile_decoder_x64.h",
"upb/descriptor/descriptor.upbdefs.c",
"google/protobuf/descriptor.upb.h",
"tests/json/test.proto.pb",
"tests/json/test.upbdefs.c",
"tests/json/test.upbdefs.h",
"upb/descriptor/descriptor.pb",
"upb/descriptor/descriptor.upbdefs.c",
"upb/descriptor/descriptor.upbdefs.h",
"upb/json/parser.c",
"tests/json/test.upbdefs.c",
"tests/json/test.upbdefs.h",
"tests/json/test.proto.pb",
"upb/pb/compile_decoder_x64.h",
],
generated_pattern = "generated/%s",
)

@ -1,3 +1,4 @@
# This file was generated from BUILD using tools/make_cmakelists.py.
cmake_minimum_required(VERSION 3.1)
@ -9,16 +10,14 @@ endif()
cmake_minimum_required (VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project (upb)
project(upb)
# Prevent CMake from setting -rdynamic on Linux (!!).
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# Options we define for users.
option(UPB_ENABLE_ASAN "Enable address sanitizer." OFF)
option(UPB_ENABLE_UBSAN "Enable undefined behavior sanitizer." OFF)
# Set default build type.
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
@ -51,8 +50,6 @@ endif()
include_directories(.)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_CXX_FLAGS "-std=c++11 -W -Wall -Wno-sign-compare")
set(CMAKE_C_FLAGS "-std=c89 -W -Wall -Wno-sign-compare")
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
@ -60,250 +57,132 @@ elseif(UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
endif()
FIND_PACKAGE(Lua)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/Makefile.am")
set(PROTOBUF_FOUND TRUE)
endif()
find_program(RAGEL NAMES ragel)
if(LUA_FOUND)
include_directories(${LUA_INCLUDE_DIR})
add_library(upb_c SHARED
upb/bindings/lua/upb.c
upb/bindings/lua/def.c
upb/bindings/lua/msg.c
)
target_link_libraries(upb_c LINK_PRIVATE
upbpb_pic
upbdef_pic
upbhandlers_pic upb_pic )
add_library(table_c SHARED
upb/bindings/lua/upb/table.c
)
target_link_libraries(table_c LINK_PRIVATE upb_c upb_pic)
add_library(pb_c SHARED
upb/bindings/lua/upb/pb.c
)
target_link_libraries(pb_c LINK_PRIVATE upb_c upbpb_pic)
set_target_properties(upb_c
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "lua"
PREFIX ""
SUFFIX ".so")
set_target_properties(table_c pb_c
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "lua/upb"
PREFIX ""
SUFFIX ".so")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
DEPENDS ${CMAKE_SOURCE_DIR}/tools/upbc
${CMAKE_SOURCE_DIR}/tools/upbc.lua
${CMAKE_SOURCE_DIR}/tools/dump_cinit.lua
${CMAKE_SOURCE_DIR}/tools/make_c_api.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua
upb_c
table_c
pb_c
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/tools/upbc
${CMAKE_SOURCE_DIR}/tools/upbc.lua
${CMAKE_SOURCE_DIR}/tools/dump_cinit.lua
${CMAKE_SOURCE_DIR}/tools/make_c_api.lua
${CMAKE_CURRENT_BINARY_DIR}/tools)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb.lua
DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua
${CMAKE_CURRENT_BINARY_DIR}/lua)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb/table.lua
${CMAKE_CURRENT_BINARY_DIR}/lua/upb/pb.lua
DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua
${CMAKE_CURRENT_BINARY_DIR}/lua/upb)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h
DEPENDS upb/pb/compile_decoder_x64.dasc
COMMAND
cd ${CMAKE_CURRENT_SOURCE_DIR} &&
lua third_party/dynasm/dynasm.lua
-c upb/pb/compile_decoder_x64.dasc
> ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h
)
add_custom_target(
upbc ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_c_api.lua
${CMAKE_CURRENT_SOURCE_DIR}/tools/upbc.lua
${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
${CMAKE_CURRENT_BINARY_DIR}/lua/upb.lua
${CMAKE_CURRENT_BINARY_DIR}/lua/upb/pb.lua
)
add_custom_target(
genfiles2 ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h
)
add_test(
NAME testlua
COMMAND lua ${CMAKE_SOURCE_DIR}/tests/bindings/lua/test_upb.lua
${CMAKE_SOURCE_DIR}/tests/bindings/lua/test_upb.pb.lua
)
set_property(TEST testlua PROPERTY ENVIRONMENT
LUA_PATH=${CMAKE_SOURCE_DIR}/third_party/lunit/?.lua$<SEMICOLON>${CMAKE_SOURCE_DIR}/upb/bindings/lua/?.lua
LUA_CPATH=${CMAKE_BINARY_DIR}/upb/bindings/lua/?.so
)
set_tests_properties(testlua
PROPERTIES
DEPENDS "upb_c;pb_c"
)
enable_testing()
endif()
if(LUA_FOUND AND PROTOBUF_FOUND)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE)
set(protobuf_BUILD_CONFORMANCE ON CACHE BOOL "Build conformance tests" FORCE)
add_subdirectory(third_party/protobuf/cmake)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c
${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance/conformance.proto
COMMAND protoc --include_imports
${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance/conformance.proto
${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/src/google/protobuf/test_messages_proto3.proto
-I${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance
-I${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/src
-o${CMAKE_CURRENT_BINARY_DIR}/conformance.pb &&
tools/upbc ${CMAKE_CURRENT_BINARY_DIR}/conformance.pb
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.c
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
${CMAKE_CURRENT_SOURCE_DIR}/google/protobuf/descriptor.proto
COMMAND protoc
${CMAKE_CURRENT_SOURCE_DIR}/google/protobuf/descriptor.proto
-I${CMAKE_CURRENT_SOURCE_DIR}
-o${CMAKE_CURRENT_BINARY_DIR}/descriptor.pb &&
tools/upbc ${CMAKE_CURRENT_BINARY_DIR}/descriptor.pb
)
add_custom_target(
genfiles ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h
)
add_executable(conformance_upb
tests/conformance_upb.c
${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c
)
target_link_libraries(conformance_upb LINK_PRIVATE
upb
)
add_custom_target(
conformance
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance_upb
${CMAKE_CURRENT_BINARY_DIR}/third_party/protobuf/cmake/conformance_test_runner
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/third_party/protobuf/cmake/conformance_test_runner ${CMAKE_CURRENT_BINARY_DIR}/conformance_upb
)
endif()
if (RAGEL)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/upb/json/parser.c
DEPENDS upb/json/parser.rl
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && RAGEL -C -o ${CMAKE_CURRENT_BINARY_DIR}/upb/json/parser.c upb/json/parser.rl
)
endif()
configure_file(tools/copy_genfiles.sh.in tools/copy_genfiles.sh)
set(UPB_SRCS
upb/decode.c
upb/encode.c
upb/msg.c
upb/table.c
upb/upb.c
)
set (UPBDEF_SRCS
upb/descriptor/descriptor.upbdefs.c
upb/descriptor/reader.c
upb/def.c
upb/msgfactory.c
upb/refcounted.c
)
set(UPBHANDLERS_SRCS
upb/sink.c
upb/handlers.c
)
set(UPBPB_SRCS
enable_testing()
add_library(upb
google/protobuf/descriptor.upb.c
upb/decode.c
upb/def.c
upb/encode.c
upb/handlers.c
upb/handlers-inl.h
upb/msg.c
upb/msgfactory.c
upb/port_def.inc
upb/port_undef.inc
upb/refcounted.c
upb/sink.c
upb/structdefs.int.h
upb/structs.int.h
upb/table.c
upb/table.int.h
upb/upb.c
google/protobuf/descriptor.upb.h
upb/decode.h
upb/def.h
upb/encode.h
upb/handlers.h
upb/msg.h
upb/msgfactory.h
upb/refcounted.h
upb/sink.h
upb/upb.h)
add_library(upb_descriptor
upb/descriptor/descriptor.upbdefs.c
upb/descriptor/reader.c
upb/descriptor/descriptor.upbdefs.h
upb/descriptor/reader.h)
target_link_libraries(upb_descriptor
upb)
add_library(upb_pb
upb/pb/compile_decoder.c
upb/pb/decoder.c
upb/pb/decoder.int.h
upb/pb/encoder.c
upb/pb/glue.c
upb/pb/textprinter.c
upb/pb/varint.c
)
set(UPBJSON_SRCS
upb/pb/varint.int.h
upb/pb/decoder.h
upb/pb/encoder.h
upb/pb/glue.h
upb/pb/textprinter.h)
target_link_libraries(upb_pb
upb
upb_descriptor)
add_library(upb_json
upb/json/parser.c
upb/json/printer.c
)
add_library(upb ${UPB_SRCS})
add_library(upbdef ${UPBDEF_SRCS})
add_library(upbhandlers ${UPBHANDLERS_SRCS})
add_library(upbpb ${UPBPB_SRCS})
add_library(upbjson ${UPBJSON_SRCS})
add_library(upb_pic ${UPB_SRCS})
add_library(upbdef_pic ${UPBDEF_SRCS})
add_library(upbhandlers_pic ${UPBHANDLERS_SRCS})
add_library(upbpb_pic ${UPBPB_SRCS})
add_library(upbjson_pic ${UPBJSON_SRCS})
upb/json/parser.h
upb/json/printer.h)
target_link_libraries(upb_json
upb)
add_library(upb_cc_bindings
upb/bindings/stdc++/string.h)
target_link_libraries(upb_cc_bindings
upb)
set_target_properties(upb_cc_bindings PROPERTIES LINKER_LANGUAGE CXX)
add_library(upb_test
tests/testmain.cc
tests/test_util.h
tests/upb_test.h)
add_executable(test_varint
tests/pb/test_varint.c)
add_test(NAME test_varint COMMAND test_varint)
target_link_libraries(test_varint
upb_pb
upb_test)
add_executable(test_def
tests/test_def.c)
add_test(NAME test_def COMMAND test_def)
target_link_libraries(test_def
upb_pb
upb_test)
add_executable(test_handlers
tests/test_handlers.c)
add_test(NAME test_handlers COMMAND test_handlers)
target_link_libraries(test_handlers
upb_pb
upb_test)
add_executable(test_decoder
tests/pb/test_decoder.cc)
add_test(NAME test_decoder COMMAND test_decoder)
target_link_libraries(test_decoder
upb_pb
upb_test)
add_executable(test_encoder
tests/pb/test_encoder.cc)
add_test(NAME test_encoder COMMAND test_encoder)
add_custom_command(
TARGET test_encoder POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/upb/descriptor/descriptor.pb
${CMAKE_CURRENT_BINARY_DIR}/upb/descriptor/descriptor.pb)
target_link_libraries(test_encoder
upb_cc_bindings
upb_pb
upb_test)
add_executable(test_cpp
tests/test_cpp.cc)
add_test(NAME test_cpp COMMAND test_cpp)
target_link_libraries(test_cpp
upb
upb_descriptor
upb_pb
upb_test)
add_executable(test_table
tests/test_table.cc)
add_test(NAME test_table COMMAND test_table)
target_link_libraries(test_table
upb
upb_test)
add_executable(test_json
tests/json/test.upbdefs.c
tests/json/test.upbdefs.h
tests/json/test_json.cc)
add_test(NAME test_json COMMAND test_json)
target_link_libraries(test_json
upb_json
upb_test)
set_property(TARGET upb_pic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET upbdef_pic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET upbhandlers_pic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET upbpb_pic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET upbjson_pic PROPERTY POSITION_INDEPENDENT_CODE ON)

@ -131,7 +131,7 @@ def generated_file_staleness_test(name, outs, generated_pattern):
"""
script_name = name + ".py"
script_src = "//:staleness_test.py"
script_src = "//:tools/staleness_test.py"
# Filter out non-existing rules so Blaze doesn't error out before we even
# run the test.

@ -0,0 +1,234 @@
#!/usr/bin/env python
"""TODO(haberman): DO NOT SUBMIT without one-line documentation for make_cmakelists.
TODO(haberman): DO NOT SUBMIT without a detailed description of make_cmakelists.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import textwrap
def StripColons(deps):
return map(lambda x: x[1:], deps)
def IsSourceFile(name):
return name.endswith(".c") or name.endswith(".cc")
class BuildFileFunctions(object):
def __init__(self, converter):
self.converter = converter
def _add_deps(self, kwargs):
if "deps" not in kwargs:
return
self.converter.toplevel += "target_link_libraries(%s\n %s)\n" % (
kwargs["name"],
"\n ".join(StripColons(kwargs["deps"]))
)
def load(self, *args):
pass
def cc_library(self, **kwargs):
if kwargs["name"] == "amalgamation":
return
files = kwargs.get("srcs", []) + kwargs.get("hdrs", [])
self.converter.toplevel += "add_library(%s\n %s)\n" % (
kwargs["name"],
"\n ".join(files)
)
self._add_deps(kwargs)
# CMake wants to know if each library is C or C++.
# If there are only .h files, it can't infer. Assume C++.
if not filter(IsSourceFile, files):
line = "set_target_properties(%s PROPERTIES LINKER_LANGUAGE CXX)\n"
self.converter.toplevel += line % (kwargs["name"])
def cc_binary(self, **kwargs):
pass
def cc_test(self, **kwargs):
self.converter.toplevel += "add_executable(%s\n %s)\n" % (
kwargs["name"],
"\n ".join(kwargs["srcs"])
)
self.converter.toplevel += "add_test(NAME %s COMMAND %s)\n" % (
kwargs["name"],
kwargs["name"],
)
if "data" in kwargs:
for data_dep in kwargs["data"]:
self.converter.toplevel += textwrap.dedent("""\
add_custom_command(
TARGET %s POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/%s
${CMAKE_CURRENT_BINARY_DIR}/%s)\n""" % (
kwargs["name"], data_dep, data_dep
))
self._add_deps(kwargs)
def py_library(self, **kwargs):
pass
def py_binary(self, **kwargs):
pass
def lua_cclibrary(self, **kwargs):
pass
def lua_library(self, **kwargs):
pass
def lua_binary(self, **kwargs):
pass
def lua_test(self, **kwargs):
pass
def sh_test(self, **kwargs):
pass
def make_shell_script(self, **kwargs):
pass
def exports_files(self, files, **kwargs):
pass
def proto_library(self, **kwargs):
pass
def generated_file_staleness_test(self, **kwargs):
pass
def upb_amalgamation(self, **kwargs):
pass
def upb_proto_library(self, **kwargs):
pass
def genrule(self, **kwargs):
pass
def glob(*args):
return []
class WorkspaceFileFunctions(object):
def __init__(self, converter):
self.converter = converter
def load(self, *args):
pass
def workspace(self, **kwargs):
self.converter.prelude += "project(%s)\n" % (kwargs["name"])
def http_archive(self, **kwargs):
pass
def git_repository(self, **kwargs):
pass
class Converter(object):
def __init__(self):
self.prelude = ""
self.toplevel = ""
self.if_lua = ""
def convert(self):
return self.template % {
"prelude": converter.prelude,
"toplevel": converter.toplevel,
}
template = textwrap.dedent("""\
# This file was generated from BUILD using tools/make_cmakelists.py.
cmake_minimum_required(VERSION 3.1)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.12)
endif()
cmake_minimum_required (VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
%(prelude)s
# Prevent CMake from setting -rdynamic on Linux (!!).
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# Set default build type.
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
# When using Ninja, compiler output won't be colorized without this.
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always SUPPORTS_COLOR_ALWAYS)
if(SUPPORTS_COLOR_ALWAYS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
# Implement ASAN/UBSAN options
if(UPB_ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()
if(UPB_ENABLE_UBSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()
include_directories(.)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
elseif(UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
endif()
enable_testing()
%(toplevel)s
""")
data = {}
converter = Converter()
def GetDict(obj):
ret = {}
for k in dir(obj):
if not k.startswith("_"):
ret[k] = getattr(obj, k);
return ret
globs = GetDict(converter)
execfile("WORKSPACE", GetDict(WorkspaceFileFunctions(converter)))
execfile("BUILD", GetDict(BuildFileFunctions(converter)))
with open(sys.argv[1], "w") as f:
f.write(converter.convert())

@ -6,7 +6,7 @@ with the actual list of files before we actually run the script.
from __future__ import absolute_import
import staleness_test_lib
from tools import staleness_test_lib
import unittest
import sys

@ -1,5 +0,0 @@
#!/bin/sh
BASE=`dirname "$0"`
export LUA_CPATH="$BASE/../lua/?.so"
export LUA_PATH="$BASE/?.lua;$BASE/../lua/?.lua"
lua $BASE/upbc.lua "$@"
Loading…
Cancel
Save