Skip to content

Commit

Permalink
Install both default_runfiles and files_to_run (#25)
Browse files Browse the repository at this point in the history
Previously installer used only the FilesToRunProvider.executable
Now it also uses DefaultInfo.default_runfiles, which should make
filegroups behave as expected.
  • Loading branch information
bttk authored Apr 21, 2020
1 parent 48547be commit 830e6cd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
33 changes: 25 additions & 8 deletions installer/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ load("@bazel_skylib//lib:shell.bzl", "shell")
_INSTALLER_GEN_SUFFIX = "_gen"
_TEMPLATE_TARGET = "@com_github_google_rules_install//installer:installer_template"

def _install_files_depset(default_info):
direct = []
transitive = []
if default_info.default_runfiles:
transitive = [default_info.default_runfiles.files]
if default_info.files_to_run and default_info.files_to_run.executable:
direct = [default_info.files_to_run.executable]
if direct or transitive:
return depset(direct = direct, transitive = transitive)
return None

def _gen_install_binary_impl(ctx):
files = []
transitive_runfiles = []
sources = []
targets = []
for d in ctx.attr.data:
file = d[DefaultInfo].files_to_run.executable
files.append(file)
sources.append(file.short_path)
target = paths.join(ctx.attr.target_subdir, paths.basename(file.short_path))
targets.append(target)
for input in ctx.attr.data:
input_files = _install_files_depset(input[DefaultInfo])
if not input_files:
continue
transitive_runfiles.append(input_files)
for file in input_files.to_list():
sources.append(file.short_path)
target = paths.join(ctx.attr.target_subdir, paths.basename(file.short_path))
targets.append(target)

ctx.actions.expand_template(
output = ctx.outputs.out,
Expand All @@ -58,7 +72,10 @@ def _gen_install_binary_impl(ctx):

return [DefaultInfo(
executable = ctx.outputs.out,
runfiles = ctx.runfiles(files),
runfiles = ctx.runfiles(
files = [ctx.outputs.out],
transitive_files = depset(transitive = transitive_runfiles),
),
)]

def _compilation_mode_transition_impl(settings, attr):
Expand Down
42 changes: 42 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,45 @@ sh_test(
":multifile_installer_under_test",
],
)

installer(
name = "filegroup_installer_under_test",
data = [":test_filegroup"],
executable = False,
)

filegroup(
name = "test_filegroup",
data = [
"testdata/data.txt",
"testdata/subdir/subdir_data.txt",
],
)

sh_test(
name = "filegroup_installer_test_1",
srcs = ["installer_test.sh"],
args = [
"$(location :filegroup_installer_under_test)",
"$(location testdata/subdir/subdir_data.txt)",
"-executable=False",
],
data = [
"testdata/subdir/subdir_data.txt",
":filegroup_installer_under_test",
],
)

sh_test(
name = "filegroup_installer_test_2",
srcs = ["installer_test.sh"],
args = [
"$(location :filegroup_installer_under_test)",
"$(location testdata/data.txt)",
"-executable=False",
],
data = [
"testdata/data.txt",
":filegroup_installer_under_test",
],
)
2 changes: 1 addition & 1 deletion tests/installer_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ while (( "$#" > 2 )); do
declare -r SUBDIR="${3#-subdir=}"
;;
-executable=*)
# target_subdir attribute of installer rule
# executable attribute of installer rule
declare -r EXECUTABLE="${3#-executable=}"
;;
*)
Expand Down

0 comments on commit 830e6cd

Please sign in to comment.