From 121ecdec770b0aa2880bdd248c60ce7c591471e2 Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Tue, 13 Feb 2024 16:31:20 +0100 Subject: [PATCH] newt: Fix autogenerated linker script usage PreNewtError instead of NewNewtError was causing crashes. Also "autogenerated" key should be handled when there is only one value ("autogenerated") inside the vals slice. --- newt/pkg/bsp_package.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/newt/pkg/bsp_package.go b/newt/pkg/bsp_package.go index 54b0aaed2..39e466695 100644 --- a/newt/pkg/bsp_package.go +++ b/newt/pkg/bsp_package.go @@ -113,15 +113,7 @@ func (bsp *BspPackage) resolveLinkerScriptSetting( return nil, err } - if path == "autogenerated" { - path, err = bsp.getAutogeneratedLinkerScriptPath() - if err != nil { - return nil, util.PreNewtError(err, - "Could not resolve autogenerated linker script path for target \"%s\"", - bsp.yov.Pkg.Name()) - } - paths = append(paths, path) - } else if path != "" { + if path != "" { paths = append(paths, path) } } else { @@ -130,9 +122,19 @@ func (bsp *BspPackage) resolveLinkerScriptSetting( // Read each linker script from the list. for _, val := range vals { if val == "autogenerated" { - return nil, util.PreNewtError(err, - "Both autogenerated and custom linker scripts cannot be used."+ + if len(vals) > 1 { + return nil, util.NewNewtError("Both autogenerated and custom linker scripts cannot be used. " + "Newt handles either autogenerated linker script or a list of custom linker scripts.") + } else { + path, err := bsp.getAutogeneratedLinkerScriptPath() + if err != nil { + return nil, util.PreNewtError(err, + "Could not resolve autogenerated linker script path for target \"%s\"", + bsp.yov.Pkg.Name()) + } + paths = append(paths, path) + continue + } } path, err := proj.ResolvePath(ypkg.Repo().Path(), val)