[Pkg-golang-commits] [golang] 01/02: Add 0002-buildpathprefix.patch to support reproducible builds

Michael Stapelberg michael at stapelberg.de
Sun Jul 30 07:49:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

stapelberg pushed a commit to branch reproducible-1.8
in repository golang.

commit 9e8a45dd7b2e67922338674c7ebd214cfda4ad7e
Author: Michael Stapelberg <stapelberg at debian.org>
Date:   Sat Jul 29 09:56:13 2017 +0200

    Add 0002-buildpathprefix.patch to support reproducible builds
---
 debian/patches/0002-buildpathprefix.patch | 83 +++++++++++++++++++++++++++++++
 debian/patches/series                     |  1 +
 2 files changed, 84 insertions(+)

diff --git a/debian/patches/0002-buildpathprefix.patch b/debian/patches/0002-buildpathprefix.patch
new file mode 100644
index 0000000..a7d2efe
--- /dev/null
+++ b/debian/patches/0002-buildpathprefix.patch
@@ -0,0 +1,83 @@
+Index: reproducible-golang/src/cmd/link/internal/ld/buildpathprefix.go
+===================================================================
+--- /dev/null
++++ reproducible-golang/src/cmd/link/internal/ld/buildpathprefix.go
+@@ -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
++}
+Index: reproducible-golang/src/cmd/link/internal/ld/dwarf.go
+===================================================================
+--- reproducible-golang.orig/src/cmd/link/internal/ld/dwarf.go
++++ reproducible-golang/src/cmd/link/internal/ld/dwarf.go
+@@ -1021,7 +1021,7 @@ func writelines(ctxt *Link, syms []*Symb
+ 	newattr(dwinfo, dwarf.DW_AT_stmt_list, dwarf.DW_CLS_PTR, 0, linesec)
+ 	newattr(dwinfo, dwarf.DW_AT_low_pc, dwarf.DW_CLS_ADDRESS, s.Value, s)
+ 	// OS X linker requires compilation dir or absolute path in comp unit name to output debug info.
+-	compDir := getCompilationDir()
++	compDir := applyBuildPathPrefixMap(getCompilationDir())
+ 	newattr(dwinfo, dwarf.DW_AT_comp_dir, dwarf.DW_CLS_STRING, int64(len(compDir)), compDir)
+ 
+ 	// Write .debug_line Line Number Program Header (sec 6.2.4)
+@@ -1052,7 +1052,7 @@ func writelines(ctxt *Link, syms []*Symb
+ 	Adduint8(ctxt, ls, 0)              // include_directories  (empty)
+ 
+ 	for _, f := range ctxt.Filesyms {
+-		Addstring(ls, f.Name)
++		Addstring(ls, applyBuildPathPrefixMap(f.Name))
+ 		Adduint8(ctxt, ls, 0)
+ 		Adduint8(ctxt, ls, 0)
+ 		Adduint8(ctxt, ls, 0)
diff --git a/debian/patches/series b/debian/patches/series
index c9dd75a..69c8340 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-Fix-FTBFS-with-Perl-526.patch
+0002-buildpathprefix.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-golang/golang.git



More information about the pkg-golang-commits mailing list