forked from bazelbuild/rules_apple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdtrace.bzl
113 lines (103 loc) · 3.51 KB
/
dtrace.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""# Bazel rules for working with dtrace."""
load(
"@bazel_skylib//lib:dicts.bzl",
"dicts",
)
load(
"@bazel_skylib//lib:paths.bzl",
"paths",
)
load(
"@build_bazel_apple_support//lib:apple_support.bzl",
"apple_support",
)
load(
"//apple/internal/utils:bundle_paths.bzl",
"bundle_paths",
)
def _dtrace_compile_impl(ctx):
"""Implementation for dtrace_compile."""
apple_fragment = ctx.fragments.apple
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
output_hdrs = []
include_dir = None
dtrace = "/usr/sbin/dtrace"
if ctx.executable.dtrace:
dtrace = ctx.executable.dtrace
for src in ctx.files.srcs:
owner_relative_path = bundle_paths.owner_relative_path(src)
label_scoped_owner_path = ctx.label.name + "/" + owner_relative_path.lstrip("/")
hdr = ctx.actions.declare_file(
paths.replace_extension(label_scoped_owner_path, ".h"),
)
output_hdrs.append(hdr)
apple_support.run(
actions = ctx.actions,
xcode_config = xcode_config,
apple_fragment = apple_fragment,
inputs = [src],
outputs = [hdr],
mnemonic = "dtraceCompile",
executable = dtrace,
arguments = ["-h", "-s", src.path, "-o", hdr.path],
progress_message = ("Compiling dtrace probes %s" % (src.basename)),
)
if not include_dir:
hdr_suffix = paths.replace_extension("/" + owner_relative_path.lstrip("/"), ".h")
include_dir = hdr.path.removesuffix(hdr_suffix)
return [
apple_common.new_objc_provider(
strict_include = depset([include_dir]),
),
CcInfo(
compilation_context = cc_common.create_compilation_context(
headers = depset(output_hdrs),
),
),
DefaultInfo(files = depset(output_hdrs)),
]
dtrace_compile = rule(
implementation = _dtrace_compile_impl,
attrs = dicts.add(apple_support.action_required_attrs(), {
"dtrace": attr.label(
doc = "dtrace binary to use.",
mandatory = False,
executable = True,
cfg = "exec",
),
"srcs": attr.label_list(
allow_files = [".d"],
allow_empty = False,
doc = "dtrace(.d) source files to be compiled.",
),
}),
fragments = ["apple"],
doc = """
Compiles
[dtrace files with probes](https://www.ibm.com/developerworks/aix/library/au-dtraceprobes.html)
to generate header files to use those probes in C languages. The header files
generated will have the same name as the source files but with a `.h`
extension. Headers will be generated in a label scoped workspace relative file
structure. For example with a directory structure of
```
Workspace
foo/
bar.d
```
and a target named `dtrace_gen` the header path would be
`<GENFILES>/dtrace_gen/foo/bar.h`.
""",
)