Skip to content

Commit 4dcbfc0

Browse files
author
Martin Kosiba
committed
fix: Relax exec_compatible_with requirement on dtrace rules.
1 parent 385c9e5 commit 4dcbfc0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

apple/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("//apple/internal/aspects:resource_aspect_hint.bzl", "apple_resource_hint", "apple_resource_hint_action")
33
load(":cc_toolchain_forwarder.bzl", "cc_toolchain_forwarder")
4+
load(":dtrace.bzl", "dtrace_wrapper")
45

56
package(default_visibility = ["//visibility:public"])
67

@@ -319,3 +320,10 @@ apple_resource_hint(
319320
name = "suppress_resources",
320321
action = apple_resource_hint_action.suppress,
321322
)
323+
324+
dtrace_wrapper(
325+
name = "dtrace_wrapper",
326+
target_compatible_with = [
327+
"@platforms//os:macos",
328+
],
329+
)

apple/dtrace.bzl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def _dtrace_compile_impl(ctx):
4141
output_hdrs = []
4242
include_dir = None
4343

44-
dtrace = "/usr/sbin/dtrace"
45-
if ctx.executable.dtrace:
46-
dtrace = ctx.executable.dtrace
44+
dtrace = ctx.executable.dtrace
4745

4846
for src in ctx.files.srcs:
4947
owner_relative_path = bundle_paths.owner_relative_path(src)
@@ -88,16 +86,14 @@ dtrace_compile = rule(
8886
mandatory = False,
8987
executable = True,
9088
cfg = "exec",
89+
default = "//apple:dtrace_wrapper",
9190
),
9291
"srcs": attr.label_list(
9392
allow_files = [".d"],
9493
allow_empty = False,
9594
doc = "dtrace(.d) source files to be compiled.",
9695
),
9796
}),
98-
exec_compatible_with = [
99-
"@platforms//os:macos",
100-
],
10197
fragments = ["apple"],
10298
doc = """
10399
Compiles
@@ -116,3 +112,15 @@ and a target named `dtrace_gen` the header path would be
116112
`<GENFILES>/dtrace_gen/foo/bar.h`.
117113
""",
118114
)
115+
116+
def _dtrace_wrapper_impl(ctx):
117+
dtrace_wrapper = ctx.actions.declare_file("%s.sh" % ctx.label.name)
118+
contents = """#!/bin/bash
119+
exec /usr/sbin/dtrace "$@"
120+
"""
121+
ctx.actions.write(dtrace_wrapper, contents, is_executable = True)
122+
return [DefaultInfo(files = depset([dtrace_wrapper]), executable = dtrace_wrapper)]
123+
124+
dtrace_wrapper = rule(
125+
implementation = _dtrace_wrapper_impl,
126+
)

0 commit comments

Comments
 (0)