Skip to content

Instantly share code, notes, and snippets.

@fmeum
Created October 14, 2021 08:29
Show Gist options
  • Save fmeum/6cd871384277dedf8359e9db05e3dcef to your computer and use it in GitHub Desktop.
Save fmeum/6cd871384277dedf8359e9db05e3dcef to your computer and use it in GitHub Desktop.
Starlark debug macro
def _stringify_provider(p):
if type(p) == "DefaultInfo":
return """
{}
data_runfiles:
{}
default_runfiles:
{}
files:
{}
files_to_run:
executable:
{}
runfiles_manifest:
{}
""".format(
type(p),
p.data_runfiles.files.to_list(),
p.default_runfiles.files.to_list(),
p.files.to_list(),
p.files_to_run.executable,
p.files_to_run.runfiles_manifest,
)
elif type(p) == "CcInfo":
return """
{}
compilation_context
{}
linking_context
{}
""".format(
type(p),
str(p.compilation_context),
str(p.linking_context),
)
KNOWN_PROVIDERS = [DefaultInfo, CcInfo]
def _debug_impl(ctx):
to_print = ""
providers = [p for p in KNOWN_PROVIDERS if p in ctx.attr.target]
for p in providers:
to_print += _stringify_provider(ctx.attr.target[p])
print(to_print)
_debug = rule(
implementation = _debug_impl,
attrs = {
"target": attr.label(mandatory = True),
},
)
def debug(target):
_debug(
name = "%s_debug" % target,
target = target,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment