This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit ea76f3b42df1fbbeaeea3935a1e9fb2b66abdba4
Author: Szymon Janc <[email protected]>
AuthorDate: Mon Oct 19 17:50:50 2026 +0200

    newt/builder: Fix crash for external target using local packages
    
    resolveTransientPkgs re-resolved each seed package by its full name
    relative to the target's repo. The full name of a local project package
    has no "@repo" prefix, so for a target located in an external repo
    that uses e.g. a BSP or compiler from the local project, the lookup
    failed and a nil package was put into the seed list. Resolving
    dependencies then crashed with a nil pointer dereference.
    
    The seed packages are already resolved, so only follow the link of
    transient packages, relative to the transient package's own repo, and
    report an error if the linked package does not exist.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/builder/targetbuild.go                        | 31 +++++++++++++++++-----
 newt/syscfg_stability_test.go                      | 17 ++++++++++++
 .../testdata/syscfg_stability/compiler/loc/pkg.yml | 22 +++++++++++++++
 newt/testdata/syscfg_stability/hw/bsp/loc/bsp.yml  | 28 +++++++++++++++++++
 newt/testdata/syscfg_stability/hw/bsp/loc/pkg.yml  | 22 +++++++++++++++
 .../repos/apache-mynewt-core/targets/ext/pkg.yml   | 22 +++++++++++++++
 .../apache-mynewt-core/targets/ext/target.yml      | 23 ++++++++++++++++
 7 files changed, 158 insertions(+), 7 deletions(-)

diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index e8937192..b68ddbeb 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -37,6 +37,7 @@ import (
        "mynewt.apache.org/newt/newt/interfaces"
        "mynewt.apache.org/newt/newt/pkg"
        "mynewt.apache.org/newt/newt/project"
+       "mynewt.apache.org/newt/newt/repo"
        "mynewt.apache.org/newt/newt/resolve"
        "mynewt.apache.org/newt/newt/symbol"
        "mynewt.apache.org/newt/newt/syscfg"
@@ -166,14 +167,26 @@ func (t *TargetBuilder) injectBuildSettings() {
 
 // resolveTransientPkgs replaces packages in a slice with the packages they
 // link to.  It has no effect on non-transient packages.
-func (t *TargetBuilder) resolveTransientPkgs(lps []*pkg.LocalPackage) {
+func (t *TargetBuilder) resolveTransientPkgs(lps []*pkg.LocalPackage) error {
        for i, lp := range lps {
-               resolved := t.target.ResolvePackageName(lp.FullName())
-               if resolved != lp {
-                       resolve.LogTransientWarning(lp)
-                       lps[i] = resolved
+               if lp.Type() != pkg.PACKAGE_TYPE_TRANSIENT {
+                       continue
                }
+
+               // The link is relative to the transient package's own repo.
+               resolved := t.target.ResolvePackageRepoAndName(
+                       lp.Repo().(*repo.Repo), lp.LinkedName())
+               if resolved == nil {
+                       return util.FmtNewtError(
+                               "transient package %s links to unknown package 
%s",
+                               lp.FullName(), lp.LinkedName())
+               }
+
+               resolve.LogTransientWarning(lp)
+               lps[i] = resolved
        }
+
+       return nil
 }
 
 func (t *TargetBuilder) ensureResolved(detectErr bool) error {
@@ -197,7 +210,9 @@ func (t *TargetBuilder) ensureResolved(detectErr bool) 
error {
                        t.compilerPkg,
                        t.target.Package(),
                }
-               t.resolveTransientPkgs(loaderSeeds)
+               if err := t.resolveTransientPkgs(loaderSeeds); err != nil {
+                       return err
+               }
 
                // For split images, inject the SPLIT_[...] settings into the
                // corresponding app packages.  This ensures that:
@@ -220,7 +235,9 @@ func (t *TargetBuilder) ensureResolved(detectErr bool) 
error {
                t.compilerPkg,
                t.target.Package(),
        }
-       t.resolveTransientPkgs(appSeeds)
+       if err := t.resolveTransientPkgs(appSeeds); err != nil {
+               return err
+       }
 
        if t.appPkg != nil {
                appSeeds = append(appSeeds, t.target.AppYml())
diff --git a/newt/syscfg_stability_test.go b/newt/syscfg_stability_test.go
index 5b03e6e7..59f5e57b 100644
--- a/newt/syscfg_stability_test.go
+++ b/newt/syscfg_stability_test.go
@@ -69,3 +69,20 @@ func TestSyscfgStabilityCmdlineDeprecated(t *testing.T) {
                }
        }
 }
+
+// A target inside an external repo can use a BSP and compiler from the
+// local project.
+func TestSyscfgStabilityExtRepoTarget(t *testing.T) {
+       out, err := newtCombinedOutput(syscfgStabilityDir, nil, "target", "dep",
+               "@apache-mynewt-core/targets/ext")
+       syscfgStabilityCheckNoPanic(t, out)
+       if err != nil {
+               t.Fatalf("newt target dep failed: %s\n%s", err, out)
+       }
+
+       for _, p := range []string{"hw/bsp/loc", "compiler/loc"} {
+               if !strings.Contains(out, "* "+p+" -->") {
+                       t.Errorf("missing package %s in dependency graph\n%s", 
p, out)
+               }
+       }
+}
diff --git a/newt/testdata/syscfg_stability/compiler/loc/pkg.yml 
b/newt/testdata/syscfg_stability/compiler/loc/pkg.yml
new file mode 100644
index 00000000..e174d605
--- /dev/null
+++ b/newt/testdata/syscfg_stability/compiler/loc/pkg.yml
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+pkg.name: compiler/loc
+pkg.type: compiler
diff --git a/newt/testdata/syscfg_stability/hw/bsp/loc/bsp.yml 
b/newt/testdata/syscfg_stability/hw/bsp/loc/bsp.yml
new file mode 100644
index 00000000..7d7dafc3
--- /dev/null
+++ b/newt/testdata/syscfg_stability/hw/bsp/loc/bsp.yml
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+bsp.arch: sim
+bsp.compiler: "@syscfg_stability/compiler/loc"
+bsp.flash_map:
+    areas:
+        FLASH_AREA_IMAGE_0:
+            device: 0
+            offset: 0x00000000
+            size: 64kB
diff --git a/newt/testdata/syscfg_stability/hw/bsp/loc/pkg.yml 
b/newt/testdata/syscfg_stability/hw/bsp/loc/pkg.yml
new file mode 100644
index 00000000..a1516526
--- /dev/null
+++ b/newt/testdata/syscfg_stability/hw/bsp/loc/pkg.yml
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+pkg.name: hw/bsp/loc
+pkg.type: bsp
diff --git 
a/newt/testdata/syscfg_stability/repos/apache-mynewt-core/targets/ext/pkg.yml 
b/newt/testdata/syscfg_stability/repos/apache-mynewt-core/targets/ext/pkg.yml
new file mode 100644
index 00000000..ad244bbe
--- /dev/null
+++ 
b/newt/testdata/syscfg_stability/repos/apache-mynewt-core/targets/ext/pkg.yml
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+pkg.name: targets/ext
+pkg.type: target
diff --git 
a/newt/testdata/syscfg_stability/repos/apache-mynewt-core/targets/ext/target.yml
 
b/newt/testdata/syscfg_stability/repos/apache-mynewt-core/targets/ext/target.yml
new file mode 100644
index 00000000..58460d33
--- /dev/null
+++ 
b/newt/testdata/syscfg_stability/repos/apache-mynewt-core/targets/ext/target.yml
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+target.app: "@syscfg_stability/apps/app"
+target.bsp: "@syscfg_stability/hw/bsp/loc"
+target.build_profile: default

Reply via email to