Skip to content

Commit

Permalink
Handle temp output names correctly (thought-machine#812)
Browse files Browse the repository at this point in the history
* Use temp output names when necessary

* Handle temp names on the way back out too

* try ensurepip?

no flippin' clue why this is failing now...
  • Loading branch information
peterebden authored Jan 5, 2020
1 parent 3f23b04 commit 7c268fb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ env:
GOPROXY: https://proxy.golang.org

task:
install_script: pkg install -y bash protobuf go git python3
install_script: pkg install -y bash protobuf go git python3 && python3 -m ensurepip
bashrc_script: touch ~/.bashrc
build_script: PLZ_ARGS="-o cache.httpurl:http://$CIRRUS_HTTP_CACHE_HOST" ./bootstrap.sh --exclude pip --exclude py2 --exclude no_cirrus
20 changes: 18 additions & 2 deletions src/core/build_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const CoverageFile = "test.coverage"
// execution API requires that we specify which is which.
const TestResultsDirLabel = "test_results_dir"

// tempOutputSuffix is the suffix we attach to temporary outputs to avoid name clashes.
const tempOutputSuffix = ".out"

// A BuildTarget is a representation of a build target and all information about it;
// its name, dependencies, build commands, etc.
type BuildTarget struct {
Expand Down Expand Up @@ -510,11 +513,11 @@ func (target *BuildTarget) NamedOutputs(name string) []string {
// filename(plz-out/tmp/) if output has the same name as the package, this avoids the name conflict issue
func (target *BuildTarget) GetTmpOutput(parseOutput string) string {
if parseOutput == target.Label.PackageName {
return parseOutput + ".out"
return parseOutput + tempOutputSuffix
} else if target.Label.PackageName == "" && target.HasSource(parseOutput) {
// This also fixes the case where source and output are the same, which can happen
// when we're in the root directory.
return parseOutput + ".out"
return parseOutput + tempOutputSuffix
}
return parseOutput
}
Expand All @@ -529,6 +532,19 @@ func (target *BuildTarget) GetTmpOutputAll(parseOutputs []string) []string {
return tmpOutputs
}

// GetRealOutput returns the real output name for a filename that might have been a temporary output
// (i.e as returned by GetTmpOutput).
func (target *BuildTarget) GetRealOutput(output string) string {
if strings.HasSuffix(output, tempOutputSuffix) {
real := strings.TrimSuffix(output, tempOutputSuffix)
// Check this isn't a file that just happens to be named the same way
if target.GetTmpOutput(real) == output {
return real
}
}
return output
}

// SourcePaths returns the source paths for a given set of sources.
func (target *BuildTarget) SourcePaths(graph *BuildGraph, sources []BuildInput) []string {
ret := make([]string, 0, len(sources))
Expand Down
2 changes: 1 addition & 1 deletion src/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (c *Client) Retrieve(target *core.BuildTarget) (*core.BuildMetadata, error)
if err := c.downloadBlobs(ctx, func(ch chan<- *blob) error {
defer close(ch)
for _, file := range resp.OutputFiles {
filePath := path.Join(outDir, file.Path)
filePath := path.Join(outDir, target.GetRealOutput(file.Path))
addPerms := extraPerms(file)
if file.Contents != nil {
// Inlining must have been requested. Can write it directly.
Expand Down
1 change: 1 addition & 0 deletions src/remote/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func outputs(target *core.BuildTarget) (files, dirs []string) {
outs := target.Outputs()
files = make([]string, 0, len(outs))
for _, out := range outs {
out = target.GetTmpOutput(out)
if !strings.ContainsRune(path.Base(out), '.') && !strings.HasSuffix(out, "file") {
dirs = append(dirs, out)
} else {
Expand Down

0 comments on commit 7c268fb

Please sign in to comment.