Skip to content

Commit

Permalink
Merge the erlc_opts rule into the erlc_opts_file rule
Browse files Browse the repository at this point in the history
There was no need to have two rules
  • Loading branch information
HoloRin committed Jul 29, 2024
1 parent de2eb26 commit b9ccd94
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 58 deletions.
10 changes: 0 additions & 10 deletions erlang_bytecode2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ load(
"//private:erlang_bytecode2.bzl",
_erlang_bytecode = "erlang_bytecode",
)
load(
"//private:erlc_opts.bzl",
_ErlcOptsInfo = "ErlcOptsInfo",
_erlc_opts = "erlc_opts",
)

ErlcOptsInfo = _ErlcOptsInfo

def erlang_bytecode(
srcs = [],
Expand All @@ -33,9 +26,6 @@ def erlang_bytecode(
**kwargs
)

def erlc_opts(**kwargs):
_erlc_opts(**kwargs)

def _beam(p):
(_, _, basename) = p.rpartition("/")
return basename.removesuffix(".erl") + ".beam"
9 changes: 7 additions & 2 deletions erlc_opts_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ load(
_erlc_opts_file = "erlc_opts_file",
)

def erlc_opts_file(**kwargs):
_erlc_opts_file(**kwargs)
def erlc_opts_file(
out = "erlc_opts_file",
**kwargs):
_erlc_opts_file(
out = out,
**kwargs
)
29 changes: 10 additions & 19 deletions examples/basic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ load("@rules_erlang//:erlc_opts_file.bzl", "erlc_opts_file")
load("@rules_erlang//:eunit2.bzl", "eunit")
load("@rules_erlang//:shell.bzl", "shell")
load("@rules_erlang//:xref.bzl", "xref")
load("@rules_erlang//private:erlc_opts.bzl", "erlc_opts")
load("@rules_erlang//private:extract_app.bzl", "extract_app")

APP_NAME = "basic"
Expand All @@ -28,20 +27,18 @@ erlc_opts_file(
}),
)

TEST_ERLC_OPTS = [
"+debug_info",
"-DTEST=1",
] + select({
"@rules_erlang//:debug_build": [],
"//conditions:default": [
"+deterministic",
],
})

erlc_opts_file(
name = "test_erlc_opts",
out = "test_erlc_opts_file",
values = TEST_ERLC_OPTS,
values = [
"+debug_info",
"-DTEST=1",
] + select({
"@rules_erlang//:debug_build": [],
"//conditions:default": [
"+deterministic",
],
}),
)

erlang_app_sources(
Expand Down Expand Up @@ -105,12 +102,6 @@ dialyze(
plt = ":deps_plt",
)

erlc_opts(
name = "test_erlc_opts_",
testonly = True,
values = TEST_ERLC_OPTS,
)

erlang_bytecode(
name = "test_helpers",
testonly = True,
Expand All @@ -121,7 +112,7 @@ erlang_bytecode(
exclude = ["test/**/*_SUITE.erl"],
),
dest = "test",
erlc_opts = ":test_erlc_opts_",
erlc_opts = ":test_erlc_opts",
)

eunit(
Expand Down
2 changes: 1 addition & 1 deletion private/erlang_bytecode2.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("//:erlang_app_info.bzl", "ErlangAppInfo", "flat_deps")
load("//:util.bzl", "path_join")
load(":erlang_bytecode.bzl", "unique_dirnames")
load(":erlc_opts.bzl", "ErlcOptsInfo")
load(":erlc_opts_file.bzl", "ErlcOptsInfo")
load(":util.bzl", "erl_libs_contents")
load(
"//tools:erlang_toolchain.bzl",
Expand Down
19 changes: 0 additions & 19 deletions private/erlc_opts.bzl

This file was deleted.

16 changes: 15 additions & 1 deletion private/erlc_opts_file.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
ErlcOptsInfo = provider(
doc = "Reusable set of erlc options",
fields = {
"values": "Strings to be passed as additional options to erlc",
},
)

def _impl(ctx):
args = ctx.actions.args()
args.add_all(ctx.attr.values)
Expand All @@ -7,10 +14,17 @@ def _impl(ctx):
content = args,
)

return [
ErlcOptsInfo(values = ctx.attr.values),
]

erlc_opts_file = rule(
implementation = _impl,
attrs = {
"values": attr.string_list(),
"out": attr.output(),
"out": attr.output(
mandatory = True,
),
},
provides = [ErlcOptsInfo],
)
7 changes: 5 additions & 2 deletions tools/app_file_tool/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
load(
"//:erlang_bytecode2.bzl",
"erlang_bytecode",
"erlc_opts",
)
load(
"//:erlc_opts_file.bzl",
"erlc_opts_file",
)
load(
"//private:escript_flat.bzl",
Expand All @@ -12,7 +15,7 @@ load(
"DEFAULT_ERLC_OPTS",
)

erlc_opts(
erlc_opts_file(
name = "erlc_opts",
values = DEFAULT_ERLC_OPTS,
)
Expand Down
7 changes: 5 additions & 2 deletions tools/compile_first/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
load(
"//:erlang_bytecode2.bzl",
"erlang_bytecode",
"erlc_opts",
)
load(
"//:erlc_opts_file.bzl",
"erlc_opts_file",
)
load(
"//private:escript_flat.bzl",
Expand All @@ -12,7 +15,7 @@ load(
"DEFAULT_ERLC_OPTS",
)

erlc_opts(
erlc_opts_file(
name = "erlc_opts",
values = DEFAULT_ERLC_OPTS,
)
Expand Down
7 changes: 5 additions & 2 deletions tools/coverdata_to_lcov/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
load(
"//:erlang_bytecode2.bzl",
"erlang_bytecode",
"erlc_opts",
)
load(
"//:erlc_opts_file.bzl",
"erlc_opts_file",
)
load(
"//private:escript_flat.bzl",
Expand All @@ -12,7 +15,7 @@ load(
"DEFAULT_ERLC_OPTS",
)

erlc_opts(
erlc_opts_file(
name = "erlc_opts",
values = DEFAULT_ERLC_OPTS,
)
Expand Down

0 comments on commit b9ccd94

Please sign in to comment.