You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/10/18 19:15:26 UTC
incubator-mynewt-newt git commit: add C++ compilation support to newt
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 878fe2fff -> 1a8b9b727
add C++ compilation support to newt
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/1a8b9b72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1a8b9b72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1a8b9b72
Branch: refs/heads/develop
Commit: 1a8b9b727f1429e2510dd0116c410e3b0043cf28
Parents: 878fe2f
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Oct 18 12:15:20 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Oct 18 12:15:20 2016 -0700
----------------------------------------------------------------------
newt/builder/build.go | 12 +++++++++
newt/toolchain/compiler.go | 54 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1a8b9b72/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 445d9a2..e78206f 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -169,6 +169,12 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
return err
}
+ // Compile CPP files
+ if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_CPP,
+ append(ignDirs, "arch")); err != nil {
+ return err
+ }
+
archDir := srcDir + "/arch/" + arch + "/"
if util.NodeExist(archDir) {
util.StatusMessage(util.VERBOSITY_VERBOSE,
@@ -185,6 +191,12 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
return err
}
+ // Compile CPP source
+ if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_CPP,
+ ignDirs); err != nil {
+ return err
+ }
+
// Compile assembly source (only architecture-specific).
if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ASM,
ignDirs); err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1a8b9b72/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index c2cfa7d..e1c43a9 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -44,6 +44,7 @@ const COMPILER_FILENAME string = "compiler.yml"
const (
COMPILER_TYPE_C = 0
COMPILER_TYPE_ASM = 1
+ COMPILER_TYPE_CPP = 2
)
type CompilerInfo struct {
@@ -61,6 +62,7 @@ type Compiler struct {
depTracker DepTracker
ccPath string
+ cppPath string
asPath string
arPath string
odPath string
@@ -219,6 +221,7 @@ func (c *Compiler) load(compilerDir string, buildProfile string) error {
}
c.ccPath = newtutil.GetStringFeatures(v, features, "compiler.path.cc")
+ c.cppPath = newtutil.GetStringFeatures(v, features, "compiler.path.cpp")
c.asPath = newtutil.GetStringFeatures(v, features, "compiler.path.as")
c.arPath = newtutil.GetStringFeatures(v, features, "compiler.path.archive")
c.odPath = newtutil.GetStringFeatures(v, features, "compiler.path.objdump")
@@ -337,6 +340,8 @@ func (c *Compiler) CompileFileCmd(file string,
cmd = c.ccPath
case COMPILER_TYPE_ASM:
cmd = c.asPath
+ case COMPILER_TYPE_CPP:
+ cmd = c.cppPath
default:
return "", util.NewNewtError("Unknown compiler type")
}
@@ -434,6 +439,8 @@ func (c *Compiler) CompileFile(file string, compilerType int) error {
switch compilerType {
case COMPILER_TYPE_C:
util.StatusMessage(util.VERBOSITY_DEFAULT, "Compiling %s\n", file)
+ case COMPILER_TYPE_CPP:
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Compiling %s\n", file)
case COMPILER_TYPE_ASM:
util.StatusMessage(util.VERBOSITY_DEFAULT, "Assembling %s\n", file)
default:
@@ -468,8 +475,6 @@ func (c *Compiler) shouldIgnoreFile(file string) bool {
// Compiles all C files matching the specified file glob.
//
-// @param match The file glob specifying which C files to
-// compile.
func (c *Compiler) CompileC() error {
files, _ := filepath.Glob("*.c")
@@ -507,6 +512,49 @@ func (c *Compiler) CompileC() error {
return nil
}
+// Compiles all CPP files
+func (c *Compiler) CompileCpp() error {
+ files, _ := filepath.Glob("*.cc")
+ moreFiles, _ := filepath.Glob("*.cpp")
+ files = append(files, moreFiles...)
+ moreFiles, _ = filepath.Glob("*.cxx")
+ files = append(files, moreFiles...)
+
+ wd, err := os.Getwd()
+ if err != nil {
+ return err
+ }
+
+ log.Infof("Compiling CC if outdated (%s/*.cc) %s", wd,
+ strings.Join(files, " "))
+
+ for _, file := range files {
+ file = filepath.ToSlash(file)
+
+ if shouldIgnore := c.shouldIgnoreFile(file); shouldIgnore {
+ log.Infof("Ignoring %s because package dictates it.", file)
+ }
+
+ compileRequired, err := c.depTracker.CompileRequired(file,
+ COMPILER_TYPE_CPP)
+ if err != nil {
+ return err
+ }
+
+ if compileRequired {
+ err = c.CompileFile(file, COMPILER_TYPE_CPP)
+ } else {
+ err = c.SkipSourceFile(file)
+ }
+
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// Compiles all assembly files matching the specified file glob.
//
// @param match The file glob specifying which assembly files
@@ -607,6 +655,8 @@ func (c *Compiler) RecursiveCompile(cType int, ignDirs []string) error {
return c.CompileC()
case COMPILER_TYPE_ASM:
return c.CompileAs()
+ case COMPILER_TYPE_CPP:
+ return c.CompileCpp()
default:
return util.NewNewtError("Wrong compiler type specified to " +
"RecursiveCompile")