You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/11/10 01:12:41 UTC

incubator-mynewt-newt git commit: MYNEWT-476; if package source has .a's, include them when linking.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop f9159f5d8 -> 93cf30fbe


MYNEWT-476; if package source has .a's, include them when linking.


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/93cf30fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/93cf30fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/93cf30fb

Branch: refs/heads/develop
Commit: 93cf30fbe0b908de14f7bf630348da7efd0602d6
Parents: f9159f5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 9 17:10:18 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 9 17:10:18 2016 -0800

----------------------------------------------------------------------
 newt/builder/build.go      | 23 ++++++++++++-----
 newt/toolchain/compiler.go | 57 +++++++++++++++++++++++++++++++++++++----
 newt/toolchain/deps.go     | 27 +++++++++++++++++++
 3 files changed, 95 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/93cf30fb/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index d5bc998..82798fb 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -176,6 +176,12 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
 		return err
 	}
 
+	// Copy in pre-compiled library files
+	if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ARCHIVE,
+		append(ignDirs, "arch")); err != nil {
+		return err
+	}
+
 	archDir := srcDir + "/arch/" + arch + "/"
 	if util.NodeExist(archDir) {
 		util.StatusMessage(util.VERBOSITY_VERBOSE,
@@ -204,6 +210,12 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
 
 			return err
 		}
+
+		// Copy in pre-compiled library files
+		if err := c.RecursiveCompile(toolchain.COMPILER_TYPE_ARCHIVE,
+			ignDirs); err != nil {
+			return err
+		}
 	}
 
 	return nil
@@ -322,9 +334,8 @@ func (b *Builder) link(elfName string, linkerScripts []string,
 	pkgNames := []string{}
 
 	for _, bpkg := range b.PkgMap {
-		if util.NodeExist(b.ArchivePath(bpkg)) {
-			pkgNames = append(pkgNames, b.ArchivePath(bpkg))
-		}
+		archiveNames, _ := filepath.Glob(b.PkgBinDir(bpkg) + "/*.a")
+		pkgNames = append(pkgNames, archiveNames...)
 	}
 
 	c.LinkerScripts = linkerScripts
@@ -583,10 +594,8 @@ func (b *Builder) buildRomElf(common *symbol.SymbolMap) error {
 
 	/* build the set of archive file names */
 	for _, bpkg := range b.PkgMap {
-		archivePath := b.ArchivePath(bpkg)
-		if util.NodeExist(archivePath) {
-			archNames = append(archNames, archivePath)
-		}
+		archiveNames, _ := filepath.Glob(b.PkgBinDir(bpkg) + "/*.a")
+		archNames = append(archNames, archiveNames...)
 	}
 
 	bld, err := d.RomElfBuildRequired(b.AppLinkerElfPath(),

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/93cf30fb/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index c139a28..42af123 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -42,9 +42,10 @@ import (
 const COMPILER_FILENAME string = "compiler.yml"
 
 const (
-	COMPILER_TYPE_C   = 0
-	COMPILER_TYPE_ASM = 1
-	COMPILER_TYPE_CPP = 2
+	COMPILER_TYPE_C       = 0
+	COMPILER_TYPE_ASM     = 1
+	COMPILER_TYPE_CPP     = 2
+	COMPILER_TYPE_ARCHIVE = 3
 )
 
 type CompilerInfo struct {
@@ -595,6 +596,46 @@ func (c *Compiler) CompileAs() error {
 	return nil
 }
 
+// Copies all archive files matching the specified file glob.
+//
+// @param match                 The file glob specifying which assembly files
+//                                  to compile.
+func (c *Compiler) CopyArchive() error {
+	files, _ := filepath.Glob("*.a")
+
+	wd, err := os.Getwd()
+	if err != nil {
+		return err
+	}
+
+	log.Infof("Copying archive if outdated (%s/*.a) %s", wd,
+		strings.Join(files, " "))
+	for _, file := range files {
+		if shouldIgnore := c.shouldIgnoreFile(file); shouldIgnore {
+			log.Infof("Ignoring %s because package dictates it.", file)
+			continue
+		}
+
+		tgtFile := c.DstDir() + "/" +
+			strings.TrimSuffix(file, filepath.Ext(file)) + ".a"
+		copyRequired, err := c.depTracker.CopyRequired(file)
+		if err != nil {
+			return err
+		}
+		if copyRequired {
+			err = util.CopyFile(file, tgtFile)
+			util.StatusMessage(util.VERBOSITY_DEFAULT, "copying %s\n",
+				filepath.ToSlash(tgtFile))
+		}
+
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
 func (c *Compiler) processEntry(wd string, node os.FileInfo, cType int,
 	ignDirs []string) error {
 
@@ -657,6 +698,8 @@ func (c *Compiler) RecursiveCompile(cType int, ignDirs []string) error {
 		return c.CompileAs()
 	case COMPILER_TYPE_CPP:
 		return c.CompileCpp()
+	case COMPILER_TYPE_ARCHIVE:
+		return c.CopyArchive()
 	default:
 		return util.NewNewtError("Wrong compiler type specified to " +
 			"RecursiveCompile")
@@ -978,14 +1021,18 @@ func (c *Compiler) CompileArchive(archiveFile string) error {
 		return util.NewNewtError(err.Error())
 	}
 
+	// Delete the old archive, if it exists.
+	err = os.Remove(archiveFile)
+
 	util.StatusMessage(util.VERBOSITY_DEFAULT, "Archiving %s\n",
 		path.Base(archiveFile))
 	objList := c.getObjFiles([]string{})
+	if objList == "" {
+		return nil
+	}
 	util.StatusMessage(util.VERBOSITY_VERBOSE, "Archiving %s with object "+
 		"files %s\n", archiveFile, objList)
 
-	// Delete the old archive, if it exists.
-	err = os.Remove(archiveFile)
 	if err != nil && !os.IsNotExist(err) {
 		return util.NewNewtError(err.Error())
 	}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/93cf30fb/newt/toolchain/deps.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/deps.go b/newt/toolchain/deps.go
index a0ab37c..86ec2cc 100644
--- a/newt/toolchain/deps.go
+++ b/newt/toolchain/deps.go
@@ -418,3 +418,30 @@ func (tracker *DepTracker) RomElfBuildRequired(dstFile string, elfFile string,
 	}
 	return false, nil
 }
+
+// Determines if the specified static library needs to be copied.  The
+// library needs to be archived if any of the following is true:
+//     * The destination library file does not exist.
+//     * Source object files has a newer modification time than the
+//       target file.
+func (tracker *DepTracker) CopyRequired(srcFile string) (bool, error) {
+
+	tgtFile := tracker.compiler.DstDir() + "/" + filepath.Base(srcFile)
+
+	// If the target doesn't exist or is older than source file, a copy
+	// is required.
+	srcModTime, err := util.FileModificationTime(srcFile)
+	if err != nil {
+		return false, err
+	}
+	tgtModTime, err := util.FileModificationTime(tgtFile)
+	if err != nil {
+		return false, err
+	}
+	if srcModTime.After(tgtModTime) {
+		return true, nil
+	}
+
+	// The target is up to date.
+	return false, nil
+}