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/03/09 21:23:21 UTC

[06/50] incubator-mynewt-newt git commit: Rearrange some code; build.go was getting confusing.

Rearrange some code; build.go was getting confusing.


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

Branch: refs/heads/develop
Commit: c8a0ed9592fb31ad85d9d9232a88d5271ca9a44e
Parents: 928e034
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Mar 7 21:25:48 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Mar 7 21:28:10 2016 -0800

----------------------------------------------------------------------
 newt/builder/build.go     | 121 +++++++----------------------------------
 newt/builder/buildutil.go | 108 ++++++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/c8a0ed95/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 46e8133..b256a53 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -20,13 +20,11 @@
 package builder
 
 import (
-	"bytes"
 	"os"
 	"path/filepath"
 
 	"mynewt.apache.org/newt/newt/cli"
 	"mynewt.apache.org/newt/newt/pkg"
-	"mynewt.apache.org/newt/newt/project"
 	"mynewt.apache.org/newt/newt/target"
 	"mynewt.apache.org/newt/newt/toolchain"
 	"mynewt.apache.org/newt/util"
@@ -44,6 +42,26 @@ type Builder struct {
 	target *target.Target
 }
 
+func NewBuilder(target *target.Target) (*Builder, error) {
+	b := &Builder{}
+
+	if err := b.Init(target); err != nil {
+		return nil, err
+	}
+
+	return b, nil
+}
+
+func (b *Builder) Init(target *target.Target) error {
+	b.target = target
+
+	b.Packages = map[*pkg.LocalPackage]*BuildPackage{}
+	b.features = map[string]bool{}
+	b.apis = map[string]*BuildPackage{}
+
+	return nil
+}
+
 func (b *Builder) Features() map[string]bool {
 	return b.features
 }
@@ -83,25 +101,6 @@ func (b *Builder) AddApi(apiString string, bpkg *BuildPackage) bool {
 	}
 }
 
