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

Introduce use_same_package_name #39

Open
wants to merge 1 commit into
base: mercury
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions decls/haskell_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ haskell_library = prelude_rule(
"linker_flags": attrs.list(attrs.arg(), default = []),
"platform": attrs.option(attrs.string(), default = None),
"platform_linker_flags": attrs.list(attrs.tuple(attrs.regex(), attrs.list(attrs.arg())), default = []),
"use_same_package_name": attrs.bool(default = False),

Choose a reason for hiding this comment

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

Maybe this could be an optional package_id attribute instead? The default behavior would still be the current behavior, i.e. equivalent with use_same_package_name = False, but then when package_id is set it's a bit more flexible and allows users direct control over the package id if needed. (For reference Bazel rules_haskell has something like this too.)

Also, to clarify. IIUC this actually directly influences -this-unit-id, correct? So, maybe the name package_id is more appropriate than package_name, or maybe it should directly be called unit_id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that sounds reasonable and with clearer semantics (name means many things). I will change this to optional explicit package-id. Thanks for suggestion!

}
),
)
Expand Down
8 changes: 6 additions & 2 deletions haskell/haskell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,12 @@ def haskell_library_impl(ctx: AnalysisContext) -> list[Provider]:
indexing_tsets = {}
sub_targets = {}

libname = repr(ctx.label.path).replace("//", "_").replace("/", "_") + "_" + ctx.label.name
pkgname = libname.replace("_", "-")
if(ctx.attrs.use_same_package_name):
libname = ctx.label.name
pkgname = libname
else:
libname = repr(ctx.label.path).replace("//", "_").replace("/", "_") + "_" + ctx.label.name
pkgname = libname.replace("_", "-")

md_file = target_metadata(
ctx,
Expand Down