diff --git a/newt/builder/build.go b/newt/builder/build.go index 7a25e76b00..1dc6b339ce 100644 --- a/newt/builder/build.go +++ b/newt/builder/build.go @@ -26,6 +26,7 @@ import ( "os" "path/filepath" "runtime" + "strings" log "github.com/sirupsen/logrus" @@ -416,18 +417,32 @@ func (b *Builder) link(elfName string, linkerScripts []string, if err != nil { return err } - c.AddInfo(&toolchain.CompilerInfo{Lflags: ci.Lflags}) + c.AddInfo(&toolchain.CompilerInfo{ + Lflags: ci.Lflags, IgnorePkgs: ci.IgnorePkgs}) } dirs = append(dirs, extraADirs...) - // Find all .a files in the input directories. + // Find all .a files in the input directories for all non-ignored packages + ignorePkgs := c.GetCompilerInfo().IgnorePkgs trimmedANames := []string{} for _, dir := range dirs { - fullANames, _ := filepath.Glob(dir + "/*.a") - for i, archiveName := range fullANames { - fullANames[i] = filepath.ToSlash(archiveName) + ignoreThisPkg := false + for i, ignorePkg := range ignorePkgs { + if strings.HasSuffix(dir, ignorePkg.String()) { + // Pop the ignore package to speed up subsequent checks. + // Assumes no duplicate packages. + ignorePkgs[i] = ignorePkgs[len(ignorePkgs)-1] + ignorePkgs = ignorePkgs[:len(ignorePkgs)-1] + ignoreThisPkg = true + } + } + if !ignoreThisPkg { + fullANames, _ := filepath.Glob(dir + "/*.a") + for i, archiveName := range fullANames { + fullANames[i] = filepath.ToSlash(archiveName) + } + trimmedANames = append(trimmedANames, fullANames...) } - trimmedANames = append(trimmedANames, fullANames...) } c.LinkerScripts = linkerScripts diff --git a/newt/builder/buildpackage.go b/newt/builder/buildpackage.go index a679664753..6992815423 100644 --- a/newt/builder/buildpackage.go +++ b/newt/builder/buildpackage.go @@ -198,6 +198,21 @@ func (bpkg *BuildPackage) CompilerInfo( ci.IgnoreDirs = append(ci.IgnoreDirs, re) } + ci.IgnorePkgs = []*regexp.Regexp{} + + ignPkgs, err := bpkg.rpkg.Lpkg.PkgY.GetValStringSlice( + "pkg.ign_pkgs", settings) + util.OneTimeWarningError(err) + + for _, str := range ignPkgs { + re, err := regexp.Compile(str) + if err != nil { + return nil, util.NewNewtError( + "Ignore pkgs, unable to compile re: " + err.Error()) + } + ci.IgnorePkgs = append(ci.IgnorePkgs, re) + } + bpkg.SourceDirectories, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice( "pkg.src_dirs", settings) util.OneTimeWarningError(err) diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go index ad264ac06f..80bb2cfd54 100644 --- a/newt/toolchain/compiler.go +++ b/newt/toolchain/compiler.go @@ -59,6 +59,7 @@ type CompilerInfo struct { Aflags []string IgnoreFiles []*regexp.Regexp IgnoreDirs []*regexp.Regexp + IgnorePkgs []*regexp.Regexp } type CompileCommand struct { @@ -166,6 +167,7 @@ func NewCompilerInfo() *CompilerInfo { ci.Aflags = []string{} ci.IgnoreFiles = []*regexp.Regexp{} ci.IgnoreDirs = []*regexp.Regexp{} + ci.IgnorePkgs = []*regexp.Regexp{} return ci } @@ -246,6 +248,7 @@ func (ci *CompilerInfo) AddCompilerInfo(newCi *CompilerInfo) { ci.Aflags = addFlags("aflag", ci.Aflags, newCi.Aflags) ci.IgnoreFiles = append(ci.IgnoreFiles, newCi.IgnoreFiles...) ci.IgnoreDirs = append(ci.IgnoreDirs, newCi.IgnoreDirs...) + ci.IgnorePkgs = append(ci.IgnorePkgs, newCi.IgnorePkgs...) } func NewCompiler(compilerDir string, dstDir string,