mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject incubator-mynewt-newt git commit: Allow BSP to specify repository-relative paths
Date Sat, 05 Nov 2016 01:26:25 GMT
Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 0fa789525 -> 9dbb073c4


Allow BSP to specify repository-relative paths

This affects the following BSP settings:
    * bsp.linkerscript
    * bsp.part2linkerscript
    * bsp.downloadscript
    * bsp.debugscript


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/9dbb073c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/9dbb073c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/9dbb073c

Branch: refs/heads/develop
Commit: 9dbb073c4ffda7946ac4ef7f59d12ecc7b55e044
Parents: 0fa7895
Author: Christopher Collins <ccollins@apache.org>
Authored: Fri Nov 4 17:56:44 2016 -0700
Committer: Christopher Collins <ccollins@apache.org>
Committed: Fri Nov 4 17:56:44 2016 -0700

----------------------------------------------------------------------
 newt/builder/build.go         |  2 +-
 newt/builder/load.go          | 12 +++++-----
 newt/interfaces/interfaces.go |  1 +
 newt/pkg/bsp_package.go       | 45 ++++++++++++++++++++++++++++++++------
 newt/project/project.go       | 23 ++++++++++++++++++-
 5 files changed, 67 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9dbb073c/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 6e2f9b5..abdba35 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -328,7 +328,7 @@ func (b *Builder) link(elfName string, linkerScript string,
 	}
 
 	if linkerScript != "" {
-		c.LinkerScript = b.bspPkg.BasePath() + "/" + linkerScript
+		c.LinkerScript = linkerScript
 	}
 	err = c.CompileElf(elfName, pkgNames, keepSymbols, b.linkElf)
 	if err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9dbb073c/newt/builder/load.go
