ruby_memprofiler_pprof 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
- data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
- data/ext/ruby_memprofiler_pprof/compat.c +182 -0
- data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
- data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
- data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
- data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
- data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
- data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
- data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
- data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
- data/lib/ruby_memprofiler_pprof/version.rb +5 -0
- data/lib/ruby_memprofiler_pprof.rb +8 -0
- data/libexec/ruby_memprofiler_pprof_profile +16 -0
- metadata +257 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2009-2021, Google LLC
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
|
13
|
+
# * Neither the name of Google LLC nor the
|
|
14
|
+
# names of its contributors may be used to endorse or promote products
|
|
15
|
+
# derived from this software without specific prior written permission.
|
|
16
|
+
#
|
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
|
|
21
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
24
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
"""A tool to convert {WORKSPACE, BUILD} -> CMakeLists.txt.
|
|
29
|
+
|
|
30
|
+
This tool is very upb-specific at the moment, and should not be seen as a
|
|
31
|
+
generic Bazel -> CMake converter.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import absolute_import
|
|
35
|
+
from __future__ import division
|
|
36
|
+
from __future__ import print_function
|
|
37
|
+
|
|
38
|
+
import sys
|
|
39
|
+
import textwrap
|
|
40
|
+
import os
|
|
41
|
+
|
|
42
|
+
def StripFirstChar(deps):
|
|
43
|
+
return [dep[1:] for dep in deps]
|
|
44
|
+
|
|
45
|
+
def IsSourceFile(name):
|
|
46
|
+
return name.endswith(".c") or name.endswith(".cc")
|
|
47
|
+
|
|
48
|
+
class BuildFileFunctions(object):
|
|
49
|
+
def __init__(self, converter):
|
|
50
|
+
self.converter = converter
|
|
51
|
+
|
|
52
|
+
def _add_deps(self, kwargs, keyword=""):
|
|
53
|
+
if "deps" not in kwargs:
|
|
54
|
+
return
|
|
55
|
+
self.converter.toplevel += "target_link_libraries(%s%s\n %s)\n" % (
|
|
56
|
+
kwargs["name"],
|
|
57
|
+
keyword,
|
|
58
|
+
"\n ".join(StripFirstChar(kwargs["deps"]))
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def load(self, *args):
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
def cc_library(self, **kwargs):
|
|
65
|
+
if kwargs["name"].endswith("amalgamation"):
|
|
66
|
+
return
|
|
67
|
+
if kwargs["name"] == "upbc_generator":
|
|
68
|
+
return
|
|
69
|
+
if kwargs["name"] == "lupb":
|
|
70
|
+
return
|
|
71
|
+
files = kwargs.get("srcs", []) + kwargs.get("hdrs", [])
|
|
72
|
+
found_files = []
|
|
73
|
+
pregenerated_files = [
|
|
74
|
+
"CMakeLists.txt", "descriptor.upb.h", "descriptor.upb.c"
|
|
75
|
+
]
|
|
76
|
+
for file in files:
|
|
77
|
+
if os.path.basename(file) in pregenerated_files:
|
|
78
|
+
found_files.append("../cmake/" + file)
|
|
79
|
+
else:
|
|
80
|
+
found_files.append("../" + file)
|
|
81
|
+
|
|
82
|
+
if list(filter(IsSourceFile, files)):
|
|
83
|
+
# Has sources, make this a normal library.
|
|
84
|
+
self.converter.toplevel += "add_library(%s\n %s)\n" % (
|
|
85
|
+
kwargs["name"],
|
|
86
|
+
"\n ".join(found_files)
|
|
87
|
+
)
|
|
88
|
+
self._add_deps(kwargs)
|
|
89
|
+
else:
|
|
90
|
+
# Header-only library, have to do a couple things differently.
|
|
91
|
+
# For some info, see:
|
|
92
|
+
# http://mariobadr.com/creating-a-header-only-library-with-cmake.html
|
|
93
|
+
self.converter.toplevel += "add_library(%s INTERFACE)\n" % (
|
|
94
|
+
kwargs["name"]
|
|
95
|
+
)
|
|
96
|
+
self._add_deps(kwargs, " INTERFACE")
|
|
97
|
+
|
|
98
|
+
def cc_binary(self, **kwargs):
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
def cc_test(self, **kwargs):
|
|
102
|
+
# Disable this until we properly support upb_proto_library().
|
|
103
|
+
# self.converter.toplevel += "add_executable(%s\n %s)\n" % (
|
|
104
|
+
# kwargs["name"],
|
|
105
|
+
# "\n ".join(kwargs["srcs"])
|
|
106
|
+
# )
|
|
107
|
+
# self.converter.toplevel += "add_test(NAME %s COMMAND %s)\n" % (
|
|
108
|
+
# kwargs["name"],
|
|
109
|
+
# kwargs["name"],
|
|
110
|
+
# )
|
|
111
|
+
|
|
112
|
+
# if "data" in kwargs:
|
|
113
|
+
# for data_dep in kwargs["data"]:
|
|
114
|
+
# self.converter.toplevel += textwrap.dedent("""\
|
|
115
|
+
# add_custom_command(
|
|
116
|
+
# TARGET %s POST_BUILD
|
|
117
|
+
# COMMAND ${CMAKE_COMMAND} -E copy
|
|
118
|
+
# ${CMAKE_SOURCE_DIR}/%s
|
|
119
|
+
# ${CMAKE_CURRENT_BINARY_DIR}/%s)\n""" % (
|
|
120
|
+
# kwargs["name"], data_dep, data_dep
|
|
121
|
+
# ))
|
|
122
|
+
|
|
123
|
+
# self._add_deps(kwargs)
|
|
124
|
+
pass
|
|
125
|
+
|
|
126
|
+
def cc_fuzz_test(self, **kwargs):
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
def py_library(self, **kwargs):
|
|
130
|
+
pass
|
|
131
|
+
|
|
132
|
+
def py_binary(self, **kwargs):
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
def lua_proto_library(self, **kwargs):
|
|
136
|
+
pass
|
|
137
|
+
|
|
138
|
+
def sh_test(self, **kwargs):
|
|
139
|
+
pass
|
|
140
|
+
|
|
141
|
+
def make_shell_script(self, **kwargs):
|
|
142
|
+
pass
|
|
143
|
+
|
|
144
|
+
def exports_files(self, files, **kwargs):
|
|
145
|
+
pass
|
|
146
|
+
|
|
147
|
+
def proto_library(self, **kwargs):
|
|
148
|
+
pass
|
|
149
|
+
|
|
150
|
+
def cc_proto_library(self, **kwargs):
|
|
151
|
+
pass
|
|
152
|
+
|
|
153
|
+
def generated_file_staleness_test(self, **kwargs):
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
def upb_amalgamation(self, **kwargs):
|
|
157
|
+
pass
|
|
158
|
+
|
|
159
|
+
def upb_proto_library(self, **kwargs):
|
|
160
|
+
pass
|
|
161
|
+
|
|
162
|
+
def upb_proto_library_copts(self, **kwargs):
|
|
163
|
+
pass
|
|
164
|
+
|
|
165
|
+
def upb_proto_reflection_library(self, **kwargs):
|
|
166
|
+
pass
|
|
167
|
+
|
|
168
|
+
def upb_proto_srcs(self, **kwargs):
|
|
169
|
+
pass
|
|
170
|
+
|
|
171
|
+
def genrule(self, **kwargs):
|
|
172
|
+
pass
|
|
173
|
+
|
|
174
|
+
def config_setting(self, **kwargs):
|
|
175
|
+
pass
|
|
176
|
+
|
|
177
|
+
def upb_fasttable_enabled(self, **kwargs):
|
|
178
|
+
pass
|
|
179
|
+
|
|
180
|
+
def select(self, arg_dict):
|
|
181
|
+
return []
|
|
182
|
+
|
|
183
|
+
def glob(self, *args):
|
|
184
|
+
return []
|
|
185
|
+
|
|
186
|
+
def licenses(self, *args):
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
def filegroup(self, **kwargs):
|
|
190
|
+
pass
|
|
191
|
+
|
|
192
|
+
def map_dep(self, arg):
|
|
193
|
+
return arg
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class WorkspaceFileFunctions(object):
|
|
197
|
+
def __init__(self, converter):
|
|
198
|
+
self.converter = converter
|
|
199
|
+
|
|
200
|
+
def load(self, *args):
|
|
201
|
+
pass
|
|
202
|
+
|
|
203
|
+
def workspace(self, **kwargs):
|
|
204
|
+
self.converter.prelude += "project(%s)\n" % (kwargs["name"])
|
|
205
|
+
self.converter.prelude += "set(CMAKE_C_STANDARD 99)\n"
|
|
206
|
+
|
|
207
|
+
def http_archive(self, **kwargs):
|
|
208
|
+
pass
|
|
209
|
+
|
|
210
|
+
def git_repository(self, **kwargs):
|
|
211
|
+
pass
|
|
212
|
+
|
|
213
|
+
def new_git_repository(self, **kwargs):
|
|
214
|
+
pass
|
|
215
|
+
|
|
216
|
+
def bazel_version_repository(self, **kwargs):
|
|
217
|
+
pass
|
|
218
|
+
|
|
219
|
+
def upb_deps(self):
|
|
220
|
+
pass
|
|
221
|
+
|
|
222
|
+
def protobuf_deps(self):
|
|
223
|
+
pass
|
|
224
|
+
|
|
225
|
+
def rules_fuzzing_dependencies(self):
|
|
226
|
+
pass
|
|
227
|
+
|
|
228
|
+
def rules_fuzzing_init(self):
|
|
229
|
+
pass
|
|
230
|
+
|
|
231
|
+
def system_python(self, **kwargs):
|
|
232
|
+
pass
|
|
233
|
+
|
|
234
|
+
def register_toolchains(self, toolchain):
|
|
235
|
+
pass
|
|
236
|
+
|
|
237
|
+
def python_source_archive(self, **kwargs):
|
|
238
|
+
pass
|
|
239
|
+
|
|
240
|
+
def python_nuget_package(self, **kwargs):
|
|
241
|
+
pass
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class Converter(object):
|
|
245
|
+
def __init__(self):
|
|
246
|
+
self.prelude = ""
|
|
247
|
+
self.toplevel = ""
|
|
248
|
+
self.if_lua = ""
|
|
249
|
+
|
|
250
|
+
def convert(self):
|
|
251
|
+
return self.template % {
|
|
252
|
+
"prelude": converter.prelude,
|
|
253
|
+
"toplevel": converter.toplevel,
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
template = textwrap.dedent("""\
|
|
257
|
+
# This file was generated from BUILD using tools/make_cmakelists.py.
|
|
258
|
+
|
|
259
|
+
cmake_minimum_required(VERSION 3.1)
|
|
260
|
+
|
|
261
|
+
if(${CMAKE_VERSION} VERSION_LESS 3.12)
|
|
262
|
+
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
|
263
|
+
else()
|
|
264
|
+
cmake_policy(VERSION 3.12)
|
|
265
|
+
endif()
|
|
266
|
+
|
|
267
|
+
cmake_minimum_required (VERSION 3.0)
|
|
268
|
+
cmake_policy(SET CMP0048 NEW)
|
|
269
|
+
|
|
270
|
+
%(prelude)s
|
|
271
|
+
|
|
272
|
+
# Prevent CMake from setting -rdynamic on Linux (!!).
|
|
273
|
+
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
|
274
|
+
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
|
275
|
+
|
|
276
|
+
# Set default build type.
|
|
277
|
+
if(NOT CMAKE_BUILD_TYPE)
|
|
278
|
+
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
|
|
279
|
+
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
|
280
|
+
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
|
|
281
|
+
FORCE)
|
|
282
|
+
endif()
|
|
283
|
+
|
|
284
|
+
# When using Ninja, compiler output won't be colorized without this.
|
|
285
|
+
include(CheckCXXCompilerFlag)
|
|
286
|
+
CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always SUPPORTS_COLOR_ALWAYS)
|
|
287
|
+
if(SUPPORTS_COLOR_ALWAYS)
|
|
288
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
|
289
|
+
endif()
|
|
290
|
+
|
|
291
|
+
# Implement ASAN/UBSAN options
|
|
292
|
+
if(UPB_ENABLE_ASAN)
|
|
293
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
|
294
|
+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
|
295
|
+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
|
296
|
+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
|
|
297
|
+
endif()
|
|
298
|
+
|
|
299
|
+
if(UPB_ENABLE_UBSAN)
|
|
300
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
|
301
|
+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
|
302
|
+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
|
303
|
+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
|
|
304
|
+
endif()
|
|
305
|
+
|
|
306
|
+
include_directories(..)
|
|
307
|
+
include_directories(../cmake)
|
|
308
|
+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
309
|
+
|
|
310
|
+
if(APPLE)
|
|
311
|
+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
|
|
312
|
+
elseif(UNIX)
|
|
313
|
+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
|
|
314
|
+
endif()
|
|
315
|
+
|
|
316
|
+
enable_testing()
|
|
317
|
+
|
|
318
|
+
%(toplevel)s
|
|
319
|
+
|
|
320
|
+
""")
|
|
321
|
+
|
|
322
|
+
data = {}
|
|
323
|
+
converter = Converter()
|
|
324
|
+
|
|
325
|
+
def GetDict(obj):
|
|
326
|
+
ret = {}
|
|
327
|
+
ret["UPB_DEFAULT_COPTS"] = [] # HACK
|
|
328
|
+
ret["UPB_DEFAULT_CPPOPTS"] = [] # HACK
|
|
329
|
+
for k in dir(obj):
|
|
330
|
+
if not k.startswith("_"):
|
|
331
|
+
ret[k] = getattr(obj, k);
|
|
332
|
+
return ret
|
|
333
|
+
|
|
334
|
+
globs = GetDict(converter)
|
|
335
|
+
|
|
336
|
+
exec(open("WORKSPACE").read(), GetDict(WorkspaceFileFunctions(converter)))
|
|
337
|
+
exec(open("BUILD").read(), GetDict(BuildFileFunctions(converter)))
|
|
338
|
+
|
|
339
|
+
with open(sys.argv[1], "w") as f:
|
|
340
|
+
f.write(converter.convert())
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2009-2021, Google LLC
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
|
13
|
+
# * Neither the name of Google LLC nor the
|
|
14
|
+
# names of its contributors may be used to endorse or promote products
|
|
15
|
+
# derived from this software without specific prior written permission.
|
|
16
|
+
#
|
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
|
|
21
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
24
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
"""The py_test() script for generated_file_staleness_test() rules.
|
|
29
|
+
|
|
30
|
+
Note that this file is preprocessed! The INSERT_<...> text below is replaced
|
|
31
|
+
with the actual list of files before we actually run the script.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import absolute_import
|
|
35
|
+
|
|
36
|
+
from cmake import staleness_test_lib
|
|
37
|
+
import unittest
|
|
38
|
+
import sys
|
|
39
|
+
|
|
40
|
+
file_list = """
|
|
41
|
+
INSERT_FILE_LIST_HERE
|
|
42
|
+
""".split()
|
|
43
|
+
|
|
44
|
+
config = staleness_test_lib.Config(file_list)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestFilesMatch(unittest.TestCase):
|
|
48
|
+
|
|
49
|
+
def testFilesMatch(self):
|
|
50
|
+
errors = staleness_test_lib.CheckFilesMatch(config)
|
|
51
|
+
self.assertFalse(errors, errors)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if len(sys.argv) > 1 and sys.argv[1] == "--fix":
|
|
55
|
+
staleness_test_lib.FixFiles(config)
|
|
56
|
+
else:
|
|
57
|
+
unittest.main()
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2009-2021, Google LLC
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
|
13
|
+
# * Neither the name of Google LLC nor the
|
|
14
|
+
# names of its contributors may be used to endorse or promote products
|
|
15
|
+
# derived from this software without specific prior written permission.
|
|
16
|
+
#
|
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
|
|
21
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
24
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
"""Shared code for validating generated_file_staleness_test() rules.
|
|
29
|
+
|
|
30
|
+
This code is used by test scripts generated from
|
|
31
|
+
generated_file_staleness_test() rules.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import absolute_import
|
|
35
|
+
from __future__ import print_function
|
|
36
|
+
|
|
37
|
+
import sys
|
|
38
|
+
import os
|
|
39
|
+
from shutil import copyfile
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class _FilePair(object):
|
|
43
|
+
"""Represents a single (target, generated) file pair."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, target, generated):
|
|
46
|
+
self.target = target
|
|
47
|
+
self.generated = generated
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Config(object):
|
|
51
|
+
"""Represents the configuration for a single staleness test target."""
|
|
52
|
+
|
|
53
|
+
def __init__(self, file_list):
|
|
54
|
+
# Duplicate to avoid modifying our arguments.
|
|
55
|
+
file_list = list(file_list)
|
|
56
|
+
|
|
57
|
+
# The file list contains a few other bits of information at the end.
|
|
58
|
+
# This is packed by the code in build_defs.bzl.
|
|
59
|
+
self.target_name = file_list.pop()
|
|
60
|
+
self.package_name = file_list.pop()
|
|
61
|
+
self.pattern = file_list.pop()
|
|
62
|
+
|
|
63
|
+
self.file_list = file_list
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _GetFilePairs(config):
|
|
67
|
+
"""Generates the list of file pairs.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
config: a Config object representing this target's config.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
A list of _FilePair objects.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
ret = []
|
|
77
|
+
|
|
78
|
+
has_bazel_genfiles = os.path.exists("bazel-bin")
|
|
79
|
+
|
|
80
|
+
for filename in config.file_list:
|
|
81
|
+
target = os.path.join(config.package_name, filename)
|
|
82
|
+
generated = os.path.join(config.package_name, config.pattern % filename)
|
|
83
|
+
if has_bazel_genfiles:
|
|
84
|
+
generated = os.path.join("bazel-bin", generated)
|
|
85
|
+
|
|
86
|
+
# Generated files should always exist. Blaze should guarantee this before
|
|
87
|
+
# we are run.
|
|
88
|
+
if not os.path.isfile(generated):
|
|
89
|
+
print("Generated file '%s' does not exist." % generated)
|
|
90
|
+
print("Please run this command to generate it:")
|
|
91
|
+
print(" bazel build %s:%s" % (config.package_name, config.target_name))
|
|
92
|
+
sys.exit(1)
|
|
93
|
+
ret.append(_FilePair(target, generated))
|
|
94
|
+
|
|
95
|
+
return ret
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _GetMissingAndStaleFiles(file_pairs):
|
|
99
|
+
"""Generates lists of missing and stale files.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
file_pairs: a list of _FilePair objects.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
missing_files: a list of _FilePair objects representing missing files.
|
|
106
|
+
These target files do not exist at all.
|
|
107
|
+
stale_files: a list of _FilePair objects representing stale files.
|
|
108
|
+
These target files exist but have stale contents.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
missing_files = []
|
|
112
|
+
stale_files = []
|
|
113
|
+
|
|
114
|
+
for pair in file_pairs:
|
|
115
|
+
if not os.path.isfile(pair.target):
|
|
116
|
+
missing_files.append(pair)
|
|
117
|
+
continue
|
|
118
|
+
|
|
119
|
+
with open(pair.generated) as g, open(pair.target) as t:
|
|
120
|
+
if g.read() != t.read():
|
|
121
|
+
stale_files.append(pair)
|
|
122
|
+
|
|
123
|
+
return missing_files, stale_files
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _CopyFiles(file_pairs):
|
|
127
|
+
"""Copies all generated files to the corresponding target file.
|
|
128
|
+
|
|
129
|
+
The target files must be writable already.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
file_pairs: a list of _FilePair objects that we want to copy.
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
for pair in file_pairs:
|
|
136
|
+
target_dir = os.path.dirname(pair.target)
|
|
137
|
+
if not os.path.isdir(target_dir):
|
|
138
|
+
os.makedirs(target_dir)
|
|
139
|
+
copyfile(pair.generated, pair.target)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def FixFiles(config):
|
|
143
|
+
"""Implements the --fix option: overwrites missing or out-of-date files.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
config: the Config object for this test.
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
file_pairs = _GetFilePairs(config)
|
|
150
|
+
missing_files, stale_files = _GetMissingAndStaleFiles(file_pairs)
|
|
151
|
+
|
|
152
|
+
_CopyFiles(stale_files + missing_files)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def CheckFilesMatch(config):
|
|
156
|
+
"""Checks whether each target file matches the corresponding generated file.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
config: the Config object for this test.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
None if everything matches, otherwise a string error message.
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
diff_errors = []
|
|
166
|
+
|
|
167
|
+
file_pairs = _GetFilePairs(config)
|
|
168
|
+
missing_files, stale_files = _GetMissingAndStaleFiles(file_pairs)
|
|
169
|
+
|
|
170
|
+
for pair in missing_files:
|
|
171
|
+
diff_errors.append("File %s does not exist" % pair.target)
|
|
172
|
+
continue
|
|
173
|
+
|
|
174
|
+
for pair in stale_files:
|
|
175
|
+
diff_errors.append("File %s is out of date" % pair.target)
|
|
176
|
+
|
|
177
|
+
if diff_errors:
|
|
178
|
+
error_msg = "Files out of date!\n\n"
|
|
179
|
+
error_msg += "To fix run THIS command:\n"
|
|
180
|
+
error_msg += " bazel-bin/%s/%s --fix\n\n" % (config.package_name,
|
|
181
|
+
config.target_name)
|
|
182
|
+
error_msg += "Errors:\n"
|
|
183
|
+
error_msg += " " + "\n ".join(diff_errors)
|
|
184
|
+
return error_msg
|
|
185
|
+
else:
|
|
186
|
+
return None
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import shutil
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
if len(sys.argv) < 2:
|
|
9
|
+
print("Must pass a filename argument")
|
|
10
|
+
sys.exit(1)
|
|
11
|
+
|
|
12
|
+
in_filename = sys.argv[1]
|
|
13
|
+
out_filename = in_filename.replace(".in.md", ".md")
|
|
14
|
+
out_dir = in_filename.replace(".in.md", "")
|
|
15
|
+
|
|
16
|
+
if in_filename == out_filename:
|
|
17
|
+
print("File must end in .in.md")
|
|
18
|
+
sys.exit(1)
|
|
19
|
+
|
|
20
|
+
if os.path.isdir(out_dir):
|
|
21
|
+
shutil.rmtree(out_dir)
|
|
22
|
+
|
|
23
|
+
os.mkdir(out_dir)
|
|
24
|
+
file_num = 1
|
|
25
|
+
|
|
26
|
+
with open(out_filename, "wb") as out_file, open(in_filename, "rb") as in_file:
|
|
27
|
+
for line in in_file:
|
|
28
|
+
if line.startswith(b"```dot"):
|
|
29
|
+
dot_lines = []
|
|
30
|
+
while True:
|
|
31
|
+
dot_line = next(in_file)
|
|
32
|
+
if dot_line == b"```\n":
|
|
33
|
+
break
|
|
34
|
+
dot_lines.append(dot_line)
|
|
35
|
+
dot_input = b"".join(dot_lines)
|
|
36
|
+
svg_filename = out_dir + "/" + str(file_num) + ".svg"
|
|
37
|
+
svg = subprocess.check_output(['dot', '-Tsvg', '-o', svg_filename], input=dot_input)
|
|
38
|
+
out_file.write(b"<div align=center>\n")
|
|
39
|
+
out_file.write(b"<img src='%s'/>\n" % (svg_filename.encode('utf-8')))
|
|
40
|
+
out_file.write(b"</div>\n")
|
|
41
|
+
file_num += 1
|
|
42
|
+
else:
|
|
43
|
+
out_file.write(line)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# C style guide
|
|
2
|
+
|
|
3
|
+
<!--*
|
|
4
|
+
# Document freshness: For more information, see go/fresh-source.
|
|
5
|
+
freshness: { owner: 'haberman' reviewed: '2022-05-08' }
|
|
6
|
+
*-->
|
|
7
|
+
|
|
8
|
+
Since upb is written in pure C, we supplement the
|
|
9
|
+
[Google C++ style guide](https://google.github.io/styleguide/cppguide.html) with
|
|
10
|
+
some C-specific guidance.
|
|
11
|
+
|
|
12
|
+
Everything written here is intended to follow the spirit of the C++ style guide.
|
|
13
|
+
|
|
14
|
+
upb is currently inconsistent about following these conventions. It is intended
|
|
15
|
+
that all code will be updated to match these guidelines. The priority is
|
|
16
|
+
converting public interfaces as these are more difficult to change later.
|
|
17
|
+
|
|
18
|
+
## Naming
|
|
19
|
+
|
|
20
|
+
### Functions and Types
|
|
21
|
+
|
|
22
|
+
C does not have namespaces. Anywhere you would normally use a namespace
|
|
23
|
+
separator (`::`) in C++, we use an underscore (`_`) in C:
|
|
24
|
+
|
|
25
|
+
```c++
|
|
26
|
+
// C equivalent for upb::Arena::New()
|
|
27
|
+
upb_Arena* upb_Arena_New();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Since we rely on `_` to be our namespace separator, we never use it to merely
|
|
31
|
+
separate words in function or type names:
|
|
32
|
+
|
|
33
|
+
```c++
|
|
34
|
+
// BAD: this would be interpreted as upb::FieldDef::has::default().
|
|
35
|
+
bool upb_FieldDef_has_default(const upb_FieldDef* f);
|
|
36
|
+
|
|
37
|
+
// GOOD: this is equivalent to upb::FieldDef::HasDefault().
|
|
38
|
+
bool upb_FieldDef_HasDefault(const upb_FieldDef* f);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For multi-word namespaces, we use `PascalCase`:
|
|
42
|
+
|
|
43
|
+
```c++
|
|
44
|
+
// `PyUpb` is the namespace.
|
|
45
|
+
PyObject* PyUpb_CMessage_GetAttr(PyObject* _self, PyObject* attr);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Private Functions and Members
|
|
49
|
+
|
|
50
|
+
Since we do not have `private` in C++, we use a leading underscore convention
|
|
51
|
+
to mark internal functions and variables that should only be accessed from
|
|
52
|
+
upb:
|
|
53
|
+
|
|
54
|
+
```c++
|
|
55
|
+
// Internal-only function.
|
|
56
|
+
int64_t _upb_Int64_FromLL();
|
|
57
|
+
|
|
58
|
+
// Internal-only members. Underscore prefixes are only necessary when the
|
|
59
|
+
// structure is defined in a header file.
|
|
60
|
+
typedef struct {
|
|
61
|
+
const int32_t* _values; // List of values <0 or >63
|
|
62
|
+
uint64_t _mask; // Bits are set for acceptable value 0 <= x < 64
|
|
63
|
+
int _value_count;
|
|
64
|
+
} upb_MiniTable_Enum;
|
|
65
|
+
```
|