Skip to content

Commit

Permalink
newt: Fix autogenerated linker script usage
Browse files Browse the repository at this point in the history
PreNewtError instead of NewNewtError was causing crashes. Also
"autogenerated" key should be handled when there is only one
value ("autogenerated") inside the vals slice.
  • Loading branch information
m-gorecki authored and sjanc committed Feb 15, 2024
1 parent 07e635e commit 121ecde
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions newt/pkg/bsp_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 121ecde

Please sign in to comment.