diff --git a/newt/builder/build.go b/newt/builder/build.go index 7a25e76b00..3f3a8a4233 100644 --- a/newt/builder/build.go +++ b/newt/builder/build.go @@ -56,6 +56,7 @@ type Builder struct { linkerScripts []string buildName string linkElf string + workDir string injectedSettings map[string]string } @@ -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)), @@ -74,6 +76,7 @@ func NewBuilder( apiMap: make(map[string]*BuildPackage, len(apiMap)), linkElf: "", targetBuilder: t, + workDir: workDir, injectedSettings: map[string]string{}, } diff --git a/newt/builder/buildpackage.go b/newt/builder/buildpackage.go index a679664753..0b112872f7 100644 --- a/newt/builder/buildpackage.go +++ b/newt/builder/buildpackage.go @@ -109,9 +109,13 @@ func (bpkg *BuildPackage) recursiveIncludePaths( } // Replaces instances of "@" 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 } @@ -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. diff --git a/newt/builder/paths.go b/newt/builder/paths.go index 46b61c6620..2445ee8259 100644 --- a/newt/builder/paths.go +++ b/newt/builder/paths.go @@ -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()) diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go index 532db09792..d729479697 100644 --- a/newt/builder/targetbuild.go +++ b/newt/builder/targetbuild.go @@ -59,6 +59,7 @@ type TargetBuilder struct { LoaderList interfaces.PackageList keyFile string + workDir string injectedSettings map[string]string res *resolve.Resolution @@ -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 } @@ -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 } @@ -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 } @@ -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 diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go index 751152dab4..ec7977a991 100644 --- a/newt/newtutil/newtutil.go +++ b/newt/newtutil/newtutil.go @@ -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 {