Revert to json.Encoder

Add tiny test for ldflags
Fix err declaration
pull/135/head
Pagran 5 years ago
parent 4611407781
commit b202bef01e

@ -6,7 +6,7 @@ package main
import (
"bufio"
"bytes"
"encoding/gob"
"encoding/json"
"errors"
"fmt"
"os"
@ -55,16 +55,9 @@ func appendPrivateNameMap(nameMap map[string]string, packageDirectory string) er
if err != nil {
return err
}
var localMap map[string]string
if err = gob.NewDecoder(file).Decode(&localMap); err != nil {
if err := json.NewDecoder(file).Decode(&nameMap); err != nil {
return err
}
for oldName, newName := range localMap {
nameMap[oldName] = newName
}
return nil
}
@ -93,7 +86,7 @@ func obfuscateImports(objPath, importCfgPath string) (garbledImports, privateNam
pkgs = append(pkgs, pkgInfo{pkg, info.Path, private})
packageDir := filepath.Dir(info.Path)
if err = appendPrivateNameMap(nameMap, packageDir); err != nil {
if err := appendPrivateNameMap(nameMap, packageDir); err != nil {
return nil, nil, fmt.Errorf("error parsing name map %s at %s: %v", pkgPath, info.Path, err)
}
}

@ -607,7 +607,7 @@ func transformCompile(args []string) ([]string, error) {
}
defer file.Close()
if err := gob.NewEncoder(file).Encode(privateNameMap); err != nil {
if err := json.NewEncoder(file).Encode(privateNameMap); err != nil {
return nil, err
}
}

@ -1,13 +1,18 @@
# Note the proper domain, since the dot adds an edge case.
env GOPRIVATE=domain.test/main
garble -tiny build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=domain.test/main/imported.ExportedVar=replaced'
garble build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=domain.test/main/imported.ExportedVar=replaced'
exec ./main
cmp stderr main.stderr
! binsubstr main$exe 'unexportedVersion'
[short] stop # no need to verify this with -short
garble -tiny build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=domain.test/main/imported.ExportedVar=replaced'
exec ./main
cmp stderr main.stderr
! binsubstr main$exe 'unexportedVersion'
exec go build -ldflags='-X=main.unexportedVersion=v1.0.0 -X=domain.test/main/imported.ExportedVar=replaced'
exec ./main
cmp stderr main.stderr

Loading…
Cancel
Save