-func (b *Builder) logFeatures() {
-	var buffer bytes.Buffer
-	buffer.WriteString("Building with the following feature set: [")
-
-	first := true
-	for feature, _ := range b.Features() {
-		if !first {
-			buffer.WriteString(" ")
-		} else {
-			first = false
-		}
-
-		buffer.WriteString(feature)
-	}
-	buffer.WriteString("]\n")
-
-	cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
-}
-
 func (b *Builder) loadDeps() error {
 	// Circularly resolve dependencies, identities, APIs, and required APIs
 	// until no new ones exist.
@@ -128,44 +127,6 @@ func (b *Builder) loadDeps() error {
 	return nil
 }
 
-// Makes sure all packages with required APIs have been augmented a dependency
-// which satisfies that requirement.  If there are any unsatisfied
-// requirements, an error is returned.
-func (b *Builder) verifyApisSatisfied() error {
-	unsatisfied := map[*BuildPackage][]string{}
-
-	for _, bpkg := range b.Packages {
-		for api, status := range bpkg.reqApiMap {
-			if status == REQ_API_STATUS_UNSATISFIED {
-				slice := unsatisfied[bpkg]
-				if slice == nil {
-					unsatisfied[bpkg] = []string{api}
-				} else {
-					slice = append(slice, api)
-				}
-			}
-		}
-	}
-
-	if len(unsatisfied) != 0 {
-		var buffer bytes.Buffer
-		for bpkg, apis := range unsatisfied {
-			buffer.WriteString("Package " + bpkg.Name() +
-				" has unsatisfied required APIs: ")
-			for i, api := range apis {
-				if i != 0 {
-					buffer.WriteString(", ")
-				}
-				buffer.WriteString(api)
-			}
-			buffer.WriteString("\n")
-		}
-		return util.NewNewtError(buffer.String())
-	}
-
-	return nil
-}
-
 // Recursively compiles all the .c and .s files in the specified directory.
 // Architecture-specific files are also compiled.
 func buildDir(srcDir string, c *toolchain.Compiler, arch string,
@@ -223,28 +184,6 @@ func buildDir(srcDir string, c *toolchain.Compiler, arch string,
 	return nil
 }
 
-func (b *Builder) binDir() string {
-	return project.GetProject().Path() + "/bin/" + b.target.ShortName()
-}
-
-func (b *Builder) pkgBinDir(pkgName string) string {
-	return b.binDir() + "/" + pkgName
-}
-
-// Generates the path+filename of the specified package's .a file.
-func (b *Builder) archivePath(pkgName string) string {
-	return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
-}
-
-func (b *Builder) appElfPath() string {
-	pkgName := b.target.App().Name()
-	return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
-}
-
-func (b *Builder) testExePath(pkgName string) string {
-	return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
-}
-
 // Compiles and archives a package.
 func (b *Builder) buildPackage(bpkg *BuildPackage) error {
 	srcDir := bpkg.BasePath() + "/src"
@@ -514,23 +453,3 @@ func (b *Builder) Clean() error {
 	err := os.RemoveAll(path)
 	return err
 }
-
-func (b *Builder) Init(target *target.Target) error {
-	b.target = target
-
-	b.Packages = map[*pkg.LocalPackage]*BuildPackage{}
-	b.features = map[string]bool{}
-	b.apis = map[string]*BuildPackage{}
-
-	return nil
-}
-
-func NewBuilder(target *target.Target) (*Builder, error) {
-	b := &Builder{}
-
-	if err := b.Init(target); err != nil {
-		return nil, err
-	}
-
-	return b, nil
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/c8a0ed95/newt/builder/buildutil.go
----------------------------------------------------------------------
diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
new file mode 100644
index 0000000..06de849
--- /dev/null
+++ b/newt/builder/buildutil.go
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package builder
+
+import (
+	"bytes"
+	"path/filepath"
+
+	"mynewt.apache.org/newt/newt/cli"
+	"mynewt.apache.org/newt/newt/project"
+	"mynewt.apache.org/newt/util"
+)
+
+func (b *Builder) binDir() string {
+	return project.GetProject().Path() + "/bin/" + b.target.ShortName()
+}
+
+func (b *Builder) pkgBinDir(pkgName string) string {
+	return b.binDir() + "/" + pkgName
+}
+
+// Generates the path+filename of the specified package's .a file.
+func (b *Builder) archivePath(pkgName string) string {
+	return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".a"
+}
+
+func (b *Builder) appElfPath() string {
+	pkgName := b.target.App().Name()
+	return b.pkgBinDir(pkgName) + "/" + filepath.Base(pkgName) + ".elf"
+}
+
+func (b *Builder) testExePath(pkgName string) string {
+	return b.pkgBinDir(pkgName) + "/test_" + filepath.Base(pkgName)
+}
+
+func (b *Builder) logFeatures() {
+	var buffer bytes.Buffer
+	buffer.WriteString("Building with the following feature set: [")
+
+	first := true
+	for feature, _ := range b.Features() {
+		if !first {
+			buffer.WriteString(" ")
+		} else {
+			first = false
+		}
+
+		buffer.WriteString(feature)
+	}
+	buffer.WriteString("]\n")
+
+	cli.StatusMessage(cli.VERBOSITY_VERBOSE, buffer.String())
+}
+
+// Makes sure all packages with required APIs have been augmented a dependency
+// which satisfies that requirement.  If there are any unsatisfied
+// requirements, an error is returned.
+func (b *Builder) verifyApisSatisfied() error {
+	unsatisfied := map[*BuildPackage][]string{}
+
+	for _, bpkg := range b.Packages {
+		for api, status := range bpkg.reqApiMap {
+			if status == REQ_API_STATUS_UNSATISFIED {
+				slice := unsatisfied[bpkg]
+				if slice == nil {
+					unsatisfied[bpkg] = []string{api}
+				} else {
+					slice = append(slice, api)
+				}
+			}
+		}
+	}
+
+	if len(unsatisfied) != 0 {
+		var buffer bytes.Buffer
+		for bpkg, apis := range unsatisfied {
+			buffer.WriteString("Package " + bpkg.Name() +
+				" has unsatisfied required APIs: ")
+			for i, api := range apis {
+				if i != 0 {
+					buffer.WriteString(", ")
+				}
+				buffer.WriteString(api)
+			}
+			buffer.WriteString("\n")
+		}
+		return util.NewNewtError(buffer.String())
+	}
+
+	return nil
+}