You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/10/10 17:15:04 UTC
[mynewt-newt] branch master updated (26d6132 -> 35f4af9)
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git.
from 26d6132 repo: print a detailed error when version not found (#337)
new 39005b8 rename: post_build --> post_link
new 316b566 Execute custom commands from pkg directory
new f8cc32b New environment variable: MYNEWT_NEWT_PATH
new b67f495 Replace "$ENV" vars in custom command strings
new 14e3cd9 Export basic env vars in newt process
new ec56577 Pass environment variables as map[string]string
new 825b29c Export more toolchain path env vars
new 35f4af9 Pass pre-link artifacts to linker
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
go.mod | 1 +
go.sum | 2 ++
newt/builder/build.go | 61 +++++++++++++++++--------------
newt/builder/buildutil.go | 48 +++++++++++++------------
newt/builder/cmake.go | 2 +-
newt/builder/extcmd.go | 34 ++++++++++++++----
newt/builder/load.go | 30 +++++++---------
newt/builder/selftest.go | 2 +-
newt/builder/targetbuild.go | 45 +++++++++++++++++++----
newt/pkg/localpackage.go | 4 +--
newt/resolve/resolve.go | 12 +++----
newt/toolchain/compiler.go | 12 +++++++
util/util.go | 87 ++++++++++++++++++++++++++++++++++++++-------
13 files changed, 238 insertions(+), 102 deletions(-)
[mynewt-newt] 07/08: Export more toolchain path env vars
Posted by cc...@apache.org.
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 825b29cee649deed283982a5204a431c8453508d
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Oct 8 16:19:29 2019 -0700
Export more toolchain path env vars
These environment variables get exported for custom commands to use.
The three new environment variables are:
MYNEWT_OBJCOPY_PATH
MYNEWT_OBJDUMP_PATH
MYNEWT_SIZE_PATH
---
newt/builder/buildutil.go | 11 +++++++----
newt/toolchain/compiler.go | 12 ++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 65a24ad..e7d8c4d 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -175,10 +175,13 @@ func BasicEnvVars(binBase string, bspPkg *pkg.BspPackage) map[string]string {
func ToolchainEnvVars(c *toolchain.Compiler) map[string]string {
return map[string]string{
- "MYNEWT_CC_PATH": c.GetCcPath(),
- "MYNEWT_CPP_PATH": c.GetCppPath(),
- "MYNEWT_AS_PATH": c.GetAsPath(),
- "MYNEWT_AR_PATH": c.GetArPath(),
+ "MYNEWT_AR_PATH": c.GetArPath(),
+ "MYNEWT_AS_PATH": c.GetAsPath(),
+ "MYNEWT_CC_PATH": c.GetCcPath(),
+ "MYNEWT_CPP_PATH": c.GetCppPath(),
+ "MYNEWT_OBJCOPY_PATH": c.GetObjcopyPath(),
+ "MYNEWT_OBJDUMP_PATH": c.GetObjdumpPath(),
+ "MYNEWT_SIZE_PATH": c.GetSizePath(),
}
}
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index 6831d7a..5473fa6 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -127,6 +127,18 @@ func (c *Compiler) GetArPath() string {
return c.arPath
}
+func (c *Compiler) GetObjcopyPath() string {
+ return c.ocPath
+}
+
+func (c *Compiler) GetObjdumpPath() string {
+ return c.odPath
+}
+
+func (c *Compiler) GetSizePath() string {
+ return c.osPath
+}
+
func (c *Compiler) GetLdResolveCircularDeps() bool {
return c.ldResolveCircularDeps
}
[mynewt-newt] 06/08: Pass environment variables as map[string]string
Posted by cc...@apache.org.
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 ec5657770d612abaab60d5d61250a87f0927abb6
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 4 17:52:55 2019 -0700
Pass environment variables as map[string]string
Prior to this commit, the util shell functions accepted env vars as
string slices (`k=v`). The problem with this approach was that env vars
already defined in the process would not get overwritten by new ones
(the new ones would be appended to the list; if they conflicted with old
ones, they were ignored).
Now environment variables are passed in maps. Newt manually overwrites
old env vars with new ones.
---
newt/builder/buildutil.go | 29 ++++++----------
newt/builder/extcmd.go | 13 +++++--
newt/builder/load.go | 30 +++++++---------
util/util.go | 87 ++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 107 insertions(+), 52 deletions(-)
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index b71fa94..65a24ad 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -21,7 +21,6 @@ package builder
import (
"bytes"
- "fmt"
"sort"
"strconv"
"strings"
@@ -33,6 +32,7 @@ import (
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/resolve"
+ "mynewt.apache.org/newt/newt/toolchain"
"mynewt.apache.org/newt/util"
)
@@ -173,6 +173,15 @@ func BasicEnvVars(binBase string, bspPkg *pkg.BspPackage) map[string]string {
return m
}
+func ToolchainEnvVars(c *toolchain.Compiler) map[string]string {
+ return map[string]string{
+ "MYNEWT_CC_PATH": c.GetCcPath(),
+ "MYNEWT_CPP_PATH": c.GetCppPath(),
+ "MYNEWT_AS_PATH": c.GetAsPath(),
+ "MYNEWT_AR_PATH": c.GetArPath(),
+ }
+}
+
// SettingsEnvVars calculates the syscfg set of environment variables required
// by image loading scripts.
func SettingsEnvVars(settings map[string]string) map[string]string {
@@ -299,21 +308,3 @@ func (b *Builder) EnvVars(imageSlot int) (map[string]string, error) {
return env, nil
}
-
-// EnvVarsToSlice converts an environment variable map into a slice of strings
-// suitable for "shell command" functions defined in `util` (e.g.,
-// util.ShellCommand).
-func EnvVarsToSlice(env map[string]string) []string {
- keys := make([]string, 0, len(env))
- for k, _ := range env {
- keys = append(keys, k)
- }
- sort.Strings(keys)
-
- slice := make([]string, 0, len(env))
- for _, key := range keys {
- slice = append(slice, fmt.Sprintf("%s=%s", key, env[key]))
- }
-
- return slice
-}
diff --git a/newt/builder/extcmd.go b/newt/builder/extcmd.go
index ba64280..cddea76 100644
--- a/newt/builder/extcmd.go
+++ b/newt/builder/extcmd.go
@@ -102,11 +102,19 @@ func (t *TargetBuilder) envVarsForCmd(sf stage.StageFunc, userSrcDir string,
WorkDir: workDir,
}
uenv := UserEnvVars(p)
-
for k, v := range uenv {
env[k] = v
}
+ c, err := t.NewCompiler("", "")
+ if err != nil {
+ return nil, err
+ }
+ tenv := ToolchainEnvVars(c)
+ for k, v := range tenv {
+ env[k] = v
+ }
+
return env, nil
}
@@ -147,8 +155,7 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, userSrcDir string,
defer os.Chdir(pwd)
util.StatusMessage(util.VERBOSITY_DEFAULT, "Executing %s\n", sf.Name)
- envs := EnvVarsToSlice(env)
- if err := util.ShellInteractiveCommand(toks, envs, true); err != nil {
+ if err := util.ShellInteractiveCommand(toks, env, true); err != nil {
return err
}
diff --git a/newt/builder/load.go b/newt/builder/load.go
index a166b8c..5f8421f 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -85,7 +85,7 @@ func (t *TargetBuilder) Load(extraJtagCmd string) error {
return err
}
-func RunOptionalCheck(checkScript string, env []string) error {
+func RunOptionalCheck(checkScript string, env map[string]string) error {
if checkScript == "" {
return nil
}
@@ -125,9 +125,8 @@ func Load(binBasePath string, bspPkg *pkg.BspPackage,
for k, v := range extraEnvSettings {
env[k] = v
}
- envSlice := EnvVarsToSlice(env)
- RunOptionalCheck(bspPkg.OptChkScript, envSlice)
+ RunOptionalCheck(bspPkg.OptChkScript, env)
// bspPath, binBasePath are passed in command line for backwards
// compatibility
cmd := []string{
@@ -142,7 +141,7 @@ func Load(binBasePath string, bspPkg *pkg.BspPackage,
for _, v := range env {
util.StatusMessage(util.VERBOSITY_VERBOSE, "* %s\n", v)
}
- if _, err := util.ShellCommand(cmd, envSlice); err != nil {
+ if _, err := util.ShellCommand(cmd, env); err != nil {
return err
}
util.StatusMessage(util.VERBOSITY_VERBOSE, "Successfully loaded image.\n")
@@ -211,31 +210,26 @@ func (b *Builder) debugBin(binPath string, extraJtagCmd string, reset bool,
bspPath := b.bspPkg.rpkg.Lpkg.BasePath()
binBasePath := binPath
- featureString := FeatureString(b.cfg.SettingValues())
bspPkg := b.targetBuilder.bspPkg
- coreRepo := project.GetProject().FindRepo("apache-mynewt-core")
- envSettings := []string{
- fmt.Sprintf("CORE_PATH=%s", coreRepo.Path()),
- fmt.Sprintf("BSP_PATH=%s", bspPath),
- fmt.Sprintf("BIN_BASENAME=%s", binBasePath),
- fmt.Sprintf("FEATURES=%s", featureString),
- fmt.Sprintf("MYNEWT_PROJECT_ROOT=%s", ProjectRoot()),
+ env, err := b.EnvVars(0)
+ if err != nil {
+ return err
}
+
if extraJtagCmd != "" {
- envSettings = append(envSettings,
- fmt.Sprintf("EXTRA_JTAG_CMD=%s", extraJtagCmd))
+ env["EXTRA_JTAG_CMD"] = extraJtagCmd
}
if reset == true {
- envSettings = append(envSettings, fmt.Sprintf("RESET=true"))
+ env["RESET"] = "true"
}
if noGDB == true {
- envSettings = append(envSettings, fmt.Sprintf("NO_GDB=1"))
+ env["NO_GDB"] = "1"
}
os.Chdir(project.GetProject().Path())
- RunOptionalCheck(bspPkg.OptChkScript, envSettings)
+ RunOptionalCheck(bspPkg.OptChkScript, env)
// bspPath, binBasePath are passed in command line for backwards
// compatibility
cmdLine := []string{
@@ -243,7 +237,7 @@ func (b *Builder) debugBin(binPath string, extraJtagCmd string, reset bool,
}
fmt.Printf("%s\n", cmdLine)
- return util.ShellInteractiveCommand(cmdLine, envSettings, false)
+ return util.ShellInteractiveCommand(cmdLine, env, false)
}
func (b *Builder) Debug(extraJtagCmd string, reset bool, noGDB bool) error {
diff --git a/util/util.go b/util/util.go
index aa46495..9800ea8 100644
--- a/util/util.go
+++ b/util/util.go
@@ -273,10 +273,11 @@ func fixupCmdArgs(args []string) {
}
}
-func LogShellCmd(cmdStrs []string, env []string) {
+func LogShellCmd(cmdStrs []string, env map[string]string) {
envLogStr := ""
if len(env) > 0 {
- envLogStr = strings.Join(env, " ") + " "
+ s := EnvVarsToSlice(env)
+ envLogStr = strings.Join(s, " ") + " "
}
log.Debugf("%s%s", envLogStr, strings.Join(cmdStrs, " "))
@@ -285,12 +286,58 @@ func LogShellCmd(cmdStrs []string, env []string) {
}
}
+// EnvVarsToSlice converts an environment variable map into a slice of `k=v`
+// strings.
+func EnvVarsToSlice(env map[string]string) []string {
+ keys := make([]string, 0, len(env))
+ for k, _ := range env {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+
+ slice := make([]string, 0, len(env))
+ for _, key := range keys {
+ slice = append(slice, fmt.Sprintf("%s=%s", key, env[key]))
+ }
+
+ return slice
+}
+
+// SliceToEnvVars converts a slice of `k=v` strings into an environment
+// variable map.
+func SliceToEnvVars(slc []string) (map[string]string, error) {
+ m := make(map[string]string, len(slc))
+ for _, s := range slc {
+ parts := strings.SplitN(s, "=", 2)
+ if len(parts) != 2 {
+ return nil, FmtNewtError("invalid env var string: \"%s\"", s)
+ }
+
+ m[parts[0]] = parts[1]
+ }
+
+ return m, nil
+}
+
+// EnvironAsMap gathers the current process's set of environment variables and
+// returns them as a map.
+func EnvironAsMap() (map[string]string, error) {
+ slc := os.Environ()
+
+ m, err := SliceToEnvVars(slc)
+ if err != nil {
+ return nil, err
+ }
+
+ return m, nil
+}
+
// Execute the specified process and block until it completes. Additionally,
// the amount of combined stdout+stderr output to be logged to the debug log
// can be restricted to a maximum number of characters.
//
// @param cmdStrs The "argv" strings of the command to execute.
-// @param env Additional key=value pairs to inject into the
+// @param env Additional key,value pairs to inject into the
// child process's environment. Specify null
// to just inherit the parent environment.
// @param logCmd Whether to log the command being executed.
@@ -304,8 +351,8 @@ func LogShellCmd(cmdStrs []string, env []string) {
// or if it just returned a non-zero exit
// status.
func ShellCommandLimitDbgOutput(
- cmdStrs []string, env []string, logCmd bool, maxDbgOutputChrs int) (
- []byte, error) {
+ cmdStrs []string, env map[string]string, logCmd bool,
+ maxDbgOutputChrs int) ([]byte, error) {
var name string
var args []string
@@ -328,7 +375,15 @@ func ShellCommandLimitDbgOutput(
cmd := exec.Command(name, args...)
if env != nil {
- cmd.Env = append(env, os.Environ()...)
+ m, err := EnvironAsMap()
+ if err != nil {
+ return nil, err
+ }
+
+ for k, v := range env {
+ m[k] = v
+ }
+ cmd.Env = EnvVarsToSlice(m)
}
o, err := cmd.CombinedOutput()
@@ -356,18 +411,20 @@ func ShellCommandLimitDbgOutput(
// Execute the specified process and block until it completes.
//
// @param cmdStrs The "argv" strings of the command to execute.
-// @param env Additional key=value pairs to inject into the
+// @param env Additional key,value pairs to inject into the
// child process's environment. Specify null
// to just inherit the parent environment.
//
// @return []byte Combined stdout and stderr output of process.
// @return error NewtError on failure.
-func ShellCommand(cmdStrs []string, env []string) ([]byte, error) {
+func ShellCommand(cmdStrs []string, env map[string]string) ([]byte, error) {
return ShellCommandLimitDbgOutput(cmdStrs, env, true, -1)
}
// Run interactive shell command
-func ShellInteractiveCommand(cmdStr []string, env []string, flagBlock bool) error {
+func ShellInteractiveCommand(cmdStr []string, env map[string]string,
+ flagBlock bool) error {
+
// Escape special characters for Windows.
fixupCmdArgs(cmdStr)
@@ -385,15 +442,21 @@ func ShellInteractiveCommand(cmdStr []string, env []string, flagBlock bool) erro
}()
}
- if env != nil {
- env = append(env, os.Environ()...)
+ m, err := EnvironAsMap()
+ if err != nil {
+ return err
+ }
+
+ for k, v := range env {
+ m[k] = v
}
+ envSlice := EnvVarsToSlice(m)
// Transfer stdin, stdout, and stderr to the new process
// and also set target directory for the shell to start in.
// and set the additional environment variables
pa := os.ProcAttr{
- Env: env,
+ Env: envSlice,
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
}
[mynewt-newt] 08/08: Pass pre-link artifacts to linker
Posted by cc...@apache.org.
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 35f4af9289a3cb5ffe19d8513c2b55bb72b7f4bd
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Oct 9 15:30:33 2019 -0700
Pass pre-link artifacts to linker
.a files produced by pre-link user scripts were not being passed to the
linker. This commit adds the pre-link "user source" directory to the
list of directories to scan at link time.
Note: Artifacts produced by pre-build scripts (not pre-link) do get used
as intended. At compile time, newt copies .a files from package source
directories to their respective binary directories. Since pre-link
scripts run after compile time, this copy never happens for pre-link
artifacts, so we need to tell newt where to look.
---
newt/builder/build.go | 61 +++++++++++++++++++++++++--------------------
newt/builder/selftest.go | 2 +-
newt/builder/targetbuild.go | 34 ++++++++++++++++++++-----
3 files changed, 63 insertions(+), 34 deletions(-)
diff --git a/newt/builder/build.go b/newt/builder/build.go
index d23d44d..7a25e76 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -90,9 +90,6 @@ func NewBuilder(
if _, err := b.addUserPreBuildBpkg(); err != nil {
return nil, err
}
- if _, err := b.addUserPreLinkBpkg(); err != nil {
- return nil, err
- }
for api, rpkg := range apiMap {
bpkg := b.PkgMap[rpkg]
@@ -400,22 +397,17 @@ func (b *Builder) ExtractSymbolInfo() (error, *symbol.SymbolMap) {
}
func (b *Builder) link(elfName string, linkerScripts []string,
- keepSymbols []string) error {
+ keepSymbols []string, extraADirs []string) error {
c, err := b.newCompiler(b.appPkg, b.FileBinDir(elfName))
if err != nil {
return err
}
- /* Always used the trimmed archive files. */
- pkgNames := []string{}
-
+ // Calculate the list of directories containing source .a files.
+ var dirs []string
for _, bpkg := range b.sortedBuildPackages() {
- archiveNames, _ := filepath.Glob(b.PkgBinDir(bpkg) + "/*.a")
- for i, archiveName := range archiveNames {
- archiveNames[i] = filepath.ToSlash(archiveName)
- }
- pkgNames = append(pkgNames, archiveNames...)
+ dirs = append(dirs, b.PkgBinDir(bpkg))
// Collect lflags from all constituent packages. Discard everything
// from the compiler info except lflags; that is all that is relevant
@@ -426,9 +418,20 @@ func (b *Builder) link(elfName string, linkerScripts []string,
}
c.AddInfo(&toolchain.CompilerInfo{Lflags: ci.Lflags})
}
+ dirs = append(dirs, extraADirs...)
+
+ // Find all .a files in the input directories.
+ trimmedANames := []string{}
+ for _, dir := range dirs {
+ fullANames, _ := filepath.Glob(dir + "/*.a")
+ for i, archiveName := range fullANames {
+ fullANames[i] = filepath.ToSlash(archiveName)
+ }
+ trimmedANames = append(trimmedANames, fullANames...)
+ }
c.LinkerScripts = linkerScripts
- err = c.CompileElf(elfName, pkgNames, keepSymbols, b.linkElf)
+ err = c.CompileElf(elfName, trimmedANames, keepSymbols, b.linkElf)
if err != nil {
return err
}
@@ -555,13 +558,6 @@ func (b *Builder) addUserPreBuildBpkg() (*BuildPackage, error) {
UserPreBuildDir(b.targetPkg.rpkg.Lpkg.FullName()))
}
-// addUserPreLinkBpkg adds the pseudo user build package to the builder. The
-// user build package contains inputs emitted by external scripts.
-func (b *Builder) addUserPreLinkBpkg() (*BuildPackage, error) {
- return b.addPseudoBpkg("user-pre-link",
- UserPreLinkDir(b.targetPkg.rpkg.Lpkg.FullName()))
-}
-
// Runs build jobs while any remain. On failure, signals the other workers to
// stop via the stop channel. On error, the error object is signaled via the
// results channel. On successful completion, nil is signaled via the results
@@ -693,15 +689,17 @@ func (b *Builder) Build() error {
return nil
}
-func (b *Builder) Link(linkerScripts []string) error {
- if err := b.link(b.AppElfPath(), linkerScripts, nil); err != nil {
+func (b *Builder) Link(linkerScripts []string, extraADirs []string) error {
+ if err := b.link(b.AppElfPath(), linkerScripts, nil,
+ extraADirs); err != nil {
+
return err
}
return nil
}
-func (b *Builder) KeepLink(
- linkerScripts []string, keepMap *symbol.SymbolMap) error {
+func (b *Builder) KeepLink(linkerScripts []string, keepMap *symbol.SymbolMap,
+ extraADirs []string) error {
keepSymbols := make([]string, 0)
@@ -710,16 +708,25 @@ func (b *Builder) KeepLink(
keepSymbols = append(keepSymbols, info.Name)
}
}
- if err := b.link(b.AppElfPath(), linkerScripts, keepSymbols); err != nil {
+
+ if err := b.link(b.AppElfPath(), linkerScripts, keepSymbols,
+ extraADirs); err != nil {
+
return err
}
+
return nil
}
-func (b *Builder) TentativeLink(linkerScripts []string) error {
- if err := b.link(b.AppTentativeElfPath(), linkerScripts, nil); err != nil {
+func (b *Builder) TentativeLink(linkerScripts []string,
+ extraADirs []string) error {
+
+ if err := b.link(b.AppTentativeElfPath(), linkerScripts, nil,
+ extraADirs); err != nil {
+
return err
}
+
return nil
}
diff --git a/newt/builder/selftest.go b/newt/builder/selftest.go
index 1fb4cc3..1ff1aae 100644
--- a/newt/builder/selftest.go
+++ b/newt/builder/selftest.go
@@ -33,7 +33,7 @@ import (
func (b *Builder) SelfTestLink(rpkg *resolve.ResolvePackage) error {
testPath := b.TestExePath()
- if err := b.link(testPath, nil, nil); err != nil {
+ if err := b.link(testPath, nil, nil, nil); err != nil {
return err
}
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index db337e5..bbc35ff 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -325,6 +325,22 @@ func (t *TargetBuilder) validateAndWriteCfg() error {
return nil
}
+// extraADirs returns a slice of extra directories that should be used at link
+// time. .a files in these directores are used as input to the link (in
+// addition to .a files produced by building packages).
+func (t *TargetBuilder) extraADirs() []string {
+ return []string{
+ // Artifacts generated by pre-link user scripts.
+ UserPreLinkSrcDir(t.target.FullName()),
+ }
+
+ // Note: we don't include the pre-build source directory in this list. At
+ // compile time, newt copies .a files from package source directories to
+ // their respective binary directories. Since pre-link scripts run after
+ // compile time, this copy never happens for pre-link artifacts, so we need
+ // to tell newt where to look.
+}
+
func (t *TargetBuilder) PrepBuild() error {
if err := t.ensureResolved(); err != nil {
return err
@@ -395,8 +411,12 @@ func (t *TargetBuilder) PrepBuild() error {
}
func (t *TargetBuilder) buildLoader() error {
- /* Tentatively link the app (using the normal single image linker script) */
- if err := t.AppBuilder.TentativeLink(t.bspPkg.LinkerScripts); err != nil {
+ /* Tentatively link the app (using the normal single image linker
+ * script)
+ */
+ if err := t.AppBuilder.TentativeLink(t.bspPkg.LinkerScripts,
+ t.extraADirs()); err != nil {
+
return err
}
@@ -412,7 +432,9 @@ func (t *TargetBuilder) buildLoader() error {
}
/* Tentatively link the loader */
- if err := t.LoaderBuilder.TentativeLink(t.bspPkg.LinkerScripts); err != nil {
+ if err := t.LoaderBuilder.TentativeLink(t.bspPkg.LinkerScripts,
+ t.extraADirs()); err != nil {
+
return err
}
@@ -554,7 +576,7 @@ func (t *TargetBuilder) Build() error {
}
/* Link the app. */
- if err := t.AppBuilder.Link(linkerScripts); err != nil {
+ if err := t.AppBuilder.Link(linkerScripts, t.extraADirs()); err != nil {
return err
}
@@ -685,8 +707,8 @@ func (t *TargetBuilder) RelinkLoader() (error, map[string]bool,
util.StatusMessage(util.VERBOSITY_VERBOSE,
"Migrating %d unused symbols into Loader\n", len(*preserveElf))
- err = t.LoaderBuilder.KeepLink(t.bspPkg.LinkerScripts, preserveElf)
-
+ err = t.LoaderBuilder.KeepLink(t.bspPkg.LinkerScripts, preserveElf,
+ t.extraADirs())
if err != nil {
return err, nil, nil
}
[mynewt-newt] 03/08: New environment variable: MYNEWT_NEWT_PATH
Posted by cc...@apache.org.
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 f8cc32ba37be99b66b4db3b2d46f401cfeac2df7
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 4 14:12:00 2019 -0700
New environment variable: MYNEWT_NEWT_PATH
This environment variable contains the path of the newt tool.
---
newt/builder/buildutil.go | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index e330f36..b71fa94 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -26,6 +26,7 @@ import (
"strconv"
"strings"
+ "github.com/kardianos/osext"
log "github.com/sirupsen/logrus"
"mynewt.apache.org/newt/newt/parse"
@@ -149,18 +150,27 @@ func (b *Builder) binBasePath() (string, error) {
}
// BasicEnvVars calculates the basic set of environment variables passed to all
-// external scripts. `binBase` is the result of calling `binBasePath()`.
+// external scripts. `binBase` is the result of calling `binBasePath()`, or ""
+// if you don't need the "BIN_BASENAME" setting.
func BasicEnvVars(binBase string, bspPkg *pkg.BspPackage) map[string]string {
coreRepo := project.GetProject().FindRepo("apache-mynewt-core")
bspPath := bspPkg.BasePath()
- return map[string]string{
+ newtPath, _ := osext.Executable()
+
+ m := map[string]string{
"CORE_PATH": coreRepo.Path(),
"BSP_PATH": bspPath,
- "BIN_BASENAME": binBase,
"BIN_ROOT": BinRoot(),
"MYNEWT_PROJECT_ROOT": ProjectRoot(),
+ "MYNEWT_NEWT_PATH": newtPath,
+ }
+
+ if binBase != "" {
+ m["BIN_BASENAME"] = binBase
}
+
+ return m
}
// SettingsEnvVars calculates the syscfg set of environment variables required
[mynewt-newt] 04/08: Replace "$ENV" vars in custom command strings
Posted by cc...@apache.org.
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 b67f4955e330c6c95f762376f007e09a664c4661
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 4 14:54:51 2019 -0700
Replace "$ENV" vars in custom command strings
---
newt/builder/extcmd.go | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/newt/builder/extcmd.go b/newt/builder/extcmd.go
index 8821e65..ba64280 100644
--- a/newt/builder/extcmd.go
+++ b/newt/builder/extcmd.go
@@ -119,13 +119,17 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, userSrcDir string,
return err
}
- envs := EnvVarsToSlice(env)
toks, err := shellquote.Split(sf.Name)
if err != nil {
return util.FmtNewtError(
"invalid command string: \"%s\": %s", sf.Name, err.Error())
}
+ // Replace environment variables in command string.
+ for i, tok := range toks {
+ toks[i] = os.ExpandEnv(tok)
+ }
+
// If the command is in the user's PATH, expand it to its real location.
cmd, err := exec.LookPath(toks[0])
if err == nil {
@@ -143,6 +147,7 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, userSrcDir string,
defer os.Chdir(pwd)
util.StatusMessage(util.VERBOSITY_DEFAULT, "Executing %s\n", sf.Name)
+ envs := EnvVarsToSlice(env)
if err := util.ShellInteractiveCommand(toks, envs, true); err != nil {
return err
}
[mynewt-newt] 05/08: Export basic env vars in newt process
Posted by cc...@apache.org.
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 14e3cd9f5243ac003d6316da3c7b34911e9e313f
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 4 14:41:13 2019 -0700
Export basic env vars in newt process
Export the following environment variables in the newt process itself:
"CORE_PATH"
"BSP_PATH"
"BIN_ROOT"
"MYNEWT_PROJECT_ROOT"
"MYNEWT_NEWT_PATH"
These allows a `pkg.yml` file to use these settings in its list of
custom commands.
---
go.mod | 1 +
go.sum | 2 ++
newt/builder/targetbuild.go | 9 +++++++++
3 files changed, 12 insertions(+)
diff --git a/go.mod b/go.mod
index e0368d0..da59696 100644
--- a/go.mod
+++ b/go.mod
@@ -5,6 +5,7 @@ go 1.12
require (
github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
github.com/apache/mynewt-artifact v0.0.3
+ github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cast v1.3.0
diff --git a/go.sum b/go.sum
index de1f0bd..22f3207 100644
--- a/go.sum
+++ b/go.sum
@@ -16,6 +16,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
+github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index ba9728b..db337e5 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -225,6 +225,15 @@ func (t *TargetBuilder) ensureResolved() error {
return err
}
+ // Configure the basic set of environment variables in the current process.
+ env := BasicEnvVars("", t.bspPkg)
+ for k, v := range env {
+ if err := os.Setenv(k, v); err != nil {
+ return util.FmtNewtError(
+ "failed to set env var %s=%s: %s", k, v, err.Error())
+ }
+ }
+
return nil
}
[mynewt-newt] 01/08: rename: post_build --> post_link
Posted by cc...@apache.org.
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 39005b80a6a034244061898c1b610dd7e4e34a36
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 4 13:45:34 2019 -0700
rename: post_build --> post_link
---
newt/builder/cmake.go | 2 +-
newt/builder/extcmd.go | 6 +++---
newt/builder/targetbuild.go | 2 +-
newt/pkg/localpackage.go | 4 ++--
newt/resolve/resolve.go | 12 ++++++------
5 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go
index 031b628..a96ce23 100644
--- a/newt/builder/cmake.go
+++ b/newt/builder/cmake.go
@@ -314,7 +314,7 @@ func (t *TargetBuilder) CMakeTargetBuilderWrite(w io.Writer, targetCompiler *too
if len(t.res.PreBuildCmdCfg.StageFuncs) > 0 ||
len(t.res.PreLinkCmdCfg.StageFuncs) > 0 ||
- len(t.res.PostBuildCmdCfg.StageFuncs) > 0 {
+ len(t.res.PostLinkCmdCfg.StageFuncs) > 0 {
util.OneTimeWarning(
"custom commands not included in cmake output (unsupported)")
diff --git a/newt/builder/extcmd.go b/newt/builder/extcmd.go
index 624a025..b8e7746 100644
--- a/newt/builder/extcmd.go
+++ b/newt/builder/extcmd.go
@@ -200,10 +200,10 @@ func (t *TargetBuilder) execPreLinkCmds(workDir string) error {
return nil
}
-// execPostBuildCmds runs the target's set of post-build user commands. It is
+// execPostLinkCmds runs the target's set of post-build user commands. It is
// an error if any command fails (exits with a nonzero status).
-func (t *TargetBuilder) execPostBuildCmds(workDir string) error {
- for _, sf := range t.res.PostBuildCmdCfg.StageFuncs {
+func (t *TargetBuilder) execPostLinkCmds(workDir string) error {
+ for _, sf := range t.res.PostLinkCmdCfg.StageFuncs {
if err := t.execExtCmds(sf, "", "", workDir); err != nil {
return err
}
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index c5145a1..ba9728b 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -550,7 +550,7 @@ func (t *TargetBuilder) Build() error {
}
// Execute the set of post-build user scripts.
- if err := t.execPostBuildCmds(workDir); err != nil {
+ if err := t.execPostLinkCmds(workDir); err != nil {
return err
}
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index d1f0088..bd48455 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -389,10 +389,10 @@ func (pkg *LocalPackage) PreLinkCmds(
return pkg.PkgY.GetValStringMapString("pkg.pre_link_cmds", settings)
}
-func (pkg *LocalPackage) PostBuildCmds(
+func (pkg *LocalPackage) PostLinkCmds(
settings map[string]string) map[string]string {
- return pkg.PkgY.GetValStringMapString("pkg.post_build_cmds", settings)
+ return pkg.PkgY.GetValStringMapString("pkg.post_link_cmds", settings)
}
func (pkg *LocalPackage) InjectedSettings() map[string]string {
diff --git a/newt/resolve/resolve.go b/newt/resolve/resolve.go
index 0cb6c98..11495ef 100644
--- a/newt/resolve/resolve.go
+++ b/newt/resolve/resolve.go
@@ -70,7 +70,7 @@ type Resolver struct {
sysdownCfg sysdown.SysdownCfg
preBuildCmdCfg extcmd.ExtCmdCfg
preLinkCmdCfg extcmd.ExtCmdCfg
- postBuildCmdCfg extcmd.ExtCmdCfg
+ postLinkCmdCfg extcmd.ExtCmdCfg
// [api-name][api-supplier]
apiConflicts map[string]map[*ResolvePackage]struct{}
@@ -125,7 +125,7 @@ type Resolution struct {
SysdownCfg sysdown.SysdownCfg
PreBuildCmdCfg extcmd.ExtCmdCfg
PreLinkCmdCfg extcmd.ExtCmdCfg
- PostBuildCmdCfg extcmd.ExtCmdCfg
+ PostLinkCmdCfg extcmd.ExtCmdCfg
ApiMap map[string]*ResolvePackage
UnsatisfiedApis map[string][]*ResolvePackage
ApiConflicts []ApiConflict
@@ -1004,10 +1004,10 @@ func (r *Resolver) resolveDepsAndCfg() error {
settings map[string]string) map[string]string {
return lpkg.PreLinkCmds(settings)
})
- r.postBuildCmdCfg = extcmd.Read("post_build_cmds", lpkgs, &r.cfg,
+ r.postLinkCmdCfg = extcmd.Read("post_link_cmds", lpkgs, &r.cfg,
func(lpkg *pkg.LocalPackage,
settings map[string]string) map[string]string {
- return lpkg.PostBuildCmds(settings)
+ return lpkg.PostLinkCmds(settings)
})
// Log the final syscfg.
@@ -1110,7 +1110,7 @@ func ResolveFull(
res.SysdownCfg = r.sysdownCfg
res.PreBuildCmdCfg = r.preBuildCmdCfg
res.PreLinkCmdCfg = r.preLinkCmdCfg
- res.PostBuildCmdCfg = r.postBuildCmdCfg
+ res.PostLinkCmdCfg = r.postLinkCmdCfg
// Determine which package satisfies each API and which APIs are
// unsatisfied.
@@ -1231,7 +1231,7 @@ func (res *Resolution) ErrorText() string {
str += res.SysdownCfg.ErrorText()
str += res.PreBuildCmdCfg.ErrorText()
str += res.PreLinkCmdCfg.ErrorText()
- str += res.PostBuildCmdCfg.ErrorText()
+ str += res.PostLinkCmdCfg.ErrorText()
str = strings.TrimSpace(str)
if str != "" {
[mynewt-newt] 02/08: Execute custom commands from pkg directory
Posted by cc...@apache.org.
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 316b566f473f5ce38c33564925c1ca5b135f0284
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 4 13:57:33 2019 -0700
Execute custom commands from pkg directory
E.g., if the following script exists:
apps/blinky/scripts/run.sh
then `apps/blinky/pkg.yml` can specify:
pkg.pre_build_cmds:
scripts/run.sh: 100
---
newt/builder/extcmd.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/newt/builder/extcmd.go b/newt/builder/extcmd.go
index b8e7746..8821e65 100644
--- a/newt/builder/extcmd.go
+++ b/newt/builder/extcmd.go
@@ -132,6 +132,16 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, userSrcDir string,
toks[0] = cmd
}
+ // Execute the commands from the package's directory.
+ pwd, err := os.Getwd()
+ if err != nil {
+ return util.ChildNewtError(err)
+ }
+ if err := os.Chdir(sf.Pkg.BasePath()); err != nil {
+ return util.ChildNewtError(err)
+ }
+ defer os.Chdir(pwd)
+
util.StatusMessage(util.VERBOSITY_DEFAULT, "Executing %s\n", sf.Name)
if err := util.ShellInteractiveCommand(toks, envs, true); err != nil {
return err