You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2020/03/03 09:41:48 UTC

[mynewt-newt] branch master updated: Add repositories info to syscfg.h

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4d51693  Add repositories info to syscfg.h
4d51693 is described below

commit 4d51693f1d0347f6e088a1335d454badd3d3a641
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Mon Mar 2 12:05:25 2020 +0100

    Add repositories info to syscfg.h
    
    This add basic repositories info to syscfg.h for easier reporting
    of project version in runtime.
    
    For each repository FOO two informative MYNEWT_VALs are created:
    REPO_HASH_FOO and REPO_VERSION_FOO. Example:
    
     /*** Repository @apache-mynewt-core info */
     #ifndef MYNEWT_VAL_REPO_HASH_APACHE_MYNEWT_CORE
     #define MYNEWT_VAL_REPO_HASH_APACHE_MYNEWT_CORE ("26a9a5263b526f9869b8057a99be0759d601c8b7")
     #endif
    
     #ifndef MYNEWT_VAL_REPO_VERSION_APACHE_MYNEWT_CORE
     #define MYNEWT_VAL_REPO_VERSION_APACHE_MYNEWT_CORE ("0.0.1")
     #endif
    
     /*** Repository @apache-mynewt-mcumgr info */
     #ifndef MYNEWT_VAL_REPO_HASH_APACHE_MYNEWT_MCUMGR
     #define MYNEWT_VAL_REPO_HASH_APACHE_MYNEWT_MCUMGR ("ae4659b445b707409fb17d626c806de3ed284720")
     #endif
    
     #ifndef MYNEWT_VAL_REPO_VERSION_APACHE_MYNEWT_MCUMGR
     #define MYNEWT_VAL_REPO_VERSION_APACHE_MYNEWT_MCUMGR ("0.0.0")
     #endif
    
     /*** Repository @apache-mynewt-nimble info */
     #ifndef MYNEWT_VAL_REPO_HASH_APACHE_MYNEWT_NIMBLE
     #define MYNEWT_VAL_REPO_HASH_APACHE_MYNEWT_NIMBLE ("01b91ea01d35d1928fe17008d1a66917150d5231-dirty")
     #endif
    
     #ifndef MYNEWT_VAL_REPO_VERSION_APACHE_MYNEWT_NIMBLE
     #define MYNEWT_VAL_REPO_VERSION_APACHE_MYNEWT_NIMBLE ("0.0.0")
     #endif
---
 newt/syscfg/syscfg.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go
index a8847ce..80d42eb 100644
--- a/newt/syscfg/syscfg.go
+++ b/newt/syscfg/syscfg.go
@@ -39,6 +39,7 @@ import (
 	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/newt/parse"
 	"mynewt.apache.org/newt/newt/pkg"
+	"mynewt.apache.org/newt/newt/project"
 	"mynewt.apache.org/newt/util"
 )
 
@@ -1391,6 +1392,59 @@ func writeSettings(cfg Cfg, w io.Writer) {
 	}
 }
 
+func writeReposInfo(w io.Writer) {
+	repos := make([]string, 0, len(project.GetProject().Repos()))
+	for r, _ := range project.GetProject().Repos() {
+		repos = append(repos, r)
+	}
+	sort.Strings(repos)
+
+	for _, n := range repos {
+		r := project.GetProject().Repos()[n]
+
+		if !r.CheckExists() {
+			continue;
+		}
+
+		commitHash, err := r.CurrentHash()
+		if err != nil {
+			continue;
+		}
+
+		fmt.Fprintf(w, "/*** Repository @%s info */\n", r.Name())
+
+		k := fmt.Sprintf("%s", settingName("REPO_HASH_" + util.CIdentifier(strings.ToUpper(r.Name()))))
+		v := fmt.Sprintf("\"%s", commitHash)
+
+		dirty, err := r.DirtyState()
+		if err != nil {
+			dirty = "unknown"
+		}
+
+		if dirty != "" {
+			v += "-dirty"
+		}
+
+		v += "\""
+
+		writeDefine(k, v, w)
+		fmt.Fprintf(w, "\n")
+
+		ver, err := r.InstalledVersion()
+		if err != nil || ver == nil {
+			v = "0.0.0"
+		} else {
+			v = ver.String();
+		}
+
+		k = fmt.Sprintf("%s", settingName("REPO_VERSION_" + util.CIdentifier(strings.ToUpper(r.Name()))))
+		v = fmt.Sprintf("\"%s\"", v)
+
+		writeDefine(k, v, w)
+		fmt.Fprintf(w, "\n")
+	}
+}
+
 func write(cfg Cfg, w io.Writer) {
 	fmt.Fprintf(w, newtutil.GeneratedPreamble())
 
@@ -1400,6 +1454,9 @@ func write(cfg Cfg, w io.Writer) {
 	writeCheckMacros(w)
 	fmt.Fprintf(w, "\n")
 
+	writeReposInfo(w)
+	fmt.Fprintf(w, "\n")
+
 	writeSettings(cfg, w)
 	fmt.Fprintf(w, "\n")