1# Copyright (c) 2009-2021, Google LLC 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are met: 6# * Redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer. 8# * Redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution. 11# * Neither the name of Google LLC nor the 12# names of its contributors may be used to endorse or promote products 13# derived from this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY 19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26load( 27 ":build_defs.bzl", 28 "staleness_test", 29) 30load( 31 "//bazel:build_defs.bzl", 32 "make_shell_script", 33) 34 35licenses(["notice"]) 36 37exports_files(["staleness_test.py"]) 38 39py_library( 40 name = "staleness_test_lib", 41 testonly = 1, 42 srcs = ["staleness_test_lib.py"], 43 # This is public only for use by the staleness_test() macro. Please do not 44 # depend on this target directly. 45 visibility = ["//visibility:public"], 46) 47 48py_binary( 49 name = "make_cmakelists", 50 srcs = ["make_cmakelists.py"], 51) 52 53genrule( 54 name = "gen_cmakelists", 55 srcs = [ 56 "//:BUILD", 57 "//:WORKSPACE", 58 "//bazel:workspace_deps.bzl", 59 ], 60 outs = ["generated-in/CMakeLists.txt"], 61 cmd = "$(location :make_cmakelists) $@", 62 tools = [":make_cmakelists"], 63) 64 65genrule( 66 name = "copy_protos", 67 srcs = ["//:descriptor_upb_proto"], 68 outs = [ 69 "generated-in/google/protobuf/descriptor.upb.c", 70 "generated-in/google/protobuf/descriptor.upb.h", 71 ], 72 cmd = "cp $(SRCS) $(@D)/generated-in/google/protobuf", 73) 74 75staleness_test( 76 name = "test_generated_files", 77 outs = [ 78 "CMakeLists.txt", 79 "google/protobuf/descriptor.upb.c", 80 "google/protobuf/descriptor.upb.h", 81 ], 82 generated_pattern = "generated-in/%s", 83 tags = ["manual"], 84) 85 86# Test the CMake build ######################################################### 87 88make_shell_script( 89 name = "gen_run_cmake_build", 90 out = "run_cmake_build.sh", 91 contents = "set -ex\n" + 92 "(cd cmake/generated-in && rsync -avR . ..)\n" + 93 "mkdir build && cd build && cmake ../cmake && make -j8 && make test", 94) 95 96sh_test( 97 name = "cmake_build", 98 srcs = ["run_cmake_build.sh"], 99 data = [ 100 ":copy_protos", 101 ":gen_cmakelists", 102 "//:cmake_files", 103 "@utf8_range//:utf8_range_srcs", 104 ], 105 target_compatible_with = select({ 106 "@platforms//os:windows": ["@platforms//:incompatible"], 107 "//conditions:default": [], 108 }), 109 deps = ["@bazel_tools//tools/bash/runfiles"], 110) 111