-
Notifications
You must be signed in to change notification settings - Fork 11
/
erlang_autodetect.bzl
55 lines (52 loc) · 1.72 KB
/
erlang_autodetect.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
load(
"@rules_erlang//compat:erlang_mk.bzl",
"app_src_from_erlang_mk_makefile",
"erlc_opts_from_erlang_mk_makefile",
)
load("@rules_erlang//compat:rebar.bzl", "erlc_opts_from_rebar_config")
load("@rules_erlang//:erlc_opts_file.bzl", "erlc_opts_file")
load("@rules_erlang//:erlang_app_sources.bzl", "erlang_app_sources")
def erlang_autodetect(name = None, testonly = False):
app_src = None
app_src_paths = native.glob(["src/%s.app.src" % name])
if len(app_src_paths) == 1:
app_src = app_src_paths[0]
if len(native.glob(["Makefile", "erlang.mk"])) == 2:
erlc_opts_from_erlang_mk_makefile(
name = "erlc_opts_file",
srcs = native.glob([
"**/*",
]),
out = "erlc_opts",
)
if app_src == None:
app_src_from_erlang_mk_makefile(
name = "app_src",
srcs = native.glob([
"**/*",
]),
out = "src/%s.app.src" % name,
)
app_src = ":app_src"
elif len(native.glob(["rebar.config"])) == 1:
erlc_opts_from_rebar_config(
name = "erlc_opts_file",
out = "erlc_opts",
)
else:
erlc_opts_file(
name = "erlc_opts_file",
values = select({
"@rules_erlang//:debug_build": ["+debug_info"],
"//conditions:default": ["+deterministic", "+debug_info"],
}),
out = "erlc_opts",
)
erlang_app_sources(
name = "srcs",
app_name = name,
app_src = app_src,
erlc_opts_file = ":erlc_opts_file",
testonly = testonly,
visibility = ["//visibility:public"],
)