make the tool work on Windows, enable tests

The tests required a few last tweaks to work on Windows.
pull/22/head
Daniel Martí 5 years ago
parent 0058dfc12a
commit 5556be7402

@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
go-version: [1.13.x]
platform: [ubuntu-latest, macos-latest]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go

@ -21,6 +21,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"golang.org/x/tools/go/ast/astutil"
@ -125,10 +126,17 @@ func main1() int {
}
_, tool := filepath.Split(args[0])
// TODO: trim ".exe" for windows?
if runtime.GOOS == "windows" {
tool = strings.TrimSuffix(tool, ".exe")
}
transform, ok := transformFuncs[tool]
if !ok {
fmt.Fprintf(os.Stderr, "unknown tool: %q", tool)
return 1
}
transformed := args[1:]
// log.Println(tool, transformed)
if transform := transformFuncs[tool]; transform != nil {
if transform != nil {
var err error
if transformed, err = transform(transformed); err != nil {
fmt.Fprintln(os.Stderr, err)
@ -155,6 +163,23 @@ func main1() int {
var transformFuncs = map[string]func([]string) ([]string, error){
"compile": transformCompile,
"link": transformLink,
"addr2line": nil,
"api": nil,
"asm": nil,
"buildid": nil,
"cgo": nil,
"cover": nil,
"dist": nil,
"doc": nil,
"fix": nil,
"nm": nil,
"objdump": nil,
"pack": nil,
"pprof": nil,
"test2json": nil,
"trace": nil,
"vet": nil,
}
func transformCompile(args []string) ([]string, error) {

@ -38,7 +38,7 @@ func TestScripts(t *testing.T) {
if runtime.GOOS == "windows" {
binfile += ".exe"
}
if err := os.Symlink(os.Args[0], filepath.Join(bindir, "garble")); err != nil {
if err := os.Symlink(os.Args[0], binfile); err != nil {
return err
}
env.Vars = append(env.Vars, fmt.Sprintf("PATH=%s%c%s", bindir, filepath.ListSeparator, os.Getenv("PATH")))

@ -9,7 +9,9 @@ cmp stderr main.stderr
[!windows] [exec:readelf] stdout '\.symtab'
# The default build includes full non-trimmed paths, as well as our names.
bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc'
# Only check $WORK on non-windows, because it's difficult to do it there.
bingrep main$exe 'globalVar' 'globalFunc'
[!windows] bingrep main$exe ${WORK@R}
# Check that we fail if the user forgot -trimpath.
! exec go build -a -toolexec=garble main.go
@ -28,11 +30,11 @@ cmp stderr main.stderr
# Finally, check that the 'garble build' shortcut works, and produces the same
# binary.
cp main main_old
rm main
cp main$exe main_old$exe
rm main$exe
garble build main.go
! bingrep main$exe 'globalVar'
bincmp main main_old
bincmp main$exe main_old$exe
-- main.go --
package main

@ -5,10 +5,10 @@ cmp stdout main.stdout
! bingrep main$exe 'ImportedVar' 'ImportedConst' 'ImportedFunc' 'ImportedType'
# Also check that the binary is reproducible when many imports are involved.
cp main main_old
rm main
cp main$exe main_old$exe
rm main$exe
garble build
bincmp main main_old
bincmp main$exe main_old$exe
-- go.mod --
module foo.com/main

Loading…
Cancel
Save