initial commit
commit
f5f72ef626
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2019, Daniel Martí. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -0,0 +1,5 @@
|
||||
module mvdan.cc/garble
|
||||
|
||||
go 1.14
|
||||
|
||||
require github.com/rogpeppe/go-internal v1.5.0
|
@ -0,0 +1,8 @@
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/rogpeppe/go-internal v1.5.0 h1:Usqs0/lDK/NqTkvrmKSwA/3XkZAs7ZAW/eLeQ2MVBTw=
|
||||
github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var flagSet = flag.NewFlagSet("garble", flag.ContinueOnError)
|
||||
|
||||
func init() { flagSet.Usage = usage }
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, `
|
||||
Usage of garble:
|
||||
|
||||
go build -toolexec=garble [build flags] [packages]
|
||||
`[1:])
|
||||
flagSet.PrintDefaults()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func main() { os.Exit(main1()) }
|
||||
|
||||
func main1() int {
|
||||
if err := flagSet.Parse(os.Args[1:]); err != nil {
|
||||
return 2
|
||||
}
|
||||
args := flagSet.Args()
|
||||
if len(args) < 1 {
|
||||
flagSet.Usage()
|
||||
}
|
||||
_, tool := filepath.Split(args[0])
|
||||
// TODO: trim ".exe" for windows?
|
||||
transformed := args[1:]
|
||||
switch tool {
|
||||
case "compile":
|
||||
var err error
|
||||
transformed, err = transformCompile(args[1:])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
cmd := exec.Command(args[0], transformed...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func transformCompile(args []string) ([]string, error) {
|
||||
return args, nil
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rogpeppe/go-internal/testscript"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(testscript.RunMain(m, map[string]func() int{
|
||||
"garble": main1,
|
||||
}))
|
||||
}
|
||||
|
||||
var update = flag.Bool("u", false, "update testscript output files")
|
||||
|
||||
func TestScripts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testscript.Run(t, testscript.Params{
|
||||
Dir: filepath.Join("testdata", "scripts"),
|
||||
Setup: func(env *testscript.Env) error {
|
||||
env.Vars = append(env.Vars, "TESTBIN="+os.Args[0])
|
||||
|
||||
for _, name := range [...]string{
|
||||
"HOME",
|
||||
"USERPROFILE", // $HOME for windows
|
||||
"GOCACHE",
|
||||
} {
|
||||
if value := os.Getenv(name); value != "" {
|
||||
env.Vars = append(env.Vars, name+"="+value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
UpdateScripts: *update,
|
||||
})
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
[!exec:go] skip
|
||||
[!symlink] skip
|
||||
|
||||
# We want to use the current garble, not whichever happens to be globally
|
||||
# installed. Use the test binary with TESTSCRIPT_COMMAND, which we know will
|
||||
# correctly run garble thanks to go-internal/testscript.
|
||||
mkdir .bin
|
||||
symlink .bin/garble$exe -> $TESTBIN
|
||||
env PATH=.bin${:}$PATH
|
||||
env TESTSCRIPT_COMMAND=garble
|
||||
|
||||
exec go build -toolexec=garble main.go
|
||||
exists main
|
||||
exec ./main
|
||||
cmp stderr main.stderr
|
||||
# TODO
|
||||
# ! grep 'globalVar' main
|
||||
# ! grep 'globalFunc' main
|
||||
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
var globalVar = "global value"
|
||||
|
||||
func globalFunc() { println("global func body") }
|
||||
|
||||
func main() {
|
||||
println(globalVar)
|
||||
globalFunc()
|
||||
}
|
||||
-- main.stderr --
|
||||
global value
|
||||
global func body
|
@ -0,0 +1,12 @@
|
||||
! garble
|
||||
stderr -count=1 'Usage of'
|
||||
stderr '\tgo build'
|
||||
! stdout .
|
||||
|
||||
! garble -h
|
||||
stderr 'Usage of'
|
||||
! stdout .
|
||||
|
||||
! garble -badflag
|
||||
stderr 'Usage of'
|
||||
! stdout .
|
Loading…
Reference in New Issue