----------------------------------------------------------------------
diff --git a/newt/builder/load.go b/newt/builder/load.go
index 46cb506..ec07f1f 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -22,7 +22,6 @@ package builder
 import (
 	"fmt"
 	"os"
-	"path/filepath"
 	"sort"
 	"strconv"
 
@@ -59,7 +58,6 @@ func Load(binBaseName string, bspPkg *pkg.BspPackage,
 	}
 
 	bspPath := bspPkg.BasePath()
-	downloadScript := filepath.Join(bspPath, bspPkg.DownloadScript)
 
 	sortedKeys := make([]string, 0, len(extraEnvSettings))
 	for k, _ := range extraEnvSettings {
@@ -79,8 +77,8 @@ func Load(binBaseName string, bspPkg *pkg.BspPackage,
 
 	// bspPath, binBaseName are passed in command line for backwards
 	// compatibility
-	downloadCmd := fmt.Sprintf("%s %s %s %s", envSettings, downloadScript,
-		bspPath, binBaseName)
+	downloadCmd := fmt.Sprintf("%s %s %s %s", envSettings,
+		bspPkg.DownloadScript, bspPath, binBaseName)
 
 	util.StatusMessage(util.VERBOSITY_VERBOSE, "Load command: %s\n",
 		downloadCmd)
@@ -198,13 +196,13 @@ func (b *Builder) Debug(extraJtagCmd string, reset bool, noGDB bool)
error {
 		envSettings = append(envSettings, fmt.Sprintf("NO_GDB=1"))
 	}
 
-	debugScript := filepath.Join(bspPath, b.targetBuilder.bspPkg.DebugScript)
-
 	os.Chdir(project.GetProject().Path())
 
 	// bspPath, binBaseName are passed in command line for backwards
 	// compatibility
-	cmdLine := []string{debugScript, bspPath, binBaseName}
+	cmdLine := []string{
+		b.targetBuilder.bspPkg.DebugScript, bspPath, binBaseName,
+	}
 
 	fmt.Printf("%s\n", cmdLine)
 	return util.ShellInteractiveCommand(cmdLine, envSettings)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9dbb073c/newt/interfaces/interfaces.go
----------------------------------------------------------------------
diff --git a/newt/interfaces/interfaces.go b/newt/interfaces/interfaces.go
index 5bafdf7..602c8bb 100644
--- a/newt/interfaces/interfaces.go
+++ b/newt/interfaces/interfaces.go
@@ -60,6 +60,7 @@ type ProjectInterface interface {
 	Name() string
 	Path() string
 	ResolveDependency(dep DependencyInterface) PackageInterface
+	ResolvePath(basePath string, name string) (string, error)
 	PackageList() PackageList
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9dbb073c/newt/pkg/bsp_package.go
----------------------------------------------------------------------
diff --git a/newt/pkg/bsp_package.go b/newt/pkg/bsp_package.go
index a57a31a..d89149b 100644
--- a/newt/pkg/bsp_package.go
+++ b/newt/pkg/bsp_package.go
@@ -23,6 +23,7 @@ import (
 	"strings"
 
 	"mynewt.apache.org/newt/newt/flash"
+	"mynewt.apache.org/newt/newt/interfaces"
 	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/util"
 	"mynewt.apache.org/newt/viper"
@@ -38,13 +39,28 @@ type BspPackage struct {
 	Part2LinkerScript string /* script to link app to second partition */
 	DownloadScript    string
 	DebugScript       string
-	WriteScript       string
 	FlashMap          flash.FlashMap
 	BspV              *viper.Viper
 }
 
+func (bsp *BspPackage) resolvePathSetting(
+	features map[string]bool, key string) (string, error) {
+
+	outVal := newtutil.GetStringFeatures(bsp.BspV, features, key)
+
+	proj := interfaces.GetProject()
+	path, err := proj.ResolvePath(bsp.BasePath(), outVal)
+	if err != nil {
+		return "", util.PreNewtError(err,
+			"BSP \"%s\" specifies invalid %s setting",
+			bsp.Name(), key)
+	}
+	return path, nil
+}
+
 func (bsp *BspPackage) Reload(features map[string]bool) error {
 	var err error
+
 	bsp.BspV, err = util.ReadConfig(bsp.BasePath(),
 		strings.TrimSuffix(BSP_YAML_FILENAME, ".yml"))
 	if err != nil {
@@ -54,18 +70,33 @@ func (bsp *BspPackage) Reload(features map[string]bool) error {
 
 	bsp.CompilerName = newtutil.GetStringFeatures(bsp.BspV,
 		features, "bsp.compiler")
+
 	bsp.Arch = newtutil.GetStringFeatures(bsp.BspV,
 		features, "bsp.arch")
-	bsp.LinkerScript = newtutil.GetStringFeatures(bsp.BspV,
+
+	bsp.LinkerScript, err = bsp.resolvePathSetting(
 		features, "bsp.linkerscript")
-	bsp.Part2LinkerScript = newtutil.GetStringFeatures(bsp.BspV,
+	if err != nil {
+		return err
+	}
+
+	bsp.Part2LinkerScript, err = bsp.resolvePathSetting(
 		features, "bsp.part2linkerscript")
-	bsp.DownloadScript = newtutil.GetStringFeatures(bsp.BspV,
+	if err != nil {
+		return err
+	}
+
+	bsp.DownloadScript, err = bsp.resolvePathSetting(
 		features, "bsp.downloadscript")
-	bsp.DebugScript = newtutil.GetStringFeatures(bsp.BspV,
+	if err != nil {
+		return err
+	}
+
+	bsp.DebugScript, err = bsp.resolvePathSetting(
 		features, "bsp.debugscript")
-	bsp.WriteScript = newtutil.GetStringFeatures(bsp.BspV,
-		features, "bsp.writescript")
+	if err != nil {
+		return err
+	}
 
 	if bsp.CompilerName == "" {
 		return util.NewNewtError("BSP does not specify a compiler " +

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9dbb073c/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 95ee367..45f7405 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -523,7 +523,6 @@ func (proj *Project) ResolveDependency(dep interfaces.DependencyInterface)
inter
 
 func (proj *Project) ResolvePackage(
 	dfltRepo interfaces.RepoInterface, name string) (*pkg.LocalPackage, error) {
-
 	// Trim trailing slash from name.  This is necessary when tab
 	// completion is used to specify the name.
 	name = strings.TrimSuffix(name, "/")
@@ -557,6 +556,28 @@ func (proj *Project) ResolvePackage(
 	return pack.(*pkg.LocalPackage), nil
 }
 
+// Resolves a path with an optional repo prefix (e.g., "@apache-mynewt-core").
+func (proj *Project) ResolvePath(
+	basePath string, name string) (string, error) {
+
+	repoName, subPath, err := newtutil.ParsePackageString(name)
+	if err != nil {
+		return "", util.FmtNewtError("invalid path: %s (%s)", name,
+			err.Error())
+	}
+
+	if repoName == "" {
+		return basePath + "/" + subPath, nil
+	} else {
+		repo := proj.repos[repoName]
+		if repo == nil {
+			return "", util.FmtNewtError("Unknown repository: %s", repoName)
+		}
+
+		return repo.Path() + "/" + subPath, nil
+	}
+}
+
 func findProjectDir(dir string) (string, error) {
 	for {
 		projFile := path.Clean(dir) + "/" + PROJECT_FILE_NAME


Mime
View raw message