Skip to content

Commit 3e529ee

Browse files
authored
Merge pull request #157 from rabbitmq/extra-apps-does-not-contain-deps
gazelle: erlang_app extra_apps will no longer contain deps
2 parents 038c3be + 61a62c8 commit 3e529ee

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

gazelle/erlang_app.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,11 @@ func (erlangApp *ErlangApp) ErlangAppRule(args language.GenerateArgs, explicitFi
673673
if erlangApp.Description != "" {
674674
r.SetAttr("app_description", erlangApp.Description)
675675
}
676-
if !erlangApp.ExtraApps.IsEmpty() {
677-
r.SetAttr("extra_apps", erlangApp.ExtraApps.Values(strings.Compare))
676+
extraApps := erlangApp.ExtraApps.Clone()
677+
extraApps.Subtract(erlangConfig.ExcludedDeps)
678+
extraApps.Subtract(erlangApp.Deps)
679+
if !extraApps.IsEmpty() {
680+
r.SetAttr("extra_apps", extraApps.Values(strings.Compare))
678681
}
679682

680683
r.SetAttr("beam_files", []string{":beam_files"})
@@ -692,6 +695,7 @@ func (erlangApp *ErlangApp) ErlangAppRule(args language.GenerateArgs, explicitFi
692695
if !deps.IsEmpty() {
693696
r.SetAttr("deps", deps.Values(strings.Compare))
694697
}
698+
695699
return r
696700
}
697701

@@ -706,8 +710,11 @@ func (erlangApp *ErlangApp) testErlangAppRule(args language.GenerateArgs, explic
706710
if erlangApp.Description != "" {
707711
r.SetAttr("app_description", erlangApp.Description)
708712
}
709-
if !erlangApp.ExtraApps.IsEmpty() {
710-
r.SetAttr("extra_apps", erlangApp.ExtraApps.Values(strings.Compare))
713+
extraApps := erlangApp.ExtraApps.Clone()
714+
extraApps.Subtract(erlangConfig.ExcludedDeps)
715+
extraApps.Subtract(erlangApp.Deps)
716+
if !extraApps.IsEmpty() {
717+
r.SetAttr("extra_apps", extraApps.Values(strings.Compare))
711718
}
712719

713720
r.SetAttr("beam_files", []string{":test_beam_files"})
@@ -725,6 +732,7 @@ func (erlangApp *ErlangApp) testErlangAppRule(args language.GenerateArgs, explic
725732
if !deps.IsEmpty() {
726733
r.SetAttr("deps", deps.Values(strings.Compare))
727734
}
735+
728736
return r
729737
}
730738

test/gazelle/erlang_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,56 @@ var _ = Describe("an ErlangApp", func() {
102102
})
103103
})
104104

105+
Describe("ErlangAppRule", func() {
106+
var fakeParser erlang.ErlParser
107+
108+
BeforeEach(func() {
109+
app.AddFile("src/foo.erl")
110+
111+
fakeParser = fakeErlParser(map[string]*erlang.ErlAttrs{
112+
"src/foo.erl": &erlang.ErlAttrs{
113+
Call: map[string][]string{
114+
"bar_lib": []string{"make_test_thing"},
115+
},
116+
},
117+
})
118+
119+
erlangConfigs := args.Config.Exts["erlang"].(erlang.ErlangConfigs)
120+
erlangConfig := erlangConfigs[args.Rel]
121+
erlangConfig.ModuleMappings["bar_lib"] = "bar_lib"
122+
erlangConfig.ExcludedDeps.Add("other_lib")
123+
})
124+
125+
It("Does not contain extra_apps that are deps", func() {
126+
// ExtraApps might be populated by the parsing of a
127+
// precompiled .app file in the ebin dir
128+
app.ExtraApps.Add("bar_lib")
129+
130+
app.BeamFilesRules(args, fakeParser)
131+
r := app.ErlangAppRule(args, false)
132+
133+
Expect(r.Name()).To(Equal("erlang_app"))
134+
Expect(r.AttrStrings("extra_apps")).ToNot(
135+
ContainElement("bar_lib"),
136+
)
137+
Expect(r.AttrStrings("deps")).To(
138+
ContainElement("bar_lib"),
139+
)
140+
})
141+
142+
It("Does not contain extra_apps that are excluded", func() {
143+
app.ExtraApps.Add("other_lib")
144+
145+
app.BeamFilesRules(args, fakeParser)
146+
r := app.ErlangAppRule(args, false)
147+
148+
Expect(r.Name()).To(Equal("erlang_app"))
149+
Expect(r.AttrStrings("extra_apps")).ToNot(
150+
ContainElement("other_lib"),
151+
)
152+
})
153+
})
154+
105155
Describe("BeamFilesRules", func() {
106156
BeforeEach(func() {
107157
app.AddFile("src/foo.erl")

0 commit comments

Comments
 (0)