Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion newt/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Builder struct {
linkerScripts []string
buildName string
linkElf string
workDir string
injectedSettings map[string]string
}

Expand All @@ -64,7 +65,8 @@ func NewBuilder(
buildName string,
rpkgs []*resolve.ResolvePackage,
apiMap map[string]*resolve.ResolvePackage,
cfg syscfg.Cfg) (*Builder, error) {
cfg syscfg.Cfg,
workDir string) (*Builder, error) {

b := &Builder{
PkgMap: make(map[*resolve.ResolvePackage]*BuildPackage, len(rpkgs)),
Expand All @@ -74,6 +76,7 @@ func NewBuilder(
apiMap: make(map[string]*BuildPackage, len(apiMap)),
linkElf: "",
targetBuilder: t,
workDir: workDir,
injectedSettings: map[string]string{},
}

Expand Down
16 changes: 10 additions & 6 deletions newt/builder/buildpackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ func (bpkg *BuildPackage) recursiveIncludePaths(
}

// Replaces instances of "@<repo-name>" with repo paths.
func expandFlags(flags []string) {
func expandFlags(b *Builder, flags []string) {
m := map[string]string{}
m["bin"] = b.AppPath()
m["user"] = b.WorkPath()

for i, f := range flags {
newFlag, changed := newtutil.ReplaceRepoDesignators(f)
newFlag, changed := newtutil.ReplaceRepoDesignators(f, m)
if changed {
flags[i] = newFlag
}
Expand Down Expand Up @@ -148,19 +152,19 @@ func (bpkg *BuildPackage) CompilerInfo(
// paths.
ci.Cflags, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.cflags", settings)
util.OneTimeWarningError(err)
expandFlags(ci.Cflags)
expandFlags(b, ci.Cflags)

ci.CXXflags, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.cxxflags", settings)
util.OneTimeWarningError(err)
expandFlags(ci.CXXflags)
expandFlags(b, ci.CXXflags)

ci.Lflags, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.lflags", settings)
util.OneTimeWarningError(err)
expandFlags(ci.Lflags)
expandFlags(b, ci.Lflags)

ci.Aflags, err = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.aflags", settings)
util.OneTimeWarningError(err)
expandFlags(ci.Aflags)
expandFlags(b, ci.Aflags)

// Package-specific injected settings get specified as C flags on the
// command line.
Expand Down
4 changes: 4 additions & 0 deletions newt/builder/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ func (b *Builder) AppPath() string {
return b.PkgBinDir(b.appPkg) + "/"
}

func (b *Builder) WorkPath() string {
return b.workDir
}

func (b *Builder) TestExePath() string {
return TestExePath(b.targetPkg.rpkg.Lpkg.FullName(), b.buildName,
b.testPkg.rpkg.Lpkg.FullName(), b.testPkg.rpkg.Lpkg.Type())
Expand Down
25 changes: 14 additions & 11 deletions newt/builder/targetbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type TargetBuilder struct {
LoaderList interfaces.PackageList

keyFile string
workDir string
injectedSettings map[string]string

res *resolve.Resolution
Expand Down Expand Up @@ -389,7 +390,7 @@ func (t *TargetBuilder) PrepBuild() error {

if t.res.LoaderSet != nil {
t.LoaderBuilder, err = NewBuilder(t, BUILD_NAME_LOADER,
t.res.LoaderSet.Rpkgs, t.res.ApiMap, t.res.Cfg)
t.res.LoaderSet.Rpkgs, t.res.ApiMap, t.res.Cfg, t.workDir)
if err != nil {
return err
}
Expand All @@ -405,7 +406,7 @@ func (t *TargetBuilder) PrepBuild() error {
}

t.AppBuilder, err = NewBuilder(t, BUILD_NAME_APP, t.res.AppSet.Rpkgs,
t.res.ApiMap, t.res.Cfg)
t.res.ApiMap, t.res.Cfg, t.workDir)
if err != nil {
return err
}
Expand Down Expand Up @@ -541,6 +542,17 @@ func (t *TargetBuilder) autogenKeys() error {
}

func (t *TargetBuilder) Build() error {
workDir, err := makeUserWorkDir()
if err != nil {
return err
}
defer func() {
log.Debugf("removing user work dir: %s", workDir)
os.RemoveAll(workDir)
}()

t.workDir = workDir

if err := t.PrepBuild(); err != nil {
return err
}
Expand All @@ -558,15 +570,6 @@ func (t *TargetBuilder) Build() error {
}
}

workDir, err := makeUserWorkDir()
if err != nil {
return err
}
defer func() {
log.Debugf("removing user work dir: %s", workDir)
os.RemoveAll(workDir)
}()

// Execute the set of pre-build user scripts.
if err := t.execPreBuildCmds(workDir); err != nil {
return err
Expand Down
25 changes: 18 additions & 7 deletions newt/newtutil/newtutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,34 @@ func FindRepoDesignator(s string) (int, int) {
return start, len
}

func ReplaceRepoDesignators(s string) (string, bool) {
func ReplaceRepoDesignators(s string, m map[string]string) (string, bool) {
start, len := FindRepoDesignator(s)
if start == -1 {
return s, false
}
repoName := s[start+1 : start+len]

proj := interfaces.GetProject()
repoPath := proj.FindRepoPath(repoName)
if repoPath == "" {
return s, false
name := s[start+1 : start+len]
var path string

if name[0:1] == "@" {
var ok bool

path, ok = m[name[1:]]
if !ok {
return s, false
}
} else {
path = proj.FindRepoPath(name)
if path == "" {
return s, false
}
}

// Trim common project base from repo path.
relRepoPath := strings.TrimPrefix(repoPath, proj.Path()+"/")
relPath := strings.TrimPrefix(path, proj.Path()+"/")

return s[:start] + relRepoPath + s[start+len:], true
return s[:start] + relPath + s[start+len:], true
}

func BuildPackageString(repoName string, pkgName string) string {
Expand Down