@ -72,8 +72,8 @@ var (
deferred [ ] func ( ) error
deferred [ ] func ( ) error
fset = token . NewFileSet ( )
fset = token . NewFileSet ( )
b64 = base64 . NewEncoding ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_z" )
b64 = base64 . NewEncoding ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_z" )
print er Config = printer . Config { Mode : printer . RawFormat }
print Config = printer . Config { Mode : printer . RawFormat }
// listPackage helps implement a types.Importer which finds the export
// listPackage helps implement a types.Importer which finds the export
// data for the original dependencies, not their garbled counterparts.
// data for the original dependencies, not their garbled counterparts.
@ -253,8 +253,7 @@ func mainErr(args []string) error {
if flagSeed == "random" {
if flagSeed == "random" {
seed = make ( [ ] byte , 16 ) // random 128 bit seed
seed = make ( [ ] byte , 16 ) // random 128 bit seed
_ , err = rand . Read ( seed )
if _ , err := rand . Read ( seed ) ; err != nil {
if err != nil {
return fmt . Errorf ( "Error generating random seed: %v" , err )
return fmt . Errorf ( "Error generating random seed: %v" , err )
}
}
@ -339,10 +338,7 @@ func mainErr(args []string) error {
if runtime . GOOS == "windows" {
if runtime . GOOS == "windows" {
tool = strings . TrimSuffix ( tool , ".exe" )
tool = strings . TrimSuffix ( tool , ".exe" )
}
}
transform , ok := transformFuncs [ tool ]
transform := transformFuncs [ tool ]
if ! ok {
return fmt . Errorf ( "unknown tool: %q" , tool )
}
transformed := args [ 1 : ]
transformed := args [ 1 : ]
// log.Println(tool, transformed)
// log.Println(tool, transformed)
if transform != nil {
if transform != nil {
@ -370,23 +366,6 @@ func mainErr(args []string) error {
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 ) {
@ -489,8 +468,7 @@ func transformCompile(args []string) ([]string, error) {
if envGarbleDebugDir != "" {
if envGarbleDebugDir != "" {
osPkgPath := filepath . FromSlash ( pkgPath )
osPkgPath := filepath . FromSlash ( pkgPath )
pkgDebugDir = filepath . Join ( envGarbleDebugDir , osPkgPath )
pkgDebugDir = filepath . Join ( envGarbleDebugDir , osPkgPath )
err = os . MkdirAll ( pkgDebugDir , 0 o755 )
if err := os . MkdirAll ( pkgDebugDir , 0 o755 ) ; err != nil {
if err != nil {
return nil , err
return nil , err
}
}
}
}
@ -528,37 +506,29 @@ func transformCompile(args []string) ([]string, error) {
// Uncomment for some quick debugging. Do not delete.
// Uncomment for some quick debugging. Do not delete.
// fmt.Fprintf(os.Stderr, "\n-- %s/%s --\n", pkgPath, origName)
// fmt.Fprintf(os.Stderr, "\n-- %s/%s --\n", pkgPath, origName)
// if err := print er Config.Fprint(os.Stderr, fset, file); err != nil {
// if err := print Config.Fprint(os.Stderr, fset, file); err != nil {
// return nil, err
// return nil, err
// }
// }
}
}
tempFilePath := filepath . Join ( tempDir , name )
tempFile , err := os . Create ( filepath . Join ( tempDir , name ) )
tempFile , err := os . Create ( tempFilePath )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
defer tempFile . Close ( )
defer tempFile . Close ( )
var (
var printWriter io . Writer = tempFile
fW io . Writer
var debugFile * os . File
debugFile * os . File
)
fW = tempFile
if pkgDebugDir != "" {
if pkgDebugDir != "" {
debugFilePath := filepath . Join ( pkgDebugDir , name )
debugFile , err = os . Create ( filepath . Join ( pkgDebugDir , name ) )
debugFile , err = os . Create ( debugFilePath )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
defer debugFile . Close ( )
defer debugFile . Close ( )
fW = io . MultiWriter ( tempFile , debugFile )
printWriter = io . MultiWriter ( tempFile , debugFile )
}
}
if err := print erConfig. Fprint ( fW , fset , file ) ; err != nil {
if err := print Config. Fprint ( printWriter , fset , file ) ; err != nil {
return nil , err
return nil , err
}
}
if err := tempFile . Close ( ) ; err != nil {
if err := tempFile . Close ( ) ; err != nil {