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

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

commit 3b5b2d66648d102d50aa7f7e25aa41cd0094b50b
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Mon Aug 26 09:58:45 2019 -0700

    Resolve transient packages before dep resolution
    
    This fixes #286.
    
    If a split image specifies a transient package as the loader, newt will
    fail to build it.
    
    For example, in this target:
    
        target.app: "@apache-mynewt-core/apps/splitty"
        target.bsp: "@apache-mynewt-core/hw/bsp/nordic_pca10040"
        target.build_profile: optimized
        target.loader: "@apache-mynewt-core/apps/bleprph"
    
    `@apache-mynewt-core/apps/bleprph` is a transient package; it links to
    `@apache-mynewt-nimble/apps/bleprph`.
    
    Newt reports the following error when asked to build this target:
    
        Error: Two app packages in build: apps/splitty, apps/bleprph
    
    The bug occurs when newt tries to partition the master set of packages
    among the loader and app.  In a split image, all loader packages are
    shared among both loader and app, so the app automatically pulls in all
    the packages in the loader *with one exception*: The loader's "app"
    package (confusing terminology) does not get pulled in.  The app has
    its own "app" package; it doesn't need the loader's "app" package.
    
    The problem was that newt couldn't identify the loader's "app" package
    if it was transient.  This package's type was "transient" (not "app"),
    so it got pulled in to the app.  Consequently, the app contained two
    "app" packages, resulting in the error.
    
    The fix is to resolve transient packages among seed packages before
    performing dependency resolution.  With this change, the loader's "app"
    package is identifiable when newt decides which packages get pulled in
    to the app.
---
 newt/builder/targetbuild.go | 19 +++++++++++++++++++
 newt/resolve/resolve.go     | 16 +++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index f388b49..07c9eaf 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -144,6 +144,18 @@ func (t *TargetBuilder) injectBuildSettings() {
        t.InjectSetting("TARGET_"+util.CIdentifier(tgtName), "1")
 }
 
+// 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) {
+       for i, lp := range lps {
+               resolved := t.target.ResolvePackageName(lp.FullName())
+               if resolved != lp {
+                       resolve.LogTransientWarning(lp)
+                       lps[i] = resolved
+               }
+       }
+}
+
 func (t *TargetBuilder) ensureResolved() error {
        if t.res != nil {
                return nil
@@ -152,6 +164,11 @@ func (t *TargetBuilder) ensureResolved() error {
        t.injectNewtSettings()
        t.injectBuildSettings()
 
+       // When populating seed lists, resolve transient packages as a separate
+       // step (i.e., fill the list with the "Yml()" version of each package, 
then
+       // call `resolveTransientPkgs` on the list).  This is done so that we 
can
+       // detect and warn the user if transient packages are being used.
+
        var loaderSeeds []*pkg.LocalPackage
        if t.loaderPkg != nil {
                loaderSeeds = []*pkg.LocalPackage{
@@ -160,6 +177,7 @@ func (t *TargetBuilder) ensureResolved() error {
                        t.compilerPkg,
                        t.target.Package(),
                }
+               t.resolveTransientPkgs(loaderSeeds)
 
                // For split images, inject the SPLIT_[...] settings into the
                // corresponding app packages.  This ensures that:
@@ -182,6 +200,7 @@ func (t *TargetBuilder) ensureResolved() error {
                t.compilerPkg,
                t.target.Package(),
        }
+       t.resolveTransientPkgs(appSeeds)
 
        if t.appPkg != nil {
                appSeeds = append(appSeeds, t.target.AppYml())
diff --git a/newt/resolve/resolve.go b/newt/resolve/resolve.go
index b9fcbed..07fa1de 100644
--- a/newt/resolve/resolve.go
+++ b/newt/resolve/resolve.go
@@ -1108,13 +1108,7 @@ func ResolveFull(
        // We have now resolved all packages so go through them and emit warning
        // when using link packages
        for _, rpkg := range res.MasterSet.Rpkgs {
-               if rpkg.Lpkg.Type() != pkg.PACKAGE_TYPE_TRANSIENT {
-                       continue
-               }
-
-               log.Warnf("Transient package %s used, update configuration "+
-                       "to use linked package instead (%s)",
-                       rpkg.Lpkg.FullName(), rpkg.Lpkg.LinkedName())
+               LogTransientWarning(rpkg.Lpkg)
        }
 
        // If there is no loader, then the set of all packages is just the app
@@ -1238,3 +1232,11 @@ func (res *Resolution) WarningText() string {
 func (res *Resolution) DeprecatedWarning() []string {
        return res.Cfg.DeprecatedWarning()
 }
+
+func LogTransientWarning(lpkg *pkg.LocalPackage) {
+       if lpkg.Type() == pkg.PACKAGE_TYPE_TRANSIENT {
+               log.Warnf("Transient package %s used, update configuration "+
+                       "to use linked package instead (%s)",
+                       lpkg.FullName(), lpkg.LinkedName())
+       }
+}

Reply via email to