diff --git a/main.go b/main.go index 0e3443d2..8874aa7c 100644 --- a/main.go +++ b/main.go @@ -1227,7 +1227,9 @@ func (tf *transformer) recordType(t types.Type) { // transformGo obfuscates the provided Go syntax file. func (tf *transformer) transformGo(file *ast.File) *ast.File { - if opts.ObfuscateLiterals { + // Only obfuscate the literals here if the flag is on + // and if the package in question is to be obfuscated. + if opts.ObfuscateLiterals && curPkg.ToObfuscate { file = literals.Obfuscate(file, tf.info, fset, tf.ignoreObjects) } diff --git a/testdata/scripts/gogarble.txt b/testdata/scripts/gogarble.txt index 6acdbf53..6ac0ea28 100644 --- a/testdata/scripts/gogarble.txt +++ b/testdata/scripts/gogarble.txt @@ -8,8 +8,12 @@ env GOPRIVATE=match-absolutely/nothing ! garble build -o=out ./standalone stderr '^GOGARBLE="match-absolutely/nothing" does not match any packages to be built$' +# A build where just some packages are obfuscated. env GOGARBLE=test/main/imported -garble build ./importer +garble -literals build -o=out ./importer + +! binsubstr out 'some long string to obfuscate' +binsubstr out 'some long string to not obfuscate' # Obfuscated packages which import non-obfuscated std packages. # Some of the imported std packages use "import maps" due to vendoring, @@ -49,15 +53,18 @@ package main func main() {} -- importer/importer.go -- -package importer +package main import "test/main/imported" -var _ = imported.Name +func main() { + println(imported.LongString) + println("some long string to not obfuscate") +} -- imported/imported.go -- package imported -var Name = "value" +var LongString = "some long string to obfuscate" -- stdimporter/main.go -- package main