Skip to content

Commit 883ea21

Browse files
authored
Merge pull request #101 from rabbitmq/support-self-includes
Support for self-referencing `-include_lib` directives
2 parents 58d82bf + 2194a8f commit 883ea21

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

erlang_app.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def erlang_app(
6262

6363
erlang_bytecode(
6464
name = "beam_files",
65+
app_name = app_name,
6566
hdrs = hdrs,
6667
srcs = srcs,
6768
erlc_opts = erlc_opts,
@@ -143,6 +144,7 @@ def test_erlang_app(
143144

144145
erlang_bytecode(
145146
name = "test_beam_files",
147+
app_name = app_name,
146148
hdrs = hdrs,
147149
srcs = srcs,
148150
erlc_opts = erlc_opts,

private/erlang_bytecode.bzl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ def _dirname(path):
2525
def _impl(ctx):
2626
erl_libs_dir = ctx.label.name + "_deps"
2727

28+
target = None
29+
if ctx.attr.app_name != "":
30+
target = ErlangAppInfo(
31+
app_name = ctx.attr.app_name,
32+
include = ctx.files.hdrs,
33+
)
34+
2835
erl_libs_files = erl_libs_contents(
2936
ctx,
37+
target_info = target,
3038
transitive = False,
3139
headers = True,
3240
dir = erl_libs_dir,
@@ -49,6 +57,8 @@ def _impl(ctx):
4957
dest_dir = beam_files[0].dirname
5058

5159
include_args = []
60+
if erl_libs_path != "":
61+
include_args.extend(["-I", erl_libs_path])
5262
for dir in unique_dirnames(ctx.files.hdrs):
5363
include_args.extend(["-I", dir])
5464

@@ -86,14 +96,17 @@ fi
8696
8797
if [ -n "$FIRST" ]; then
8898
"{erlang_home}"/bin/erlc \\
89-
-v {include_args} {pa_args} -o {out_dir} {erlc_opts} \\
99+
-v {include_args} {pa_args} \\
100+
-o {out_dir} {erlc_opts} \\
90101
$FIRST
91102
"{erlang_home}"/bin/erlc \\
92-
-v {include_args} {pa_args} -pa {out_dir} -o {out_dir} {erlc_opts} \\
103+
-v {include_args} {pa_args} -pa {out_dir} \\
104+
-o {out_dir} {erlc_opts} \\
93105
$@
94106
else
95107
"{erlang_home}"/bin/erlc \\
96-
-v {include_args} {pa_args} -o {out_dir} {erlc_opts} \\
108+
-v {include_args} {pa_args} \\
109+
-o {out_dir} {erlc_opts} \\
97110
$@
98111
fi
99112
""".format(
@@ -136,6 +149,7 @@ erlang_bytecode = rule(
136149
# rule.
137150
cfg = "target",
138151
),
152+
"app_name": attr.string(),
139153
"hdrs": attr.label_list(
140154
allow_files = [".hrl"],
141155
),

private/util.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ def additional_file_dest_relative_path(dep_label, f):
2121
else:
2222
return f.short_path
2323

24-
def erl_libs_contents2(ctx, deps = [], headers = False, dir = _DEFAULT_ERL_LIBS_DIR):
24+
def erl_libs_contents2(ctx, target_info = None, deps = [], headers = False, dir = _DEFAULT_ERL_LIBS_DIR):
2525
erl_libs_files = []
26+
if headers and target_info != None:
27+
dep_path = path_join(dir, target_info.app_name)
28+
for hdr in target_info.include:
29+
dest = ctx.actions.declare_file(path_join(dep_path, hdr.path))
30+
ctx.actions.symlink(output = dest, target_file = hdr)
31+
erl_libs_files.append(dest)
2632
for dep in deps:
2733
lib_info = dep[ErlangAppInfo]
2834
dep_path = path_join(dir, lib_info.app_name)

0 commit comments

Comments
 (0)