Skip to content

Commit a31781e

Browse files
authored
Merge pull request #36 from rabbitmq/project-app-extra-keys
Handle PROJECT_APP_EXTRA_KEYS when auto-importing erlang.mk apps
2 parents 0c6db1c + 1f8d27a commit a31781e

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

app_file.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@ load("//private:app_file.bzl", "app_file_private")
22

33
_stamp_condition = str(Label("//private:private_stamp_detect"))
44

5-
def app_file(**kwargs):
5+
def app_file(
6+
app_extra_keys = [],
7+
app_extra = "",
8+
**kwargs):
9+
if len(app_extra_keys) > 0 and app_extra != "":
10+
all_app_extra = ",".join(app_extra_keys + [app_extra])
11+
elif len(app_extra_keys) > 0:
12+
all_app_extra = ",".join(app_extra_keys)
13+
else:
14+
all_app_extra = app_extra
15+
616
app_file_private(
717
private_stamp_detect = select({
818
_stamp_condition: True,
919
"//conditions:default": False,
1020
}),
21+
app_extra_keys = all_app_extra,
1122
**kwargs
1223
)

bzlmod/extensions.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ erlang_app(
367367
app_description = \"""$(PROJECT_DESCRIPTION)\""",
368368
app_version = "$(PROJECT_VERSION)",
369369
app_env = \"""$(PROJECT_ENV)\""",
370+
app_extra = \"""$(PROJECT_APP_EXTRA_KEYS)\""",
370371
extra_apps = [
371372
$(foreach dep,$(LOCAL_DEPS), "$(dep)",\n) ],
372373
erlc_opts = [

erlang_app.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def erlang_app(
3636
app_registered = [],
3737
app_env = "",
3838
app_extra_keys = [],
39+
app_extra = "",
3940
extra_apps = [],
4041
erlc_opts = DEFAULT_ERLC_OPTS,
4142
first_srcs = [],
@@ -80,6 +81,7 @@ def erlang_app(
8081
app_registered = app_registered,
8182
app_env = app_env,
8283
app_extra_keys = app_extra_keys,
84+
app_extra = app_extra,
8385
extra_apps = extra_apps,
8486
app_src = native.glob(["src/{}.app.src".format(app_name)]),
8587
modules = all_beam,
@@ -110,6 +112,7 @@ def test_erlang_app(
110112
app_registered = [],
111113
app_env = "",
112114
app_extra_keys = [],
115+
app_extra = "",
113116
extra_apps = [],
114117
erlc_opts = DEFAULT_TEST_ERLC_OPTS,
115118
first_srcs = [],

private/app_file.bzl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ def _impl(ctx):
3535
applications.append(dep[ErlangAppInfo].app_name)
3636
applications_list = "[" + ",".join(applications) + "]"
3737

38-
app_extra_keys_list = ""
39-
if len(ctx.attr.app_extra_keys) > 0:
40-
app_extra_keys_list = "[" + ",".join(ctx.attr.app_extra_keys) + "]"
41-
4238
stamp = ctx.attr.stamp == 1 or (ctx.attr.stamp == -1 and
4339
ctx.attr.private_stamp_detect)
4440

@@ -51,10 +47,9 @@ else
5147
fi
5248
5349
if [ -n '{description}' ]; then
54-
echo '"{description}".' | \\
55-
"{erlang_home}"/bin/escript {app_file_tool} \\
56-
description \\
57-
{out} > {out}.tmp && mv {out}.tmp {out}
50+
cat << 'EOF' | "{erlang_home}"/bin/escript {app_file_tool} description {out} > {out}.tmp && mv {out}.tmp {out}
51+
"{description}".
52+
EOF
5853
fi
5954
6055
# set the version env var from the stable-status.txt
@@ -108,9 +103,11 @@ if [ -n '{env}' ]; then
108103
EOF
109104
fi
110105
111-
if [ -n '{extra_tuples}' ]; then
106+
if [ -n '{extra_keys}' ]; then
112107
cat << 'EOF' | "{erlang_home}"/bin/escript {app_file_tool} {out} > {out}.tmp && mv {out}.tmp {out}
113-
{extra_tuples}.
108+
[
109+
{extra_keys}
110+
].
114111
EOF
115112
fi
116113
""".format(
@@ -126,7 +123,7 @@ fi
126123
applications = applications_list,
127124
app_module = app_module,
128125
env = ctx.attr.app_env,
129-
extra_tuples = app_extra_keys_list,
126+
extra_keys = ctx.attr.app_extra_keys,
130127
src = src,
131128
out = app_file.path,
132129
)
@@ -161,7 +158,7 @@ app_file_private = rule(
161158
"app_module": attr.string(),
162159
"app_registered": attr.string_list(),
163160
"app_env": attr.string(),
164-
"app_extra_keys": attr.string_list(),
161+
"app_extra_keys": attr.string(),
165162
"extra_apps": attr.string_list(),
166163
"app_src": attr.label_list(allow_files = [".app.src"]),
167164
"modules": attr.label_list(allow_files = [".beam"]),

0 commit comments

Comments
 (0)