Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
Don’t use relativize paths in internal modules
Browse files Browse the repository at this point in the history
This makes it possible to use cabal_paths with local projects.

Fixes #75.
  • Loading branch information
matthewbauer committed Feb 4, 2019
1 parent 2686e6d commit 5f0d7da
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions third_party/cabal2bazel/bzl/cabal_paths.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,31 @@ def _impl_path_module_gen(ctx):
base_dir = ctx.label.package + (
("/" + ctx.attr.data_dir) if ctx.attr.data_dir else "")

ctx.template_action(
# If workspace_root is not empty, we have an external repo.
# We need to relativize the paths.
if ctx.label.workspace_root != "":
ctx.template_action(
template=ctx.file._template,
output=paths_file,
substitutions={
"%{module}": ctx.attr.module,
"%{base_dir}": paths.join(
# TODO: this probably won't work for packages not in external
# repositories. See:
# https://github.com/bazelbuild/bazel/wiki/Updating-the-runfiles-tree-structure
"..", paths.relativize(ctx.label.workspace_root, "external"), base_dir),
"%{version}": str(ctx.attr.version),
"%{module}": ctx.attr.module,
"%{base_dir}": paths.join(
# https://github.com/bazelbuild/bazel/wiki/Updating-the-runfiles-tree-structure
"..", paths.relativize(ctx.label.workspace_root, "external"), base_dir),
"%{version}": str(ctx.attr.version),
},
)
)
else: # Otherwise this is a local directory, and we can use relative paths.
ctx.template_action(
template=ctx.file._template,
output=paths_file,
substitutions={
"%{module}": ctx.attr.module,
"%{base_dir}": base_dir,
"%{version}": str(ctx.attr.version),
},
)

return struct(files=depset([paths_file]))


Expand Down

0 comments on commit 5f0d7da

Please sign in to comment.