-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make builds reproducible by honoring BUILD_PATH_PREFIX_MAP Upstream has rejected the patch in this form and promised to implement an alternative they are happy with instead. That hasn't happened yet though. Bug: golang/go#22491, golang/go#16860 Forwarded: https://golang.org/cl/73291 (rejected upstream though)
- Loading branch information
1 parent
3038e76
commit 4f5c942
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2010 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package ld | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
func decode(s string) string { | ||
s = strings.Replace(s, "%.", ":", -1) | ||
s = strings.Replace(s, "%+", "=", -1) | ||
s = strings.Replace(s, "%#", "%", -1) | ||
return s | ||
} | ||
|
||
type prefixMapEntry struct { | ||
target string | ||
source string | ||
} | ||
|
||
var ( | ||
buildPathPrefixMap []prefixMapEntry | ||
buildPathPrefixMapOnce sync.Once | ||
) | ||
|
||
// See https://reproducible-builds.org/specs/build-path-prefix-map/ | ||
func applyBuildPathPrefixMap(dir string) string { | ||
// Parse the BUILD_PATH_PREFIX_MAP only once; this function gets called for | ||
// every compiled file. | ||
buildPathPrefixMapOnce.Do(func() { | ||
for _, item := range strings.Split(os.Getenv("BUILD_PATH_PREFIX_MAP"), ":") { | ||
if strings.TrimSpace(item) == "" { | ||
continue | ||
} | ||
parts := strings.Split(item, "=") | ||
if got, want := len(parts), 2; got != want { | ||
log.Fatalf("parsing BUILD_PATH_PREFIX_MAP: incorrect number of = separators in item %q: got %d, want %d", item, got-1, want-1) | ||
} | ||
buildPathPrefixMap = append(buildPathPrefixMap, prefixMapEntry{ | ||
target: decode(parts[0]), | ||
source: decode(parts[1]), | ||
}) | ||
} | ||
}) | ||
for _, e := range buildPathPrefixMap { | ||
if strings.HasPrefix(dir, e.source) { | ||
return e.target + strings.TrimPrefix(dir, e.source) | ||
} | ||
} | ||
return dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters