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: strategy:
matrix: matrix:
go-version: [1.13.x] go-version: [1.13.x]
platform: [ubuntu-latest, macos-latest] platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- name: Install Go - name: Install Go

@ -21,6 +21,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"golang.org/x/tools/go/ast/astutil" "golang.org/x/tools/go/ast/astutil"
@ -125,10 +126,17 @@ func main1() int {
} }
_, tool := filepath.Split(args[0]) _, 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:] transformed := args[1:]
// log.Println(tool, transformed) // log.Println(tool, transformed)
if transform := transformFuncs[tool]; transform != nil { if transform != nil {
var err error var err error
if transformed, err = transform(transformed); err != nil { if transformed, err = transform(transformed); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
@ -155,6 +163,23 @@ func main1() int {
var transformFuncs = map[string]func([]string) ([]string, error){ var transformFuncs = map[string]func([]string) ([]string, error){
"compile": transformCompile, "compile": transformCompile,
"link": transformLink, "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) { func transformCompile(args []string) ([]string, error) {

@ -38,7 +38,7 @@ func TestScripts(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
binfile += ".exe" 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 return err
} }
env.Vars = append(env.Vars, fmt.Sprintf("PATH=%s%c%s", bindir, filepath.ListSeparator, os.Getenv("PATH"))) 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' [!windows] [exec:readelf] stdout '\.symtab'
# The default build includes full non-trimmed paths, as well as our names. # 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. # Check that we fail if the user forgot -trimpath.
! exec go build -a -toolexec=garble main.go ! 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 # Finally, check that the 'garble build' shortcut works, and produces the same
# binary. # binary.
cp main main_old cp main$exe main_old$exe
rm main rm main$exe
garble build main.go garble build main.go
! bingrep main$exe 'globalVar' ! bingrep main$exe 'globalVar'
bincmp main main_old bincmp main$exe main_old$exe
-- main.go -- -- main.go --
package main package main

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

Loading…
Cancel
Save