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 2016/03/10 06:31:45 UTC
[1/3] incubator-mynewt-newt git commit: Fail build if target has
invalid build profile.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 34866da09 -> a8b5adac8
Fail build if target has invalid build profile.
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/2bca5cc7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/2bca5cc7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/2bca5cc7
Branch: refs/heads/develop
Commit: 2bca5cc7e49c7a8402d548ed7349bfee1b6bd526
Parents: 34866da
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Mar 9 19:14:41 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Mar 9 19:14:41 2016 -0800
----------------------------------------------------------------------
newt/cli/build_cmds.go | 4 ++--
newt/target/target.go | 5 ++++-
newt/toolchain/compiler.go | 6 ++++++
util/util.go | 4 ++++
4 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2bca5cc7/newt/cli/build_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index 40276c8..2fd6212 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -49,11 +49,11 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
b, err := builder.NewBuilder(t)
if err != nil {
- NewtUsage(cmd, err)
+ NewtUsage(nil, err)
}
err = b.Build()
if err != nil {
- NewtUsage(cmd, err)
+ NewtUsage(nil, err)
}
util.StatusMessage(util.VERBOSITY_DEFAULT, "App successfully built: %s\n",
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2bca5cc7/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 3f56731..6b88b9e 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -33,6 +33,7 @@ import (
)
const TARGET_FILENAME string = "target.yml"
+const DEFAULT_BUILD_PROFILE string = "default"
var globalTargetMap map[string]*Target
@@ -52,7 +53,9 @@ type Target struct {
}
func NewTarget(basePkg *pkg.LocalPackage) *Target {
- target := &Target{}
+ target := &Target{
+ BuildProfile: DEFAULT_BUILD_PROFILE,
+ }
target.Init(basePkg)
return target
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2bca5cc7/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index bada60b..7f76fb3 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -113,6 +113,12 @@ func (c *Compiler) load(compilerDir string, buildProfile string) error {
c.ocPath = v.GetString("compiler.path.objcopy")
cflags := v.GetStringSlice("compiler.flags." + buildProfile)
+ if len(cflags) == 0 {
+ // Assume no flags implies an unsupported build profile.
+ return util.FmtNewtError("Compiler doesn't support build profile "+
+ "specified by target (build_profile=\"%s\")", buildProfile)
+ }
+
for _, flag := range cflags {
if strings.HasPrefix(flag, "compiler.flags") {
c.info.Cflags = append(c.info.Cflags,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2bca5cc7/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index 805654b..582a70f 100644
--- a/util/util.go
+++ b/util/util.go
@@ -74,6 +74,10 @@ func NewNewtError(msg string) *NewtError {
return err
}
+func FmtNewtError(format string, args ...interface{}) *NewtError {
+ return NewNewtError(fmt.Sprintf(format, args...))
+}
+
// Print Silent, Quiet and Verbose aware status messages to stdout.
func StatusMessage(level int, message string, args ...interface{}) {
if Verbosity >= level {
[2/3] incubator-mynewt-newt git commit: Trim "target." prefix in
target show output.
Posted by cc...@apache.org.
Trim "target." prefix in target show output.
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/b4d33a1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/b4d33a1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/b4d33a1e
Branch: refs/heads/develop
Commit: b4d33a1e6dd175539b8cb8cdf2ef24a65917d034
Parents: 2bca5cc
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Mar 9 19:17:48 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Mar 9 19:17:48 2016 -0800
----------------------------------------------------------------------
newt/cli/target_cmds.go | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b4d33a1e/newt/cli/target_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 23e501a..81ef400 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -97,8 +97,10 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
sort.Strings(keys)
for _, k := range keys {
- util.StatusMessage(util.VERBOSITY_QUIET, " %s=%s\n", k,
- target.Vars[k])
+ varName := strings.TrimPrefix(k, "target.")
+ value := target.Vars[k]
+ util.StatusMessage(util.VERBOSITY_QUIET, " %s=%s\n",
+ varName, value)
}
}
}
[3/3] incubator-mynewt-newt git commit: 1.Depend on yml files;
2.include app's lflags.
Posted by cc...@apache.org.
1.Depend on yml files; 2.include app's lflags.
1. If a source yml file changes, a full rebuild is required.
2. There was a bug; the app package's linker flags were not being fed to
the linker.
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/a8b5adac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a8b5adac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a8b5adac
Branch: refs/heads/develop
Commit: a8b5adac81c6d6991e422fa431cf4d03038d0cf5
Parents: b4d33a1
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Mar 9 21:29:03 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Mar 9 21:29:03 2016 -0800
----------------------------------------------------------------------
newt/builder/build.go | 38 +++++++++++++++++++--------
newt/pkg/localpackage.go | 15 +++++++++++
newt/target/target.go | 4 +++
newt/toolchain/compiler.go | 26 ++++++++++++++++++
newt/toolchain/deps.go | 58 +++++++++++++++++++++++++++++++----------
5 files changed, 116 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a8b5adac/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 391dbeb..78d8c9a 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -34,6 +34,7 @@ type Builder struct {
features map[string]bool
apis map[string]*BuildPackage
+ appPkg *BuildPackage
Bsp *pkg.BspPackage
compilerPkg *pkg.LocalPackage
compilerInfo *toolchain.CompilerInfo
@@ -201,6 +202,29 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
return nil
}
+func (b *Builder) newCompiler(bpkg *BuildPackage, dstDir string) (*toolchain.Compiler, error) {
+ c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(), dstDir,
+ b.target.BuildProfile)
+ if err != nil {
+ return nil, err
+ }
+ c.AddInfo(b.compilerInfo)
+
+ ci, err := bpkg.CompilerInfo(b)
+ if err != nil {
+ return nil, err
+ }
+ c.AddInfo(ci)
+
+ // Specify all the source yml files as dependencies. If a yml file has
+ // changed, a full rebuild is required.
+ for _, bp := range b.Packages {
+ c.AddDeps(bp.CfgFilenames()...)
+ }
+
+ return c, nil
+}
+
// Compiles and archives a package.
func (b *Builder) buildPackage(bpkg *BuildPackage) error {
srcDir := bpkg.BasePath() + "/src"
@@ -209,18 +233,10 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
return nil
}
- c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
- b.PkgBinDir(bpkg.Name()), b.target.BuildProfile)
+ c, err := b.newCompiler(bpkg, b.PkgBinDir(bpkg.Name()))
if err != nil {
return err
}
- c.AddInfo(b.compilerInfo)
-
- ci, err := bpkg.CompilerInfo(b)
- if err != nil {
- return err
- }
- c.AddInfo(ci)
// Build the package source in two phases:
// 1. Non-test code.
@@ -254,8 +270,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
}
func (b *Builder) link(elfName string) error {
- c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
- b.PkgBinDir(elfName), b.target.BuildProfile)
+ c, err := b.newCompiler(b.appPkg, b.PkgBinDir(elfName))
if err != nil {
return err
}
@@ -321,6 +336,7 @@ func (b *Builder) PrepBuild() error {
if appBpkg == nil {
appBpkg = b.AddPackage(appPkg)
}
+ b.appPkg = appBpkg
}
bspBpkg := b.Packages[bspPkg]
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a8b5adac/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 2ecd3f8..d2547af 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -65,6 +65,9 @@ type LocalPackage struct {
// Pointer to pkg.yml configuration structure
Viper *viper.Viper
+
+ // Names of all source yml files; used to determine if rebuild required.
+ cfgFilenames []string
}
func NewLocalPackage(r *repo.Repo, pkgDir string) *LocalPackage {
@@ -156,6 +159,14 @@ func (pkg *LocalPackage) Hash() (string, error) {
return hashStr, nil
}
+func (pkg *LocalPackage) CfgFilenames() []string {
+ return pkg.cfgFilenames
+}
+
+func (pkg *LocalPackage) AddCfgFilename(cfgFilename string) {
+ pkg.cfgFilenames = append(pkg.cfgFilenames, cfgFilename)
+}
+
func (pkg *LocalPackage) HasDep(searchDep *Dependency) bool {
for _, dep := range pkg.deps {
if dep.String() == searchDep.String() {
@@ -166,6 +177,8 @@ func (pkg *LocalPackage) HasDep(searchDep *Dependency) bool {
}
func (pkg *LocalPackage) AddDep(dep *Dependency) {
+ // Remember the name of the configuration file so that it can be specified
+ // as a dependency to the compiler.
pkg.deps = append(pkg.deps, dep)
}
@@ -269,6 +282,8 @@ func (pkg *LocalPackage) Load() error {
return err
}
+ pkg.AddCfgFilename(pkg.basePath + PACKAGE_FILE_NAME)
+
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a8b5adac/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 6b88b9e..c91f892 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -92,6 +92,10 @@ func (target *Target) Load(basePkg *pkg.LocalPackage) error {
target.Arch = target.Vars["target.arch"]
target.BuildProfile = target.Vars["target.build_profile"]
+ // Remember the name of the configuration file so that it can be specified
+ // as a dependency to the compiler.
+ target.basePkg.AddCfgFilename(basePkg.BasePath() + TARGET_FILENAME)
+
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a8b5adac/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index 7f76fb3..42df688 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -32,6 +32,8 @@ import (
"mynewt.apache.org/newt/util"
)
+const COMPILER_FILENAME string = "compiler.yml"
+
const (
COMPILER_TYPE_C = 0
COMPILER_TYPE_ASM = 1
@@ -60,6 +62,8 @@ type Compiler struct {
dstDir string
info CompilerInfo
+
+ extraDeps []string
}
func NewCompilerInfo() *CompilerInfo {
@@ -85,6 +89,7 @@ func NewCompiler(compilerDir string, dstDir string,
c := &Compiler{
ObjPathList: map[string]bool{},
dstDir: filepath.Clean(dstDir),
+ extraDeps: []string{compilerDir + COMPILER_FILENAME},
}
c.depTracker = NewDepTracker(c)
@@ -146,6 +151,10 @@ func (c *Compiler) DstDir() string {
return c.dstDir
}
+func (c *Compiler) AddDeps(depFilenames ...string) {
+ c.extraDeps = append(c.extraDeps, depFilenames...)
+}
+
// Skips compilation of the specified C or assembly file, but adds the name of
// the object file that would have been generated to the compiler's list of
// object files. This function is used when the object file is already up to
@@ -189,6 +198,11 @@ func (c *Compiler) lflagsString() string {
return strings.Join(lflags, " ")
}
+func (c *Compiler) depsString() string {
+ extraDeps := util.SortFields(c.extraDeps...)
+ return strings.Join(extraDeps, " ") + "\n"
+}
+
// Calculates the command-line invocation necessary to compile the specified C
// or assembly file.
//
@@ -241,6 +255,18 @@ func (c *Compiler) GenDepsForFile(file string) error {
return err
}
+ // Append the extra dependencies (.yml files) to the .d file.
+ f, err := os.OpenFile(depFile, os.O_APPEND|os.O_WRONLY, 0666)
+ if err != nil {
+ return util.NewNewtError(err.Error())
+ }
+ defer f.Close()
+
+ objFile := strings.TrimSuffix(file, filepath.Ext(file)) + ".o"
+ if _, err := f.WriteString(objFile + ": " + c.depsString()); err != nil {
+ return util.NewNewtError(err.Error())
+ }
+
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a8b5adac/newt/toolchain/deps.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/deps.go b/newt/toolchain/deps.go
index fa639a5..814dd3f 100644
--- a/newt/toolchain/deps.go
+++ b/newt/toolchain/deps.go
@@ -45,14 +45,36 @@ func NewDepTracker(c *Compiler) DepTracker {
return tracker
}
+// @return string The name of the dependent file (i.e., the first
+// .o file encountered).
+// @return []string Populated with the dependencies' filenames.
+func parseDepsLine(line string) (string, []string, error) {
+ tokens := strings.Fields(line)
+ if len(tokens) == 0 {
+ return "", nil, nil
+ }
+
+ dFileTok := tokens[0]
+ if dFileTok[len(dFileTok)-1:] != ":" {
+ return "", nil, util.NewNewtError("Invalid Makefile dependency file; " +
+ "line missing ':'")
+ }
+
+ dFileName := dFileTok[:len(dFileTok)-1]
+ return dFileName, tokens[1:], nil
+
+}
+
// Parses a dependency (.d) file generated by gcc. On success, the returned
// string array is populated with the dependency filenames. This function
-// expects the first line of a dependency file to have the following format:
+// expects each line of a dependency file to have the following format:
//
-// <file>.d: <file>.c a.h b.h c.h \
+// <file>.o: <file>.c a.h b.h c.h \
// d.h e.h f.h
//
-// This function ignores all lines except for the first.
+// Only the first dependent object(<file>.o) is considered.
+//
+// @return []string Populated with the dependencies' filenames.
func ParseDepsFile(filename string) ([]string, error) {
lines, err := util.ReadLines(filename)
if err != nil {
@@ -63,20 +85,24 @@ func ParseDepsFile(filename string) ([]string, error) {
return []string{}, nil
}
- // Assume only the first line is important.
- tokens := strings.Fields(lines[0])
- if len(tokens) == 0 {
- return nil, util.NewNewtError("Invalid Makefile dependency file; first " +
- "line is blank")
- }
+ var dFile string
+ allDeps := []string{}
+ for _, line := range lines {
+ src, deps, err := parseDepsLine(line)
+ if err != nil {
+ return nil, err
+ }
- dFileTok := tokens[0]
- if dFileTok[len(dFileTok)-1:] != ":" {
- return nil, util.NewNewtError("Invalid Makefile dependency file; first " +
- "line missing ':'")
+ if dFile == "" {
+ dFile = src
+ }
+
+ if src == dFile {
+ allDeps = append(allDeps, deps...)
+ }
}
- return tokens[1:], nil
+ return allDeps, nil
}
// Updates the dependency tracker's most recent timestamp according to the
@@ -141,6 +167,10 @@ func (tracker *DepTracker) CompileRequired(srcFile string,
if commandHasChanged(objFile, cmd) {
util.StatusMessage(util.VERBOSITY_VERBOSE, "%s - rebuild required; "+
"different command\n", srcFile)
+ err := tracker.compiler.GenDepsForFile(srcFile)
+ if err != nil {
+ return false, err
+ }
return true, nil
}