Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolves #71] Add trimpath arg to gobuild #102

Merged
merged 7 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
sudo: false
sudo: required

dist: trusty

services:
- docker

language:
- go

go:
- "1.12"
- "1.13"
- '1.12'
- '1.13'

git:
depth: 1

install: true
install: true # skipping the default go dependencies install step

before_script:
# Download and install kubectl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Download and install KinD
- curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.5.1/kind-$(uname)-amd64 && chmod +x ./kind && sudo mv kind /usr/local/bin/
# Create a new Kubernetes cluster using KinD
- kind create cluster
- export KUBECONFIG=$(kind get kubeconfig-path)

script:
# Verify that all source files are correctly formatted.
- find . -name "*.go" | grep -v vendor/ | xargs gofmt -d -e -l

- go clean -i
- go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

- bash integration_test.sh
# TODO: Set up coverage.
#after_success:
# - bash <(curl -s https://codecov.io/bash)
2 changes: 2 additions & 0 deletions integration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go install ./cmd/ko
ko apply -f ./cmd/ko/test -L
3 changes: 2 additions & 1 deletion pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ func build(ip string, platform v1.Platform, disableOptimizations bool) (string,
}
file := filepath.Join(tmpDir, "out")

args := make([]string, 0, 6)
args := make([]string, 0, 7)
args = append(args, "build")
if disableOptimizations {
// Disable optimizations (-N) and inlining (-l).
args = append(args, "-gcflags", "all=-N -l")
}
args = append(args, "-o", file)
args = addGo113TrimPathFlag(args)
args = append(args, ip)
cmd := exec.Command("go", args...)

Expand Down
22 changes: 22 additions & 0 deletions pkg/build/trimpath_113.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// house flag adding function for go1.13 and later version with -trimpath available
// +build go1.13

package build

func addGo113TrimPathFlag(args []string) []string {
return append(args, "-trimpath")
}
22 changes: 22 additions & 0 deletions pkg/build/trimpath_pre113.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// house placeholder function for go1.12 and earlier version without -trimpath
// +build !go1.13

package build

func addGo113TrimPathFlag(args []string) []string {
return args
}