Skip to content

Commit

Permalink
refactor(lib): share funcitonality
Browse files Browse the repository at this point in the history
  • Loading branch information
mgred committed Jul 22, 2024
1 parent e966140 commit c3580e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
10 changes: 2 additions & 8 deletions lib/private/formatter.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
"Formatter"

load("//toolchains:toolchains.bzl", "FD_TOOLCHAIN_TYPE", "GOAWK_TOOLCHAIN_TYPE")
load(":utils.bzl", "declare_launcher_file", "get_binary_from_toolchain")

def _get_target_file_path(target):
if DefaultInfo in target:
f = target[DefaultInfo].files.to_list().pop()
return f.short_path
fail("Cannot get file path")
load(":utils.bzl", "declare_launcher_file", "get_binary_from_toolchain", "get_target_file")

def _join_exclude_args(items):
return " ".join(["--exclude \\\"%s\\\"" % i for i in items])
Expand All @@ -21,7 +15,7 @@ def _parallel_run_impl(ctx):

args = ctx.actions.args()
for k, v in ctx.attr.tools.items():
args.add("%s:%s" % (v, _get_target_file_path(k)))
args.add("%s:%s" % (v, get_target_file(k).short_path))

ctx.actions.write(
output = args_file,
Expand Down
9 changes: 2 additions & 7 deletions lib/private/git_archive.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
"Create a tarball with `git archive`"

load("//toolchains:toolchains.bzl", "SHA_TOOLCHAIN_TYPE")
load(":utils.bzl", "declare_launcher_file", "get_binary_from_toolchain")

def _get_target_file_path(target):
if DefaultInfo in target:
return target[DefaultInfo].files.to_list().pop().path
fail("Cannot get file path")
load(":utils.bzl", "declare_launcher_file", "get_binary_from_toolchain", "get_target_file")

def _format_virtual_file_arg(target, path):
return """--add-virtual-file="$PREFIX/{path}":"$(< "{source}")" """.format(
path = path,
source = _get_target_file_path(target),
source = get_target_file(target).path,
)

def _git_archive_impl(ctx):
Expand Down
5 changes: 5 additions & 0 deletions lib/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
def declare_launcher_file(ctx):
return ctx.actions.declare_file("{}_/{}".format(ctx.label.name, ctx.label.name))

def get_target_file(target):
if DefaultInfo in target:
return target[DefaultInfo].files.to_list().pop()
fail("Cannot get file path")

def _get_binary_info_from_toolchain(ctx, toolchain):
if toolchain in ctx.toolchains and hasattr(ctx.toolchains[toolchain], "binary_info"):
return ctx.toolchains[toolchain].binary_info
Expand Down

0 comments on commit c3580e3

Please sign in to comment.