Commit eee5d30a authored by Matthew Finkel's avatar Matthew Finkel Committed by Georg Koppen
Browse files

Bug 28803: Integrate building Pluggable Transports for Android

We integrate building Pluggable Transports for Android to solve #32303
in particular later on but it is important for providing snowflake
support as well at some point (see: #28672)

The bulk of the patch got written by boklm when trying to provide
snowflake support for Android (#28672).
parent eab41780
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
From 44e3391a5a3d9a2c4b57f78e43414465ab84681e Mon Sep 17 00:00:00 2001
From: Nicolas Vigier <boklm@torproject.org>
Date: Thu, 27 Jun 2019 19:21:05 +0200
Subject: [PATCH] Use fixed go-build tmp directory

Use fixed go-build tmp directory, when the directory does not exist, in
order to avoid some reproducibility issues where build directory gets
embedded in generated binaries.
---
 src/cmd/go/internal/work/action.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go
index 1f91046eb1..ba74b26a38 100644
--- a/src/cmd/go/internal/work/action.go
+++ b/src/cmd/go/internal/work/action.go
@@ -224,9 +224,13 @@ func (b *Builder) Init() {
 	if cfg.BuildN {
 		b.WorkDir = "$WORK"
 	} else {
-		tmp, err := ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-build")
-		if err != nil {
-			base.Fatalf("go: creating work dir: %v", err)
+		tmp := filepath.Join(os.Getenv("GOTMPDIR"), "go-build-workdir")
+		_, err := os.Stat(tmp)
+		if !os.IsNotExist(err) {
+			tmp, err = ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-build")
+			if err != nil {
+				base.Fatalf("go: creating work dir: %v", err)
+			}
 		}
 		if !filepath.IsAbs(tmp) {
 			abs, err := filepath.Abs(tmp)
+6 −6
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ export GOROOT_BOOTSTRAP="/var/tmp/build/go1.4"
cd $rootdir
[% IF ! c("var/linux") %]
  [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  # http://golang.org/doc/install/source#environment
  export GOOS=[% c("var/GOOS") %]
  export GOARCH=[% c("var/GOARCH") %]
[% END %]

# Building go
@@ -48,9 +51,6 @@ cd /var/tmp/dist/go/src
  echo "#!/bin/sh" > "$CC_FOR_TARGET"
  echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
  chmod +x "$CC_FOR_TARGET"
  # http://golang.org/doc/install/source#environment
  export GOOS=darwin
  export GOARCH=amd64
  # faketime is needed because clang 3.9.1 on Darwin embeds the timestamps of
  # certain intermediate object files (including those that arise here while
  # compiling the Go runtime itself). Without this, variable timestamps would
@@ -65,10 +65,10 @@ cd /var/tmp/dist/go/src
  echo "#!/bin/sh" > "$CC_FOR_TARGET"
  echo "exec [% c("arch") %]-w64-mingw32-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  chmod +x "$CC_FOR_TARGET"
  # http://golang.org/doc/install/source#environment
  export GOOS=windows
  export GOARCH=[% c("var/GOARCH") %]
  CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
[% ELSIF c("var/android") -%]
  patch -p2 < $rootdir/0001-Use-fixed-go-build-tmp-directory.patch
  CGO_ENABLED=1 CC_FOR_TARGET=[% c("var/CC") %] CGO_CFLAGS='-D__ANDROID_API__=[% c("var/android_min_api") %]' CC= CFLAGS= LDFLAGS= ./make.bash
[% END -%]

cd /var/tmp/dist
+27 −3
Original line number Diff line number Diff line
@@ -10,8 +10,13 @@ var:
  setup: |
    mkdir -p /var/tmp/dist
    tar -C /var/tmp/dist -xf $rootdir/[% c("go_tarfile") %]
    [% IF pc(c("origin_project"), "var/no_crosscompile") -%]
      export GOOS=linux
      export GOARCH=amd64
    [% ELSE -%]
      export GOOS=[% c("var/GOOS") %]
      export GOARCH=[% c("var/GOARCH") %]
    [% END -%]
    export GOPATH=/var/tmp/dist/gopath
    export PATH=/var/tmp/dist/go/bin:/var/tmp/dist/gopath/bin:"$PATH"
    [% IF c("var/linux") -%]
@@ -21,6 +26,8 @@ var:
    [% IF c("var/linux-i686") -%]
      export CGO_ENABLED=1
    [% END -%]
    export GOTMPDIR=/var/tmp/build/go-tmp
    mkdir -p "$GOTMPDIR"

  # Template build script for building a go library.
  # This can be called as projects/go/var/build_go_lib.
@@ -82,15 +89,32 @@ targets:
  linux-i686:
    var:
      GOARCH: 386
  android:
    var:
      GOOS: android
  android-x86:
    var:
      GOARCH: 386
  android-x86_64:
    var:
      GOARCH: amd64
  android-armv7:
    var:
      GOARCH: arm
  android-aarch64:
    var:
      GOARCH: arm64

input_files:
  - project: container-image
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
    enable: '[% c("var/windows") || c("var/osx") %]'
    enable: '[% ! c("var/linux") %]'
  - URL: 'https://golang.org/dl/go[% c("version") %].src.tar.gz'
    name: go
    sha256sum: ab0e56ed9c4732a653ed22e232652709afbf573e710f56a07f7fdeca578d62fc
  - URL: 'https://golang.org/dl/go[% c("var/go14_version") %].src.tar.gz'
    name: go14
    sha256sum: 9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
  - filename: 0001-Use-fixed-go-build-tmp-directory.patch
    enable: '[% c("var/android") %]'
+9 −0
Original line number Diff line number Diff line
@@ -11,7 +11,16 @@ var:
    use_container: 1
  go_lib: git.schwanenlied.me/yawning/bsaes.git

targets:
  android:
    var:
      build_go_lib_pre: |
        [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]

input_files:
  - project: container-image
  - name: go
    project: go
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
    enable: '[% c("var/android") %]'
+35 −0
Original line number Diff line number Diff line
From 188307b6acd5003e82cb68872da9463f5f707515 Mon Sep 17 00:00:00 2001
From: Nicolas Vigier <boklm@torproject.org>
Date: Thu, 27 Jun 2019 12:46:38 +0200
Subject: [PATCH] If the GOMOBILE_TMPDIR env variable is defined, use that as
 tmpdir

Having the option to select a fixed tmpdir makes it possible to have
reproducible builds, as the build directory is embedded in the generated
executables.
---
 cmd/gomobile/env.go | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/cmd/gomobile/env.go b/cmd/gomobile/env.go
index 471b009..b97141b 100644
--- a/cmd/gomobile/env.go
+++ b/cmd/gomobile/env.go
@@ -61,9 +61,14 @@ func buildEnvInit() (cleanup func(), err error) {
 		tmpdir = "$WORK"
 		cleanupFn = func() {}
 	} else {
-		tmpdir, err = ioutil.TempDir("", "gomobile-work-")
-		if err != nil {
-			return nil, err
+		gomobile_tmpdir := os.Getenv("GOMOBILE_TMPDIR")
+		if gomobile_tmpdir != "" {
+			tmpdir = gomobile_tmpdir
+		} else {
+			tmpdir, err = ioutil.TempDir("", "gomobile-work-")
+			if err != nil {
+				return nil, err
+			}
 		}
 	}
 	if buildX {
Loading