Skip to content

Commit

Permalink
Fixed issue where a package in specified in importmap would be hashed…
Browse files Browse the repository at this point in the history
… differently in a package that imported it, due to the mapping of import paths.

Also commented out the 'net' import in the goprivate testscript (again) due to cgo compile errors
  • Loading branch information
capnspacehook committed Nov 8, 2020
1 parent 28a5265 commit accbe4d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
56 changes: 36 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ func fillBuildInfo(flags []string) error {
if err != nil {
return err
}

importMap := make(map[string]string)
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
Expand All @@ -859,27 +861,41 @@ func fillBuildInfo(flags []string) error {
if i < 0 {
continue
}
if verb := line[:i]; verb != "packagefile" {
continue
}
args := strings.TrimSpace(line[i+1:])
j := strings.Index(args, "=")
if j < 0 {
continue
}
importPath, objectPath := args[:j], args[j+1:]
buildID, err := buildidOf(objectPath)
if err != nil {
return err
}
// log.Println("buildid:", buildID)
verb := line[:i]
switch verb {
case "importmap":
args := strings.TrimSpace(line[i+1:])
j := strings.Index(args, "=")
if j < 0 {
continue
}
beforePath, afterPath := args[:j], args[j+1:]
importMap[afterPath] = beforePath
case "packagefile":
args := strings.TrimSpace(line[i+1:])
j := strings.Index(args, "=")
if j < 0 {
continue
}
importPath, objectPath := args[:j], args[j+1:]
buildID, err := buildidOf(objectPath)
if err != nil {
return err
}
// log.Println("buildid:", buildID)

if len(buildInfo.imports) == 0 {
buildInfo.firstImport = importPath
}
buildInfo.imports[importPath] = importedPkg{
packagefile: objectPath,
actionID: decodeHash(actionID(buildID)),
if len(buildInfo.imports) == 0 {
buildInfo.firstImport = importPath
}
impPkg := importedPkg{
packagefile: objectPath,
actionID: decodeHash(actionID(buildID)),
}
buildInfo.imports[importPath] = impPkg

if otherPath, ok := importMap[importPath]; ok {
buildInfo.imports[otherPath] = impPkg
}
}
}
// log.Printf("%#v", buildInfo)
Expand Down
3 changes: 2 additions & 1 deletion testdata/scripts/goprivate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ go 1.15
-- standalone/main.go --
package main

import _ "net"
# TODO: This tests that #146 is fixed, but is blocked by errors garbling 'net'
//import _ "net"

func main() {}
-- importer/importer.go --
Expand Down

0 comments on commit accbe4d

Please sign in to comment.