Skip to content

Commit 3696c37

Browse files
authored
Improve configure_file and add rapidcheck, json, yaml-cpp [BUILD-411] (#12)
1 parent b80ca39 commit 3696c37

File tree

4 files changed

+106
-9
lines changed

4 files changed

+106
-9
lines changed

third_party/json.BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2022 Swift Navigation Inc.
2+
# Contact: Swift Navigation <[email protected]>
3+
#
4+
# This source is subject to the license found in the file 'LICENSE' which must
5+
# be be distributed together with this source. All other rights reserved.
6+
#
7+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10+
11+
package(
12+
default_visibility = ["//visibility:public"],
13+
)
14+
15+
cc_library(
16+
name = "json",
17+
hdrs = ["src/json.hpp"],
18+
includes = ["src"],
19+
)

third_party/rapidcheck.BUILD

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (C) 2022 Swift Navigation Inc.
2+
# Contact: Swift Navigation <[email protected]>
3+
#
4+
# This source is subject to the license found in the file 'LICENSE' which must
5+
# be be distributed together with this source. All other rights reserved.
6+
#
7+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10+
11+
package(
12+
default_visibility = ["//visibility:public"],
13+
)
14+
15+
cc_library(
16+
name = "rapidcheck",
17+
srcs = glob(["src/**"]),
18+
hdrs = glob(["include/**"] + ["extras/**"]),
19+
includes = [
20+
"extras/gtest/include",
21+
"include",
22+
],
23+
)

third_party/yaml-cpp.BUILD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (C) 2022 Swift Navigation Inc.
2+
# Contact: Swift Navigation <[email protected]>
3+
#
4+
# This source is subject to the license found in the file 'LICENSE' which must
5+
# be be distributed together with this source. All other rights reserved.
6+
#
7+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10+
11+
package(
12+
default_visibility = ["//visibility:public"],
13+
)
14+
15+
yaml_cpp_defines = select({
16+
# On Windows, ensure static linking is used.
17+
"@platforms//os:windows": [
18+
"YAML_CPP_STATIC_DEFINE",
19+
"YAML_CPP_NO_CONTRIB",
20+
],
21+
"//conditions:default": [],
22+
})
23+
24+
cc_library(
25+
name = "yaml-cpp_internal",
26+
hdrs = glob(["src/**/*.h"]),
27+
strip_include_prefix = "src",
28+
visibility = ["//:__subpackages__"],
29+
)
30+
31+
cc_library(
32+
name = "yaml-cpp",
33+
srcs = glob([
34+
"src/**/*.cpp",
35+
"src/**/*.h",
36+
]),
37+
hdrs = glob(["include/**/*.h"]),
38+
defines = yaml_cpp_defines,
39+
includes = ["include"],
40+
visibility = ["//visibility:public"],
41+
)

tools/configure_file.bzl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,38 @@
1010

1111
CMAKE_FALSE_CONSTANTS = ["0", "OFF", "NO", "FALSE", "N", "IGNORE", "NOTFOUND"]
1212

13-
def _configure_file_impl(ctx):
14-
vars = {}
15-
for (key, val) in ctx.attr.vars.items():
16-
cmake_define = "#cmakedefine {}".format(key)
17-
define = "// #undef {}".format(key) if val in CMAKE_FALSE_CONSTANTS else "#define {}".format(key)
13+
def configure_file_impl(ctx, vars):
14+
subs = {}
15+
for (key, val) in vars.items():
16+
cmake_define_nl = "#cmakedefine {}\n".format(key)
17+
define_nl = "// #undef {}\n".format(key) if val in CMAKE_FALSE_CONSTANTS else "#define {}\n".format(key)
18+
cmake_define_s = "#cmakedefine {} ".format(key)
19+
define_s = "// #undef {} ".format(key) if val in CMAKE_FALSE_CONSTANTS else "#define {} ".format(key)
20+
21+
cmake_define_01_nl = "#cmakedefine01 {}\n".format(key)
22+
define_01_nl = "#define {} 0\n".format(key) if val in CMAKE_FALSE_CONSTANTS else "#define {} 1\n".format(key)
23+
cmake_define_01_s = "#cmakedefine01 {} ".format(key)
24+
define_01_s = "#define {} 0 ".format(key) if val in CMAKE_FALSE_CONSTANTS else "#define {} 1 ".format(key)
25+
26+
subs[cmake_define_nl] = define_nl
27+
subs[cmake_define_s] = define_s
28+
subs[cmake_define_01_nl] = define_01_nl
29+
subs[cmake_define_01_s] = define_01_s
1830

19-
vars[cmake_define] = define
20-
vars["@{}@".format(key)] = val
21-
vars["${" + key + "}"] = val
31+
subs["@{}@".format(key)] = val
32+
subs["${" + key + "}"] = val
2233

2334
out = ctx.actions.declare_file(ctx.attr.out)
2435
ctx.actions.expand_template(
2536
output = out,
2637
template = ctx.file.template,
27-
substitutions = vars,
38+
substitutions = subs,
2839
)
2940
return [DefaultInfo(files = depset([out]))]
3041

42+
def _configure_file_impl(ctx):
43+
return configure_file_impl(ctx, ctx.attr.vars)
44+
3145
configure_file = rule(
3246
implementation = _configure_file_impl,
3347
attrs = {

0 commit comments

Comments
 (0)