Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve symlink and refactor #27

Merged
merged 5 commits into from
Sep 3, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _nixpkgs_package_impl(ctx):
"-A", ctx.attr.attribute_path
if ctx.attr.nix_file or ctx.attr.nix_file_content
else ctx.attr.attribute_path or ctx.attr.name,
"--no-out-link",
])

# If neither repository or path are set, leave empty which will use
Expand All @@ -75,10 +76,10 @@ def _nixpkgs_package_impl(ctx):
elif not (ctx.attr.nix_file or ctx.attr.nix_file_content):
fail(strFailureImplicitNixpkgs)

nix_build_path = ctx.which("nix-build")
if nix_build_path == None:
fail("Could not find nix-build on the path. Please install it. See: https://nixos.org/nix/")

nix_build_path = _executable_path(
"nix-build", ctx,
extra_msg = "See: https://nixos.org/nix/"
)
nix_build = [nix_build_path] + expr_args

# Large enough integer that Bazel can still parse. We don't have
Expand All @@ -98,11 +99,9 @@ def _nixpkgs_package_impl(ctx):
# Build a forest of symlinks (like new_local_package() does) to the
# Nix store.

find_path = ctx.which("find")
if find_path == None:
fail("Could not find the 'find' command. Please ensure it is in your PATH.")
find_path = _executable_path("find", ctx)

res = ctx.execute(["find", output_path, "-maxdepth", "1"])
res = ctx.execute([find_path, output_path, "-maxdepth", "1"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually fixes a bug in some situations, find_path should have been used here all along.

if res.return_code == 0:
for i in res.stdout.splitlines():
basename = i.rpartition("/")[-1]
Expand All @@ -124,3 +123,12 @@ nixpkgs_package = repository_rule(
},
local = True,
)


def _executable_path(exe_name, rep_ctx, extra_msg=""):
"""Try to find the executable, fail with an error."""
path = rep_ctx.which(exe_name)
if path == None:
fail("Could not find the `{}` executable in PATH.{}\n"
.format(exe_name, " " + extra_msg if extra_msg else ""))
return path