Skip to content

Commit 80cccce

Browse files
committed
Fix module merging when combining manifests
Dedup and override modules
1 parent 1aba408 commit 80cccce

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

cli/manifest_parser/manifest_parser.go

+44-16
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,24 @@ func ReadManifestFinal(
183183
return nil, nil, errors.Annotatef(err, "while expanding description")
184184
}
185185

186-
manifest.Modules = append(manifest.Modules, build.SWModule{
187-
Name: build.MosModuleName,
188-
Location: build.MosDefaultRepo,
189-
Version: manifest.MongooseOsVersion,
190-
})
186+
var mosModule *build.SWModule
187+
for i, m := range manifest.Modules {
188+
if m.Name == build.MosModuleName {
189+
mosModule = &manifest.Modules[i]
190+
break
191+
}
192+
}
193+
if mosModule == nil {
194+
manifest.Modules = append(manifest.Modules, build.SWModule{
195+
Name: build.MosModuleName,
196+
Location: build.MosDefaultRepo,
197+
Version: manifest.MongooseOsVersion,
198+
})
199+
} else {
200+
if mosModule.Version == "" {
201+
mosModule.Version = manifest.MongooseOsVersion
202+
}
203+
}
191204

192205
// Prepare local copies of all sw modules {{{
193206
// Modules are collected from the bottom of the dependency chain,
@@ -786,21 +799,20 @@ func readManifestWithLibs2(dir string, pc *manifestParseContext) (*build.FWAppMa
786799
}
787800

788801
func prepareLibs(parentNodeName string, manifest *build.FWAppManifest, pc *manifestParseContext) (time.Time, error) {
789-
wg := &sync.WaitGroup{}
802+
var wg sync.WaitGroup
790803
wg.Add(len(manifest.Libs))
791804

792-
lpres := make(chan libPrepareResult)
793-
794-
for i := range manifest.Libs {
795-
go prepareLib(parentNodeName, &manifest.Libs[i], manifest, pc, lpres, wg)
796-
}
797-
805+
lpres := make(chan libPrepareResult, 1000)
798806
// Closer goroutine
799807
go func() {
800808
wg.Wait()
801809
close(lpres)
802810
}()
803811

812+
for i := range manifest.Libs {
813+
go prepareLib(parentNodeName, &manifest.Libs[i], manifest, pc, lpres, &wg)
814+
}
815+
804816
// Handle all lib prepare results
805817
var mtime time.Time
806818
for res := range lpres {
@@ -966,8 +978,10 @@ func prepareLib(
966978
)
967979

968980
pc.mtx.Lock()
969-
if pc.libsHandled[name] != nil {
981+
lh := pc.libsHandled[name]
982+
if lh != nil {
970983
pc.mtx.Unlock()
984+
ls.Lib = &lh.Lib
971985
prepareLibReencounter(parentNodeName, manifest, pc,
972986
&pc.libsHandled[name].Lib, m)
973987
return
@@ -989,7 +1003,7 @@ func prepareLib(
9891003
manifest.BuildVars[haveName] = "1"
9901004
manifest.CDefs[haveName] = "1"
9911005

992-
lh := &build.FWAppManifestLibHandled{
1006+
lh = &build.FWAppManifestLibHandled{
9931007
Lib: *m,
9941008
Path: libLocalDir,
9951009
Deps: pc.deps.GetDeps(name),
@@ -1541,8 +1555,22 @@ func extendManifest(
15411555
prependPaths(m2.BinaryLibs, m2Dir)...,
15421556
)
15431557

1544-
// Add modules and libs from lib
1545-
mMain.Modules = append(m1.Modules, m2.Modules...)
1558+
// Add modules from the lib, dedup and override if necessary.
1559+
mm := make(map[string]build.SWModule)
1560+
for _, m := range append(m1.Modules, m2.Modules...) {
1561+
// Module must already be normalized at this point.
1562+
if m.Name == "" {
1563+
return fmt.Errorf("module not normalized! %+v", m)
1564+
}
1565+
mm[m.Name] = m
1566+
}
1567+
mMain.Modules = nil
1568+
for _, m := range mm {
1569+
mMain.Modules = append(mMain.Modules, m)
1570+
}
1571+
sort.Slice(mMain.Modules, func(i, j int) bool { return mMain.Modules[i].Name < mMain.Modules[j].Name })
1572+
1573+
// Add modules libs from the lib.
15461574
mMain.Libs = append(m1.Libs, m2.Libs...)
15471575
mMain.ConfigSchema = append(m1.ConfigSchema, m2.ConfigSchema...)
15481576
mMain.CFlags = append(m1.CFlags, m2.CFlags...)

0 commit comments

Comments
 (0)