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 2018/12/11 00:40:56 UTC

[mynewt-newt] 01/03: Include auto-generated macros in syscfg

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 8473fc33755af1e80fdb128aeffc39b49a188e5b
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Dec 6 17:09:12 2018 -0800

    Include auto-generated macros in syscfg
    
    This fixes #144.
    
    Among others, newt defines the following macros on the command line for
    each build:
        -DAPP_NAME="<app-name>"
        -DAPP_<app-name>
        -DARCH_NAME="<arch-name>"
        -DARCH_<arch-name>
        -DBSP_NAME="<bsp-name>"
        -DBSP_<bsp-name>
    
    This is inconsistent with all the other settings, which are accessed
    through syscfg.  It also adds noise to the command line invocations,
    making debugging more difficult.
    
    Now, newt injects each of the above settings into syscfg.  These
    settings can be checked using the `MYNEWT_VAL()` macro.  Newt continues
    to define these macros on the command line for backwards compatibility.
---
 newt/builder/build.go       |  3 ++-
 newt/builder/targetbuild.go | 40 ++++++++++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/newt/builder/build.go b/newt/builder/build.go
index 9db2213..06b1641 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -486,7 +486,8 @@ func (b *Builder) PrepBuild() error {
 
 	// Define a cpp symbol indicating the BSP architecture, name of the
 	// BSP and app.
-
+	// The arch, app, and bsp defines are kept here for backwards compatiblity.
+	// Users should prefer the equivalent syscfg defines.
 	archName := b.targetBuilder.bspPkg.Arch
 	bspCi.Cflags = append(bspCi.Cflags, "-DARCH_"+util.CIdentifier(archName))
 	bspCi.Cflags = append(bspCi.Cflags, "-DARCH_NAME="+archName+"")
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index f5fa8e6..ed2416b 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -99,9 +99,6 @@ func NewTargetTester(target *target.Target,
 		injectedSettings: map[string]string{},
 	}
 
-	// Indicate that this version of newt supports the generated logcfg header.
-	t.InjectSetting("NEWT_FEATURE_LOGCFG", "1")
-
 	return t, nil
 }
 
@@ -122,11 +119,38 @@ func (t *TargetBuilder) NewCompiler(dstDir string, buildProfile string) (
 	return c, err
 }
 
+func (t *TargetBuilder) injectNewtSettings() {
+	// Indicate that this version of newt supports the generated logcfg header.
+	t.InjectSetting("NEWT_FEATURE_LOGCFG", "1")
+
+	// Indicate to the apache-mynewt-core code that this version of newt
+	// supports the sysdown mechanism (generated package shutdown functions).
+	t.InjectSetting("NEWT_FEATURE_SYSDOWN", "1")
+}
+
+func (t *TargetBuilder) injectBuildSettings() {
+	t.InjectSetting("ARCH_NAME", "\""+t.bspPkg.Arch+"\"")
+	t.InjectSetting("ARCH_"+util.CIdentifier(t.bspPkg.Arch), "1")
+
+	if t.appPkg != nil {
+		appName := filepath.Base(t.appPkg.Name())
+		t.InjectSetting("APP_NAME", "\""+appName+"\"")
+		t.InjectSetting("APP_"+util.CIdentifier(appName), "1")
+	}
+
+	bspName := filepath.Base(t.bspPkg.Name())
+	t.InjectSetting("BSP_NAME", "\""+bspName+"\"")
+	t.InjectSetting("BSP_"+util.CIdentifier(bspName), "1")
+}
+
 func (t *TargetBuilder) ensureResolved() error {
 	if t.res != nil {
 		return nil
 	}
 
+	t.injectNewtSettings()
+	t.injectBuildSettings()
+
 	var loaderSeeds []*pkg.LocalPackage
 	if t.loaderPkg != nil {
 		loaderSeeds = []*pkg.LocalPackage{
@@ -149,7 +173,7 @@ func (t *TargetBuilder) ensureResolved() error {
 
 		// Inject the SPLIT_IMAGE setting into the entire target.  All packages
 		// now know that they are part of a split image build.
-		t.injectedSettings["SPLIT_IMAGE"] = "1"
+		t.InjectSetting("SPLIT_IMAGE", "1")
 	}
 
 	appSeeds := []*pkg.LocalPackage{
@@ -168,16 +192,12 @@ func (t *TargetBuilder) ensureResolved() error {
 		//     * TEST:      lets packages know that this is a test app
 		//     * SELFTEST:  indicates that the "newt test" command is used;
 		//                  causes a package to define a main() function.
-		t.injectedSettings["TEST"] = "1"
-		t.injectedSettings["SELFTEST"] = "1"
+		t.InjectSetting("TEST", "1")
+		t.InjectSetting("SELFTEST", "1")
 
 		appSeeds = append(appSeeds, t.testPkg)
 	}
 
-	// Indicate to the apache-mynewt-core code that this version of newt
-	// supports the sysdown mechanism (generated package shutdown functions).
-	t.injectedSettings["NEWT_FEATURE_SYSDOWN"] = "1"
-
 	var err error
 	t.res, err = resolve.ResolveFull(
 		loaderSeeds, appSeeds, t.injectedSettings, t.bspPkg.FlashMap)