From 59222cb14bf8de89e5358b31a2926f6e626f91bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 4 Jun 2023 11:06:00 +0100 Subject: [PATCH] various minor TODO cleanups computeLinkerVariableStrinsg had an unusedargument. Only skip obfuscating the name "FS" in the "embed" package. The reflect methods no longer use the transformer receiver type, so that TODO now feels unnecessary. Many methods need to be aware of what the current types.Package is, and that seems reasonable. We no longer use writeFileExclusive for our own cache on disk, so the TODO about using locking or atomic writes is no longer relevant. --- main.go | 10 +++++----- reflect.go | 3 --- shared.go | 3 --- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index cd472d1..eb71740 100644 --- a/main.go +++ b/main.go @@ -952,7 +952,7 @@ func (tf *transformer) transformCompile(args []string) ([]string, error) { // These maps are not kept in pkgCache, since they are only needed to obfuscate curPkg. tf.fieldToStruct = computeFieldToStruct(tf.info) if flagLiterals { - if tf.linkerVariableStrings, err = computeLinkerVariableStrings(tf.pkg, files); err != nil { + if tf.linkerVariableStrings, err = computeLinkerVariableStrings(tf.pkg); err != nil { return nil, err } } @@ -1466,7 +1466,7 @@ func computePkgCache(fsCache *cache.Cache, lpkg *listedPackage, pkg *types.Packa // computeLinkerVariableStrings iterates over the -ldflags arguments, // filling a map with all the string values set via the linker's -X flag. // TODO: can we put this in sharedCache, using objectString as a key? -func computeLinkerVariableStrings(pkg *types.Package, files []*ast.File) (map[*types.Var]string, error) { +func computeLinkerVariableStrings(pkg *types.Package) (map[*types.Var]string, error) { linkerVariableStrings := make(map[*types.Var]string) // TODO: this is a linker flag that affects how we obfuscate a package at @@ -1823,9 +1823,9 @@ func (tf *transformer) transformGoFile(file *ast.File) *ast.File { } case "embed": // FS is detected by the compiler for //go:embed. - // TODO: We probably want a conditional, otherwise we're not - // obfuscating the embed package at all. - return name == "FS" + if name == "FS" { + return true + } case "reflect": switch name { // Per the linker's deadcode.go docs, diff --git a/reflect.go b/reflect.go index 73b5ff1..bca6fe2 100644 --- a/reflect.go +++ b/reflect.go @@ -369,9 +369,6 @@ func (ri *reflectInspector) recursivelyRecordUsedForReflect(t types.Type) { switch t := t.(type) { case *types.Named: obj := t.Obj() - - // TODO: the transformer is only needed in this function, there is - // probably a way to do this with only the ssa information. if obj.Pkg() == nil || obj.Pkg() != ri.pkg { return // not from the specified package } diff --git a/shared.go b/shared.go index d3fabea..271d8f9 100644 --- a/shared.go +++ b/shared.go @@ -111,9 +111,6 @@ func createExclusive(name string) (*os.File, error) { return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666) } -// TODO(mvdan): consider using proper atomic file writes. -// Or possibly even "lockedfile", mimicking cmd/go. - func writeFileExclusive(name string, data []byte) error { f, err := createExclusive(name) if err != nil {