From 1ac451fff73fc3743f3bbd581cd1508767e5effe Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:03:08 +0100 Subject: [PATCH 1/9] Convert jarcat -> arcat --- ChangeLog | 4 ++++ VERSION | 2 +- build_defs/cc.build_defs | 12 ++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0eecb10..f80b963 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Version 0.4.0 +------------- + * Change to using build.arcat instead of the deprecated jarcat config option. + Version 0.3.2 ------------- * Fix dsymutil to have no default value (as plz was with its builtin rules) diff --git a/VERSION b/VERSION index d15723f..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.2 +0.4.0 diff --git a/build_defs/cc.build_defs b/build_defs/cc.build_defs index 9ab8988..94fc44c 100644 --- a/build_defs/cc.build_defs +++ b/build_defs/cc.build_defs @@ -164,13 +164,13 @@ def cc_library(name:str, srcs:list=[], hdrs:list=[], private_hdrs:list=[], deps: tag = 'a', srcs = {'srcs': a_rules}, outs = [out], - cmd = '"$TOOLS_JARCAT" ar --combine && "$TOOLS_AR" s "$OUT"', + cmd = '"$TOOLS_ARCAT" ar --combine && "$TOOLS_AR" s "$OUT"', building_description = 'Archiving...', test_only = test_only, labels = labels, output_is_complete = True, tools = { - 'jarcat': [CONFIG.JARCAT_TOOL], + 'arcat': [CONFIG.ARCAT_TOOL], 'ar': [CONFIG.CC.AR_TOOL], }, ) @@ -355,7 +355,7 @@ def cc_static_library(name:str, srcs:list=[], hdrs:list=[], compiler_flags:list& name = name, deps = deps, outs = [out], - cmd = '"$TOOLS_JARCAT" ar --find && "$TOOLS_AR" s "$OUT"', + cmd = '"$TOOLS_ARCAT" ar --find && "$TOOLS_AR" s "$OUT"', needs_transitive_deps = True, output_is_complete = True, visibility = visibility, @@ -364,7 +364,7 @@ def cc_static_library(name:str, srcs:list=[], hdrs:list=[], compiler_flags:list& provides = provides, requires = ['cc'], tools = { - 'jarcat': [CONFIG.JARCAT_TOOL], + 'arcat': [CONFIG.ARCAT_TOOL], 'ar': [CONFIG.CC.AR_TOOL], }, labels = labels, @@ -723,7 +723,7 @@ def _library_cmds(c, compiler_flags, pkg_config_libs, pkg_config_cflags, extra_f opt_flags = _build_flags(compiler_flags, pkg_config_libs, pkg_config_cflags, c=c) cmd_template = '$TOOLS_CC -c -I . ${SRCS_SRCS} %s %s' if archive: - cmd_template += ' && "$TOOLS_JARCAT" ar -r && "$TOOLS_AR" s "$OUT"' + cmd_template += ' && "$TOOLS_ARCAT" ar -r && "$TOOLS_AR" s "$OUT"' cmds = { 'dbg': cmd_template % (dbg_flags, extra_flags), 'opt': cmd_template % (opt_flags, extra_flags), @@ -732,7 +732,7 @@ def _library_cmds(c, compiler_flags, pkg_config_libs, pkg_config_cflags, extra_f cmds['cover'] = cmd_template % (dbg_flags + _COVERAGE_FLAGS, extra_flags) return cmds, { 'cc': [CONFIG.CC.CC_TOOL if c else CONFIG.CC.CPP_TOOL], - 'jarcat': [CONFIG.JARCAT_TOOL if archive else None], + 'arcat': [CONFIG.ARCAT_TOOL if archive else None], 'ar': [CONFIG.CC.AR_TOOL if archive else None], } From 0fcb08b1b2f9728745f1f4962547784aff77eebb Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:05:10 +0100 Subject: [PATCH 2/9] Update plz version --- .plzconfig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.plzconfig b/.plzconfig index 3793798..68f7a2f 100644 --- a/.plzconfig +++ b/.plzconfig @@ -1,5 +1,5 @@ [please] -version = >=16.12.1 +version = >=17.0.0 [parse] preloadbuilddefs = build_defs/cc.build_defs @@ -12,7 +12,7 @@ ConfigKey = Coverage DefaultValue = true Type = bool Inherit = true -Help = Whether to build with coverage +Help = Whether to build with coverage [PluginConfig "cc_tool"] ConfigKey = CCTool @@ -42,7 +42,7 @@ Hel- = The path or build label for the archiver ConfigKey = DefaultOptCFlags DefaultValue = --std=c99 -O3 -pipe -DNDEBUG -Wall -Werror Inherit = true -Help = The default c compiler flags when compiling for release +Help = The default c compiler flags when compiling for release [PluginConfig "default_dbg_cflags"] ConfigKey = DefaultDbgCFlags @@ -54,7 +54,7 @@ Help = The default c compiler flags when compiling for debug ConfigKey = DefaultOptCppFlags DefaultValue = --std=c++11 -O3 -pipe -DNDEBUG -Wall -Werror Inherit = true -Help = The default c++ compiler flags when compiling for release +Help = The default c++ compiler flags when compiling for release [PluginConfig "default_dbg_cppflags"] ConfigKey = DefaultDbgCppFlags @@ -66,19 +66,19 @@ Help = The default c++ compiler flags when compiling for debug ConfigKey = DefaultLdFlags DefaultValue = -lpthread -ldl Inherit = true -Help = The default set of flags to apply when linking +Help = The default set of flags to apply when linking [PluginConfig "pkg_config_path"] ConfigKey = PkgConfigPath DefaultValue = Inherit = true -Help = A path to the systems package configs +Help = A path to the systems package configs [PluginConfig "test_main"] ConfigKey = TestMain Inherit = true DefaultValue = //unittest-pp:main -Help = A build label with c/c++ source code to use run tests. +Help = A build label with c/c++ source code to use run tests. [PluginConfig "dsym_tool"] ConfigKey = DsymTool @@ -90,7 +90,7 @@ Help = Set this to dsymutil or equivalent on MacOS to use this tool to generate ConfigKey = AsmTool DefaultValue = nasm Inherit = true -Help = The tool to use for assembling assembly code +Help = The tool to use for assembling assembly code [PluginConfig "default_namespace"] ConfigKey = DefaultNamespace From ef1a13563771a5b0da115e9771523f9a6361574e Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:08:09 +0100 Subject: [PATCH 3/9] Fix config values --- .plzconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.plzconfig b/.plzconfig index 68f7a2f..94d96d7 100644 --- a/.plzconfig +++ b/.plzconfig @@ -30,13 +30,13 @@ Help = The path or build label for the C++ compiler ConfigKey = LDTool DefaultValue = ld Inherit = true -Hel- = The path or build label for the linker +Help = The path or build label for the linker [PluginConfig "ar_tool"] ConfigKey = ARTool DefaultValue = ar Inherit = true -Hel- = The path or build label for the archiver +Help = The path or build label for the archiver [PluginConfig "default_opt_cflags"] ConfigKey = DefaultOptCFlags From e09924a8efa7ea99cf59950516a9f65733f75bb3 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:10:30 +0100 Subject: [PATCH 4/9] add a bunch of subincludes --- compdb/BUILD | 10 ++++++---- test/BUILD | 2 ++ test/binary/BUILD | 2 ++ test/c/BUILD | 2 ++ test/deps/BUILD | 2 ++ test/embed/BUILD | 4 ++-- test/gtest/BUILD | 2 ++ test/labels/BUILD | 2 ++ test/modules/BUILD | 2 ++ test/so/BUILD | 2 ++ 10 files changed, 24 insertions(+), 6 deletions(-) diff --git a/compdb/BUILD b/compdb/BUILD index 06017a8..a4d0986 100644 --- a/compdb/BUILD +++ b/compdb/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + cc_binary( name = "compdb", srcs = ["compdb.cc"], @@ -13,17 +15,17 @@ cc_binary( github_repo( name = "subprocess", + build_file = "subprocess.build", + hashes = ["4dd85ccdbf5c78dee8321dc3587c2c4970793abc394c4b9288debc8825b01571"], repo = "arun11299/cpp-subprocess", revision = "v2.0", - hashes = ["4dd85ccdbf5c78dee8321dc3587c2c4970793abc394c4b9288debc8825b01571"], strip_prefix = "cpp-subprocess-2.0", - build_file = "subprocess.build", ) github_repo( name = "json", + build_file = "json.build", + hashes = ["83258a1aa68921b1d82ca3fcfeef04f27471d33cc0e51d516109d161916223f2"], repo = "nlohmann/json", revision = "v3.10.4", - hashes = ["83258a1aa68921b1d82ca3fcfeef04f27471d33cc0e51d516109d161916223f2"], - build_file = "json.build", ) diff --git a/test/BUILD b/test/BUILD index cda4b14..5a311af 100644 --- a/test/BUILD +++ b/test/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + # Test the way cc rules depend on one another; ideally we should be able to # pick up all transitive dependencies correctly but compile the .o files independently. diff --git a/test/binary/BUILD b/test/binary/BUILD index a6228a4..2c9dfd7 100644 --- a/test/binary/BUILD +++ b/test/binary/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + cc_binary( name = "test_binary", srcs = ["test_binary.cc"], diff --git a/test/c/BUILD b/test/c/BUILD index 8390b87..1694c72 100644 --- a/test/c/BUILD +++ b/test/c/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:c") + c_test( name = "c_test", srcs = ["test.c"], diff --git a/test/deps/BUILD b/test/deps/BUILD index 7336ae9..27e9b51 100644 --- a/test/deps/BUILD +++ b/test/deps/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + # Tests that a sequence of dependencies works as expected. cc_library( name = "lib1", diff --git a/test/embed/BUILD b/test/embed/BUILD index 3e7fe4c..d2a39c1 100644 --- a/test/embed/BUILD +++ b/test/embed/BUILD @@ -1,4 +1,4 @@ -subinclude("//build_defs:cc_embed_binary") +subinclude("//build_defs:cc", "//build_defs:cc_embed_binary") cc_embed_binary( name = "embedded_file_1", @@ -32,9 +32,9 @@ cc_library( name = "embedded_files", srcs = ["embedded_files.cc"], hdrs = ["embedded_files.h"], + visibility = ["//test/..."], deps = [ ":embedded_file_1", ":embedded_file_3", ], - visibility = ["//test/..."], ) diff --git a/test/gtest/BUILD b/test/gtest/BUILD index a467790..f8bd142 100644 --- a/test/gtest/BUILD +++ b/test/gtest/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + package(cc = { "test_main": "//gtest:main", }) diff --git a/test/labels/BUILD b/test/labels/BUILD index 5c97be0..65ab5ed 100644 --- a/test/labels/BUILD +++ b/test/labels/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + cc_library( name = "lib1", hdrs = ["lib1/include/lib.hpp"], diff --git a/test/modules/BUILD b/test/modules/BUILD index 3c9d323..09c0a36 100644 --- a/test/modules/BUILD +++ b/test/modules/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + # Currently only supported for Clang. if "clang" in CONFIG.CC.CPP_TOOL: cc_module( diff --git a/test/so/BUILD b/test/so/BUILD index 8bbdc87..ce4b6e2 100644 --- a/test/so/BUILD +++ b/test/so/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + # TODO(peterebden): now Python is becoming a plugin, we should choose something else to test with. cc_shared_object( name = "so_test", From 84faeb5b3c060f18a17a662d4a996e958150da67 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:11:06 +0100 Subject: [PATCH 5/9] Remove so test since no Python --- test/so/BUILD | 36 ------------------- test/so/__init__.py | 0 test/so/shared_object_test.py | 20 ----------- test/so/so_test.cc | 67 ----------------------------------- 4 files changed, 123 deletions(-) delete mode 100644 test/so/BUILD delete mode 100644 test/so/__init__.py delete mode 100644 test/so/shared_object_test.py delete mode 100644 test/so/so_test.cc diff --git a/test/so/BUILD b/test/so/BUILD deleted file mode 100644 index ce4b6e2..0000000 --- a/test/so/BUILD +++ /dev/null @@ -1,36 +0,0 @@ -subinclude("//build_defs:cc") - -# TODO(peterebden): now Python is becoming a plugin, we should choose something else to test with. -cc_shared_object( - name = "so_test", - srcs = ["so_test.cc"], - out = "so_test.so", - linker_flags = ["-bundle -undefined dynamic_lookup"] if is_platform(os = "darwin") else [], - pkg_config_cflags = ["python3"], - deps = [ - "//test/embed:embedded_files", - ], -) - -# Used by Python build code as a convenient way of testing itself. -python_library( - name = "so_test_py", - srcs = ["__init__.py"], - resources = [":so_test"], - visibility = ["//test/python_rules:zip_unsafe_test"], - zip_safe = False, -) - -python_test( - name = "shared_object_test", - srcs = ["shared_object_test.py"], - labels = [ - "cc", - "py3_pkg_config", - "embed", - ], - zip_safe = False, - deps = [ - ":so_test", - ], -) diff --git a/test/so/__init__.py b/test/so/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/so/shared_object_test.py b/test/so/shared_object_test.py deleted file mode 100644 index 8019976..0000000 --- a/test/so/shared_object_test.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Unit test to confirm we can load .so Python extensions.""" - -import unittest - -from test.so import so_test - - -class SharedObjectTest(unittest.TestCase): - - def test_file1_contents(self): - contents = so_test.get_embedded_file_1() - self.assertEqual('testing message 1\n', contents) - - def test_file3_contents(self): - contents = so_test.get_embedded_file_3() - self.assertEqual('testing message 3\n', contents) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/so/so_test.cc b/test/so/so_test.cc deleted file mode 100644 index 2af7dd1..0000000 --- a/test/so/so_test.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Simple Python extension, this happens to be a handy way of testing that -// cc_shared_object actually does something useful. - -#include -#include - -#include "test/embed/embedded_files.h" - - -namespace plz { - -PyObject* get_file1(PyObject *self, PyObject *args) { - return PyUnicode_FromString(embedded_file1_contents().c_str()); -} - -PyObject* get_file3(PyObject *self, PyObject *args) { - return PyUnicode_FromString(embedded_file3_contents().c_str()); -} - -static PyMethodDef so_test_methods[] = { - {"get_embedded_file_1", get_file1, METH_VARARGS, "gets the first embedded file"}, - {"get_embedded_file_3", get_file3, METH_VARARGS, "gets the third embedded file"}, - {NULL, NULL, 0, NULL} -}; - -#if PY_MAJOR_VERSION >= 3 -#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) - -struct module_state { - PyObject *error; -}; - -static int so_test_traverse(PyObject *m, visitproc visit, void *arg) { - Py_VISIT(GETSTATE(m)->error); - return 0; -} - -static int so_test_clear(PyObject *m) { - Py_CLEAR(GETSTATE(m)->error); - return 0; -} - -static struct PyModuleDef so_test_def = { - PyModuleDef_HEAD_INIT, - "so_test", - NULL, - sizeof(struct module_state), - so_test_methods, - NULL, - so_test_traverse, - so_test_clear, - NULL -}; - -#endif // PY_MAJOR_VERSION >= 3 - -} // namespace plz - -#if PY_MAJOR_VERSION >= 3 -PyMODINIT_FUNC PyInit_so_test() { - return PyModule_Create(&plz::so_test_def); -} -#else -PyMODINIT_FUNC initso_test() { - Py_InitModule("so_test", plz::so_test_methods); -} -#endif From 313534c7d433f27c5005a84fc120587182ffc966 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:11:43 +0100 Subject: [PATCH 6/9] more --- gtest/BUILD | 4 +++- unittest-pp/BUILD | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gtest/BUILD b/gtest/BUILD index dd029bf..949ee64 100644 --- a/gtest/BUILD +++ b/gtest/BUILD @@ -1,3 +1,5 @@ +subinclude("//build_defs:cc") + github_repo( name = "gtest", bazel_compat = True, @@ -7,8 +9,8 @@ github_repo( cc_library( name = "main", + visibility = ["PUBLIC"], deps = [ "///gtest/gtest//:gtest_main", ], - visibility = ["PUBLIC"], ) diff --git a/unittest-pp/BUILD b/unittest-pp/BUILD index 187ca83..b5e4617 100644 --- a/unittest-pp/BUILD +++ b/unittest-pp/BUILD @@ -1,8 +1,10 @@ +subinclude("//build_defs:cc") + github_repo( name = "unittest_cpp", - repo = "unittest-cpp/unittest-cpp", - hashes = ["3ba4f8b6c6e75ca8c79dd6008c78e95fb08554fbf2e0f1195fb78a4bf5a8a805"], build_file = "unittest.build", + hashes = ["3ba4f8b6c6e75ca8c79dd6008c78e95fb08554fbf2e0f1195fb78a4bf5a8a805"], + repo = "unittest-cpp/unittest-cpp", revision = "v2.0.0", strip_prefix = "unittest-cpp-2.0.0", ) From c6b6d804b6ab3569aaf6a3462def2c159d24e0bf Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:39:19 +0100 Subject: [PATCH 7/9] unittestpp --- unittest-pp/unittest.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittest-pp/unittest.build b/unittest-pp/unittest.build index fb9693d..b8f9f0c 100644 --- a/unittest-pp/unittest.build +++ b/unittest-pp/unittest.build @@ -1,5 +1,7 @@ # BUILD file for UnitTest++ (github.com/unittest-cpp/unittest-cpp) +subinclude("///cc//build_defs:cc") + os = "Win32" if CONFIG.OS == "windows" else "Posix" cc_library( From 0a44ce12a8d3784d8adc5fe5dcd2b41be5b6163d Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:41:43 +0100 Subject: [PATCH 8/9] remove bazel compat --- gtest/BUILD | 2 +- gtest/gtest.build | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 gtest/gtest.build diff --git a/gtest/BUILD b/gtest/BUILD index 949ee64..31d6f73 100644 --- a/gtest/BUILD +++ b/gtest/BUILD @@ -2,7 +2,7 @@ subinclude("//build_defs:cc") github_repo( name = "gtest", - bazel_compat = True, + build_file = "gtest.build", repo = "google/googletest", revision = "release-1.8.1", ) diff --git a/gtest/gtest.build b/gtest/gtest.build new file mode 100644 index 0000000..63cd7fa --- /dev/null +++ b/gtest/gtest.build @@ -0,0 +1,42 @@ +package(default_visibility = ["PUBLIC"]) + +subinclude("///cc//build_defs:cc") + +# Google Test including Google Mock +cc_library( + name = "gtest", + srcs = glob( + include = [ + "googletest/src/*.cc", + "googletest/src/*.h", + "googletest/include/gtest/**/*.h", + "googlemock/src/*.cc", + "googlemock/include/gmock/**/*.h", + ], + exclude = [ + "googletest/src/gtest-all.cc", + "googletest/src/gtest_main.cc", + "googlemock/src/gmock-all.cc", + "googlemock/src/gmock_main.cc", + ], + ), + hdrs = glob([ + "googletest/include/gtest/*.h", + "googlemock/include/gmock/*.h", + ]), + cflags = ["-pthread"], + includes = [ + "googlemock", + "googlemock/include", + "googletest", + "googletest/include", + ], +) + +cc_library( + name = "gtest_main", + srcs = [ + "googlemock/src/gmock_main.cc", + ], + deps = [":gtest"], +) From fd72957b8276d4c6d104baa7c3c6b987cb04f8d2 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 11 Jul 2023 10:45:54 +0100 Subject: [PATCH 9/9] preload it --- .plzconfig | 2 +- gtest/gtest.build | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.plzconfig b/.plzconfig index 94d96d7..cd0284f 100644 --- a/.plzconfig +++ b/.plzconfig @@ -2,7 +2,7 @@ version = >=17.0.0 [parse] -preloadbuilddefs = build_defs/cc.build_defs +preloadsubincludes = //build_defs:cc [PluginDefinition] name = cc diff --git a/gtest/gtest.build b/gtest/gtest.build index 63cd7fa..c131be6 100644 --- a/gtest/gtest.build +++ b/gtest/gtest.build @@ -1,7 +1,5 @@ package(default_visibility = ["PUBLIC"]) -subinclude("///cc//build_defs:cc") - # Google Test including Google Mock cc_library( name = "gtest",