Handle absolute paths for the ninja shard writing.
Test: OUT_DIR=/source/foo m nothing Change-Id: Id3849e7446cd0cb26a5b5c74ac3bf4521449b716
This commit is contained in:
parent
d5133cfc64
commit
c3ac2a249a
3 changed files with 16 additions and 17 deletions
|
@ -20,7 +20,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"runtime/pprof"
|
||||
|
@ -64,7 +63,7 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
}
|
||||
|
||||
if args.Cpuprofile != "" {
|
||||
f, err := os.Create(joinPath(ctx.SrcDir(), args.Cpuprofile))
|
||||
f, err := os.Create(blueprint.JoinPath(ctx.SrcDir(), args.Cpuprofile))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening cpuprofile: %s", err)
|
||||
}
|
||||
|
@ -74,7 +73,7 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
}
|
||||
|
||||
if args.TraceFile != "" {
|
||||
f, err := os.Create(joinPath(ctx.SrcDir(), args.TraceFile))
|
||||
f, err := os.Create(blueprint.JoinPath(ctx.SrcDir(), args.TraceFile))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening trace: %s", err)
|
||||
}
|
||||
|
@ -159,12 +158,12 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
ctx.BeginEvent("write_files")
|
||||
defer ctx.EndEvent("write_files")
|
||||
if args.EmptyNinjaFile {
|
||||
if err := os.WriteFile(joinPath(ctx.SrcDir(), args.OutFile), []byte(nil), blueprint.OutFilePermissions); err != nil {
|
||||
if err := os.WriteFile(blueprint.JoinPath(ctx.SrcDir(), args.OutFile), []byte(nil), blueprint.OutFilePermissions); err != nil {
|
||||
return nil, fmt.Errorf("error writing empty Ninja file: %s", err)
|
||||
}
|
||||
out = io.Discard.(blueprint.StringWriterWriter)
|
||||
} else {
|
||||
f, err := os.OpenFile(joinPath(ctx.SrcDir(), args.OutFile), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, blueprint.OutFilePermissions)
|
||||
f, err := os.OpenFile(blueprint.JoinPath(ctx.SrcDir(), args.OutFile), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, blueprint.OutFilePermissions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening Ninja file: %s", err)
|
||||
}
|
||||
|
@ -195,7 +194,7 @@ func RunBlueprint(args Args, stopBefore StopBefore, ctx *blueprint.Context, conf
|
|||
}
|
||||
|
||||
if args.Memprofile != "" {
|
||||
f, err := os.Create(joinPath(ctx.SrcDir(), args.Memprofile))
|
||||
f, err := os.Create(blueprint.JoinPath(ctx.SrcDir(), args.Memprofile))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening memprofile: %s", err)
|
||||
}
|
||||
|
@ -223,10 +222,3 @@ func fatalErrors(errs []error) error {
|
|||
|
||||
return errors.New("fatal errors encountered")
|
||||
}
|
||||
|
||||
func joinPath(base, path string) string {
|
||||
if filepath.IsAbs(path) {
|
||||
return path
|
||||
}
|
||||
return filepath.Join(base, path)
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ func (s *GlobSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
|||
// We don't need to write the depfile because we're guaranteed that ninja
|
||||
// will run the command at least once (to record it into the ninja_log), so
|
||||
// the depfile will be loaded from that execution.
|
||||
absoluteFileListFile := joinPath(s.SrcDir, fileListFile)
|
||||
absoluteFileListFile := blueprint.JoinPath(s.SrcDir, fileListFile)
|
||||
err := pathtools.WriteFileIfChanged(absoluteFileListFile, globs.FileList(), 0666)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error writing %s: %s", fileListFile, err))
|
||||
|
@ -217,7 +217,7 @@ func WriteBuildGlobsNinjaFile(glob *GlobSingleton, config interface{}) error {
|
|||
}
|
||||
|
||||
const outFilePermissions = 0666
|
||||
err := ioutil.WriteFile(joinPath(glob.SrcDir, glob.GlobFile), buffer, outFilePermissions)
|
||||
err := ioutil.WriteFile(blueprint.JoinPath(glob.SrcDir, glob.GlobFile), buffer, outFilePermissions)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing %s: %s", glob.GlobFile, err)
|
||||
}
|
||||
|
|
11
context.go
11
context.go
|
@ -4544,9 +4544,9 @@ func (c *Context) writeAllModuleActions(nw *ninjaWriter, shardNinja bool, ninjaF
|
|||
wg.Add(1)
|
||||
go func(file string, batchModules []*moduleInfo) {
|
||||
defer wg.Done()
|
||||
f, err := os.OpenFile(filepath.Join(c.SrcDir(), file), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, OutFilePermissions)
|
||||
f, err := os.OpenFile(JoinPath(c.SrcDir(), file), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, OutFilePermissions)
|
||||
if err != nil {
|
||||
errorCh <- fmt.Errorf("error opening Ninja file: %s", err)
|
||||
errorCh <- fmt.Errorf("error opening Ninja file shard: %s", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
|
@ -5259,3 +5259,10 @@ func (pi *PackageIncludes) matchesIncludeTags(ctx *Context) (bool, error) {
|
|||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func JoinPath(base, path string) string {
|
||||
if filepath.IsAbs(path) {
|
||||
return path
|
||||
}
|
||||
return filepath.Join(base, path)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue