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/12/19 23:31:37 UTC
incubator-mynewt-newt git commit: Revert "MYNEWT-512 newt - Remove
sysinit code generation."
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 856ea2f0f -> f985e2c27
Revert "MYNEWT-512 newt - Remove sysinit code generation."
This reverts commit d4d54282e5ad47bbd4dd6144746b35b3c4224b7e.
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/f985e2c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f985e2c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f985e2c2
Branch: refs/heads/develop
Commit: f985e2c27af03ff20f30b5614ee72bb0d5788f59
Parents: 856ea2f
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Dec 19 15:26:34 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Dec 19 15:26:34 2016 -0800
----------------------------------------------------------------------
newt/builder/targetbuild.go | 23 ++++++
newt/newtutil/newtutil.go | 11 ++-
newt/sysinit/sysinit.go | 171 +++++++++++++++++++++++++++++++++++++++
3 files changed, 201 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f985e2c2/newt/builder/targetbuild.go
----------------------------------------------------------------------
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index de52df0..9579bed 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -38,6 +38,7 @@ import (
"mynewt.apache.org/newt/newt/resolve"
"mynewt.apache.org/newt/newt/symbol"
"mynewt.apache.org/newt/newt/syscfg"
+ "mynewt.apache.org/newt/newt/sysinit"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/newt/toolchain"
"mynewt.apache.org/newt/util"
@@ -209,6 +210,24 @@ func (t *TargetBuilder) validateAndWriteCfg() error {
return nil
}
+func (t *TargetBuilder) generateSysinit() error {
+ if err := t.ensureResolved(); err != nil {
+ return err
+ }
+
+ srcDir := GeneratedSrcDir(t.target.Name())
+
+ if t.res.LoaderPkgs != nil {
+ sysinit.EnsureWritten(t.res.LoaderPkgs, srcDir,
+ pkg.ShortName(t.target.Package()), true)
+ }
+
+ sysinit.EnsureWritten(t.res.AppPkgs, srcDir,
+ pkg.ShortName(t.target.Package()), false)
+
+ return nil
+}
+
func (t *TargetBuilder) generateFlashMap() error {
return t.bspPkg.FlashMap.EnsureWritten(
GeneratedSrcDir(t.target.Name()),
@@ -217,6 +236,10 @@ func (t *TargetBuilder) generateFlashMap() error {
}
func (t *TargetBuilder) generateCode() error {
+ if err := t.generateSysinit(); err != nil {
+ return err
+ }
+
if err := t.generateFlashMap(); err != nil {
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f985e2c2/newt/newtutil/newtutil.go
----------------------------------------------------------------------
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index 9278a19..0182514 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -51,15 +51,18 @@ type RepoCommitEntry struct {
// A warning is displayed if newt requires a newer version of a repo.
var RepoMinCommits = map[string]*RepoCommitEntry{
+ // Newt no longer cd's to a source directory when it compiles its contents.
+ // Consequently, package include flags need to be relative to the project
+ // directory, not the package source directory.
CORE_REPO_NAME: &RepoCommitEntry{
Version: "develop",
- Hash: "43a5ef8860cbf4bc5bf43fde8a29fe74361536fa",
- Description: "Sysinit section in linker scripts.",
+ Hash: "cd99344df197d5b9e372b93142184a39ec078f69",
+ Description: "Include paths now relative to project base.",
},
ARDUINO_ZERO_REPO_NAME: &RepoCommitEntry{
Version: "develop",
- Hash: "5ba55a5201fd99c23688518d30f13356ce3a34c9",
- Description: "Sysinit section in linker scripts.",
+ Hash: "a6348961fef56dbfe09a1b9418d3add3ad22eaf2",
+ Description: "Include paths now relative to project base.",
},
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f985e2c2/newt/sysinit/sysinit.go
----------------------------------------------------------------------
diff --git a/newt/sysinit/sysinit.go b/newt/sysinit/sysinit.go
new file mode 100644
index 0000000..9835a3a
--- /dev/null
+++ b/newt/sysinit/sysinit.go
@@ -0,0 +1,171 @@
+/**
+ * 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 sysinit
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "sort"
+
+ log "github.com/Sirupsen/logrus"
+
+ "mynewt.apache.org/newt/newt/newtutil"
+ "mynewt.apache.org/newt/newt/pkg"
+ "mynewt.apache.org/newt/util"
+)
+
+func buildStageMap(pkgs []*pkg.LocalPackage) map[int][]*pkg.LocalPackage {
+ sm := map[int][]*pkg.LocalPackage{}
+
+ for _, p := range pkgs {
+ stage := p.InitStage()
+ sm[stage] = append(sm[stage], p)
+ }
+
+ return sm
+}
+
+func writePrototypes(pkgs []*pkg.LocalPackage, w io.Writer) {
+ sorted := pkg.SortLclPkgs(pkgs)
+ fmt.Fprintf(w, "void os_init(void);\n")
+ for _, p := range sorted {
+ fmt.Fprintf(w, "void %s(void);\n", p.InitFnName())
+ }
+}
+
+func writeStage(stage int, pkgs []*pkg.LocalPackage, w io.Writer) {
+ sorted := pkg.SortLclPkgs(pkgs)
+
+ fmt.Fprintf(w, " /*** Stage %d */\n", stage)
+ for i, p := range sorted {
+ fmt.Fprintf(w, " /* %d.%d: %s */\n", stage, i, p.Name())
+ fmt.Fprintf(w, " %s();\n", p.InitFnName())
+ }
+}
+
+func onlyPkgsWithInit(pkgs []*pkg.LocalPackage) []*pkg.LocalPackage {
+ good := make([]*pkg.LocalPackage, 0, len(pkgs))
+ for _, p := range pkgs {
+ if p.InitFnName() != "" {
+ good = append(good, p)
+ }
+ }
+
+ return good
+}
+
+func write(pkgs []*pkg.LocalPackage, isLoader bool,
+ w io.Writer) {
+
+ goodPkgs := onlyPkgsWithInit(pkgs)
+ stageMap := buildStageMap(goodPkgs)
+
+ i := 0
+ stages := make([]int, len(stageMap))
+ for k, _ := range stageMap {
+ stages[i] = k
+ i++
+ }
+ sort.Ints(stages)
+
+ fmt.Fprintf(w, newtutil.GeneratedPreamble())
+
+ if isLoader {
+ fmt.Fprintf(w, "#if SPLIT_LOADER\n\n")
+ } else {
+ fmt.Fprintf(w, "#if !SPLIT_LOADER\n\n")
+ }
+
+ writePrototypes(goodPkgs, w)
+
+ var fnName string
+ if isLoader {
+ fnName = "sysinit_loader"
+ } else {
+ fnName = "sysinit_app"
+ }
+
+ fmt.Fprintf(w, "\n")
+ fmt.Fprintf(w, "void\n%s(void)\n{\n", fnName)
+ fmt.Fprintf(w, " os_init();\n")
+
+ for _, s := range stages {
+ fmt.Fprintf(w, "\n")
+ writeStage(s, stageMap[s], w)
+ }
+
+ fmt.Fprintf(w, "}\n\n")
+ fmt.Fprintf(w, "#endif\n")
+}
+
+func writeRequired(contents []byte, path string) (bool, error) {
+ oldSrc, err := ioutil.ReadFile(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ // File doesn't exist; write required.
+ return true, nil
+ }
+
+ return true, util.NewNewtError(err.Error())
+ }
+
+ rc := bytes.Compare(oldSrc, contents)
+ return rc != 0, nil
+}
+
+func EnsureWritten(pkgs []*pkg.LocalPackage, srcDir string, targetName string,
+ isLoader bool) error {
+
+ buf := bytes.Buffer{}
+ write(pkgs, isLoader, &buf)
+
+ var path string
+ if isLoader {
+ path = fmt.Sprintf("%s/%s-sysinit-loader.c", srcDir, targetName)
+ } else {
+ path = fmt.Sprintf("%s/%s-sysinit-app.c", srcDir, targetName)
+ }
+
+ writeReqd, err := writeRequired(buf.Bytes(), path)
+ if err != nil {
+ return err
+ }
+
+ if !writeReqd {
+ log.Debugf("sysinit unchanged; not writing src file (%s).", path)
+ return nil
+ }
+
+ log.Debugf("sysinit changed; writing src file (%s).", path)
+
+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+ return util.NewNewtError(err.Error())
+ }
+
+ if err := ioutil.WriteFile(path, buf.Bytes(), 0644); err != nil {
+ return util.NewNewtError(err.Error())
+ }
+
+ return nil
+}