You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/08/25 10:37:34 UTC

[GitHub] andrzej-kaczmarek closed pull request #202: Add new package type -> transient

andrzej-kaczmarek closed pull request #202: Add new package type -> transient
URL: https://github.com/apache/mynewt-newt/pull/202
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index 9f7818e0..1c2f8ba7 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -128,8 +128,8 @@ func (t *TargetBuilder) ensureResolved() error {
 	var loaderSeeds []*pkg.LocalPackage
 	if t.loaderPkg != nil {
 		loaderSeeds = []*pkg.LocalPackage{
-			t.loaderPkg,
-			t.bspPkg.LocalPackage,
+			t.target.LoaderYml(),
+			t.target.BspYml(),
 			t.compilerPkg,
 			t.target.Package(),
 		}
@@ -151,13 +151,13 @@ func (t *TargetBuilder) ensureResolved() error {
 	}
 
 	appSeeds := []*pkg.LocalPackage{
-		t.bspPkg.LocalPackage,
+		t.target.BspYml(),
 		t.compilerPkg,
 		t.target.Package(),
 	}
 
 	if t.appPkg != nil {
-		appSeeds = append(appSeeds, t.appPkg)
+		appSeeds = append(appSeeds, t.target.AppYml())
 	}
 
 	if t.testPkg != nil {
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 5a8d81fc..5cb02fa0 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -56,6 +56,7 @@ type LocalPackage struct {
 	name        string
 	basePath    string
 	packageType interfaces.PackageType
+	linkedName  string
 
 	// General information about the package
 	desc *PackageDesc
@@ -104,6 +105,10 @@ func (pkg *LocalPackage) FullName() string {
 	}
 }
 
+func (pkg *LocalPackage) LinkedName() string {
+	return pkg.linkedName
+}
+
 func (pkg *LocalPackage) BasePath() string {
 	return pkg.basePath
 }
@@ -316,6 +321,21 @@ func (pkg *LocalPackage) Load() error {
 		}
 	}
 
+	if pkg.packageType == PACKAGE_TYPE_TRANSIENT {
+		n := pkg.PkgY.GetValString("pkg.link", nil)
+		if len(n) == 0 {
+			return util.FmtNewtError(
+				"Transient package \"%s\" does not specify target "+
+					"package in its `pkg.yml` file (pkg.name=%s)",
+				pkg.basePath, pkg.name)
+		}
+
+		pkg.linkedName = n
+
+		// We don't really want anything else for this package
+		return nil
+	}
+
 	init := pkg.PkgY.GetValStringMapString("pkg.init", nil)
 	for name, stageStr := range init {
 		stage, err := strconv.ParseInt(stageStr, 10, 64)
diff --git a/newt/pkg/package.go b/newt/pkg/package.go
index 58bf5238..f4f6feb0 100644
--- a/newt/pkg/package.go
+++ b/newt/pkg/package.go
@@ -37,6 +37,7 @@ const (
 	PACKAGE_TYPE_SDK
 	PACKAGE_TYPE_GENERATED
 	PACKAGE_TYPE_LIB
+	PACKAGE_TYPE_TRANSIENT
 	PACKAGE_TYPE_BSP
 	PACKAGE_TYPE_UNITTEST
 	PACKAGE_TYPE_APP
@@ -49,6 +50,7 @@ var PackageTypeNames = map[interfaces.PackageType]string{
 	PACKAGE_TYPE_SDK:       "sdk",
 	PACKAGE_TYPE_GENERATED: "generated",
 	PACKAGE_TYPE_LIB:       "lib",
+	PACKAGE_TYPE_TRANSIENT: "transient",
 	PACKAGE_TYPE_BSP:       "bsp",
 	PACKAGE_TYPE_UNITTEST:  "unittest",
 	PACKAGE_TYPE_APP:       "app",
diff --git a/newt/resolve/resolve.go b/newt/resolve/resolve.go
index c58bdb4f..dcdb0a37 100644
--- a/newt/resolve/resolve.go
+++ b/newt/resolve/resolve.go
@@ -24,11 +24,14 @@ import (
 	"sort"
 	"strings"
 
+	log "github.com/Sirupsen/logrus"
+
 	"mynewt.apache.org/newt/newt/flash"
 	"mynewt.apache.org/newt/newt/pkg"
 	"mynewt.apache.org/newt/newt/project"
 	"mynewt.apache.org/newt/newt/syscfg"
 	"mynewt.apache.org/newt/util"
+	"mynewt.apache.org/newt/newt/ycfg"
 )
 
 // Represents a supplied API.
@@ -327,7 +330,13 @@ func (r *Resolver) loadDepsForPkg(rpkg *ResolvePackage) (bool, error) {
 
 	changed := false
 
-	depEntries := rpkg.Lpkg.PkgY.GetSlice("pkg.deps", settings)
+	var depEntries []ycfg.YCfgEntry
+
+	if rpkg.Lpkg.Type() == pkg.PACKAGE_TYPE_TRANSIENT {
+		depEntries = rpkg.Lpkg.PkgY.GetSlice("pkg.link", nil)
+	} else {
+		depEntries = rpkg.Lpkg.PkgY.GetSlice("pkg.deps", settings)
+	}
 	depender := rpkg.Lpkg.Name()
 
 	seen := make(map[*ResolvePackage]struct{}, len(rpkg.Deps))
@@ -644,6 +653,18 @@ func ResolveFull(
 
 	res.MasterSet.Rpkgs = r.rpkgSlice()
 
+	// 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())
+	}
+
 	// If there is no loader, then the set of all packages is just the app
 	// packages.  We already resolved the necessary dependency information when
 	// syscfg was calculated above.
diff --git a/newt/target/target.go b/newt/target/target.go
index bd9e53cb..0979854a 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -195,8 +195,8 @@ func (target *Target) Clone(newRepo *repo.Repo, newName string) *Target {
 	return &newTarget
 }
 
-func (target *Target) resolvePackageName(name string) *pkg.LocalPackage {
-	dep, err := pkg.NewDependency(target.basePkg.Repo(), name)
+func (target *Target) resolvePackageRepoAndName(repo *repo.Repo, name string) *pkg.LocalPackage {
+	dep, err := pkg.NewDependency(repo, name)
 	if err != nil {
 		return nil
 	}
@@ -209,6 +209,27 @@ func (target *Target) resolvePackageName(name string) *pkg.LocalPackage {
 	return pack
 }
 
+func (target *Target) resolvePackageName(name string) *pkg.LocalPackage {
+	pack := target.resolvePackageYmlName(name)
+
+	if pack == nil || pack.Type() != pkg.PACKAGE_TYPE_TRANSIENT {
+		return pack
+	}
+
+	// We follow only one level of linking here to make things easier and assuming
+	// nested linking means someone using really deprecated packages ;)
+
+	pack = target.resolvePackageRepoAndName(pack.Repo().(*repo.Repo), pack.LinkedName())
+
+	return pack
+}
+
+func (target *Target) resolvePackageYmlName(name string) *pkg.LocalPackage {
+	return target.resolvePackageRepoAndName(target.basePkg.Repo().(*repo.Repo), name)
+}
+
+// Methods below resolve package by name and follow links to get proper package
+
 func (target *Target) App() *pkg.LocalPackage {
 	return target.resolvePackageName(target.AppName)
 }
@@ -221,6 +242,21 @@ func (target *Target) Bsp() *pkg.LocalPackage {
 	return target.resolvePackageName(target.BspName)
 }
 
+// Methods below resolve package by name as stated in YML file (so do not follow links)
+// e.g. to use as seed for dependencies calculation
+
+func (target *Target) AppYml() *pkg.LocalPackage {
+	return target.resolvePackageYmlName(target.AppName)
+}
+
+func (target *Target) LoaderYml() *pkg.LocalPackage {
+	return target.resolvePackageYmlName(target.LoaderName)
+}
+
+func (target *Target) BspYml() *pkg.LocalPackage {
+	return target.resolvePackageYmlName(target.BspName)
+}
+
 // Save the target's configuration elements
 func (t *Target) Save() error {
 	if err := t.basePkg.Save(); err != nil {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services