You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2023/02/02 12:56:27 UTC

[mynewt-newt] branch master updated (1bc33f9e -> 5cb641e3)

This is an automated email from the ASF dual-hosted git repository.

andk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


    from 1bc33f9e Add wrapper for settings map
     new 1785cb87 builder: Fix names in pkg.yml
     new 5cb641e3 builder: Allow to specify source files for package

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 newt/builder/build.go        | 29 ++++++++++++++++++++++++++++-
 newt/builder/buildpackage.go | 29 ++++++++++++++++++++++++++---
 newt/toolchain/compiler.go   | 30 ++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 4 deletions(-)


[mynewt-newt] 02/02: builder: Allow to specify source files for package

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 5cb641e33f065bd70d8ae0bc79e5135b08960b70
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jan 30 14:25:23 2023 +0100

    builder: Allow to specify source files for package
    
    This adds pkg.source_files to pkg.yml which allows to specify files
    which should be included in build. Once set, it overrides default src/
    directory so it has to be added manually if required.
---
 newt/builder/build.go        | 29 ++++++++++++++++++++++++++++-
 newt/builder/buildpackage.go |  5 +++++
 newt/toolchain/compiler.go   | 30 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/newt/builder/build.go b/newt/builder/build.go
index 8dc94379..5c0f323a 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -341,7 +341,8 @@ func (b *Builder) collectCompileEntriesBpkg(bpkg *BuildPackage) (
 			}
 			srcDirs = append(srcDirs, dir)
 		}
-	} else {
+	} else if len(bpkg.SourceFiles) == 0 {
+		// Add 'src/' automatically only if neither source dirs nor files are defined
 		srcDir := bpkg.rpkg.Lpkg.BasePath() + "/src"
 		if util.NodeNotExist(srcDir) {
 			// Nothing to compile.
@@ -362,6 +363,32 @@ func (b *Builder) collectCompileEntriesBpkg(bpkg *BuildPackage) (
 		entries = append(entries, subEntries...)
 	}
 
+	for _, filename := range bpkg.SourceFiles {
+		var dir string
+		repo, path, err := newtutil.ParsePackageString(filename)
+
+		if err != nil {
+			return nil, err
+		}
+
+		if repo != "" {
+			filename = "repos/" + repo + "/" + path
+		} else {
+			filename = bpkg.rpkg.Lpkg.BasePath() + "/" + filename
+		}
+
+		if util.NodeNotExist(filename) {
+			return nil, util.NewNewtError(fmt.Sprintf(
+				"Specified source directory %s, does not exist.",
+				dir))
+		}
+
+		entry, err := c.CollectSingleEntry(filename)
+		if err == nil {
+			entries = append(entries, *entry)
+		}
+	}
+
 	return entries, nil
 }
 
diff --git a/newt/builder/buildpackage.go b/newt/builder/buildpackage.go
index 94535e62..c731872e 100644
--- a/newt/builder/buildpackage.go
+++ b/newt/builder/buildpackage.go
@@ -35,6 +35,7 @@ import (
 type BuildPackage struct {
 	rpkg              *resolve.ResolvePackage
 	SourceDirectories []string
+	SourceFiles       []string
 	ci                *toolchain.CompilerInfo
 }
 
@@ -220,6 +221,10 @@ func (bpkg *BuildPackage) CompilerInfo(
 		util.OneTimeWarningError(err)
 	}
 
+	bpkg.SourceFiles, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
+		"pkg.source_files", settings)
+	util.OneTimeWarningError(err)
+
 	includePaths, err := bpkg.recursiveIncludePaths(b)
 	if err != nil {
 		return nil, err
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index 5691f0cb..be9135ed 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -667,6 +667,21 @@ func compilerTypeToExts(compilerType int) ([]string, error) {
 	}
 }
 
+func fileNameToCompilerType(filename string) (int, error) {
+	switch filepath.Ext(filename) {
+	case ".c":
+		return COMPILER_TYPE_C, nil
+	case ".s", ".S":
+		return COMPILER_TYPE_ASM, nil
+	case ".cc", ".cpp", ".cxx":
+		return COMPILER_TYPE_CPP, nil
+	case ".a":
+		return COMPILER_TYPE_ARCHIVE, nil
+	default:
+		return -1, util.NewNewtError("Unknown file type for " + filename)
+	}
+}
+
 // Compiles all C files matching the specified file glob.
 func (c *Compiler) CompileC(filename string) error {
 	filename = filepath.ToSlash(filename)
@@ -815,6 +830,21 @@ func (c *Compiler) processEntry(node os.FileInfo, cType int,
 	return entries, err
 }
 
+func (c *Compiler) CollectSingleEntry(filename string) (*CompilerJob, error) {
+	file := filepath.ToSlash(filename)
+	ctype, err := fileNameToCompilerType(file)
+
+	if err != nil {
+		return nil, err
+	}
+
+	return &CompilerJob{
+		Filename:     file,
+		Compiler:     c,
+		CompilerType: ctype,
+	}, nil
+}
+
 func (c *Compiler) RecursiveCollectEntries(cType int,
 	ignDirs []string) ([]CompilerJob, error) {
 


[mynewt-newt] 01/02: builder: Fix names in pkg.yml

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit 1785cb87967cc9763f7a70c41d46f59d85bbe465
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Jan 26 15:18:12 2023 +0100

    builder: Fix names in pkg.yml
    
    This adds consistent naming for pkg settings to include/ignore source
    files and directories in pkg.yml:
    - source_dirs
    - ignore_dirs
    - ignore_files
    
    Old names still work for backwards compatibility, but only if new
    variant is not used.
---
 newt/builder/buildpackage.go | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/newt/builder/buildpackage.go b/newt/builder/buildpackage.go
index 40e4fb06..94535e62 100644
--- a/newt/builder/buildpackage.go
+++ b/newt/builder/buildpackage.go
@@ -171,9 +171,15 @@ func (bpkg *BuildPackage) CompilerInfo(
 	ci.IgnoreFiles = []*regexp.Regexp{}
 
 	ignPats, err := bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
-		"pkg.ign_files", settings)
+		"pkg.ignore_files", settings)
 	util.OneTimeWarningError(err)
 
+	if len(ignPats) == 0 {
+		ignPats, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
+			"pkg.ign_files", settings)
+		util.OneTimeWarningError(err)
+	}
+
 	for _, str := range ignPats {
 		re, err := regexp.Compile(str)
 		if err != nil {
@@ -186,9 +192,15 @@ func (bpkg *BuildPackage) CompilerInfo(
 	ci.IgnoreDirs = []*regexp.Regexp{}
 
 	ignPats, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
-		"pkg.ign_dirs", settings)
+		"pkg.ignore_dirs", settings)
 	util.OneTimeWarningError(err)
 
+	if len(ignPats) == 0 {
+		ignPats, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
+			"pkg.ign_dirs", settings)
+		util.OneTimeWarningError(err)
+	}
+
 	for _, str := range ignPats {
 		re, err := regexp.Compile(str)
 		if err != nil {
@@ -199,9 +211,15 @@ func (bpkg *BuildPackage) CompilerInfo(
 	}
 
 	bpkg.SourceDirectories, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
-		"pkg.src_dirs", settings)
+		"pkg.source_dirs", settings)
 	util.OneTimeWarningError(err)
 
+	if len(bpkg.SourceDirectories) == 0 {
+		bpkg.SourceDirectories, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice(
+			"pkg.src_dirs", settings)
+		util.OneTimeWarningError(err)
+	}
+
 	includePaths, err := bpkg.recursiveIncludePaths(b)
 	if err != nil {
 		return nil, err