@ -16,6 +16,7 @@ import (
"os/exec"
"os/exec"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"runtime"
"github.com/bluekeyes/go-gitdiff/gitdiff"
"github.com/bluekeyes/go-gitdiff/gitdiff"
"github.com/rogpeppe/go-internal/lockedfile"
"github.com/rogpeppe/go-internal/lockedfile"
@ -138,7 +139,7 @@ func applyPatches(srcDir, workingDir string, modFiles map[string]bool, patches [
return mod , nil
return mod , nil
}
}
func cachePath ( goExe string ) ( string , error ) {
func cachePath ( ) ( string , error ) {
var cacheDir string
var cacheDir string
if val , ok := os . LookupEnv ( garbleCacheDir ) ; ok {
if val , ok := os . LookupEnv ( garbleCacheDir ) ; ok {
cacheDir = val
cacheDir = val
@ -155,6 +156,11 @@ func cachePath(goExe string) (string, error) {
return "" , err
return "" , err
}
}
goExe := ""
if runtime . GOOS == "windows" {
goExe = ".exe"
}
// Note that we only keep one patched and built linker in the cache.
// Note that we only keep one patched and built linker in the cache.
// If the user switches between Go versions or garble versions often,
// If the user switches between Go versions or garble versions often,
// this may result in rebuilds since we don't keep multiple binaries in the cache.
// this may result in rebuilds since we don't keep multiple binaries in the cache.
@ -220,13 +226,13 @@ func buildLinker(workingDir string, overlay map[string]string, outputLinkPath st
return nil
return nil
}
}
func PatchLinker ( goRoot , goVersion , goExe, tempDir string ) ( string , func ( ) , error ) {
func PatchLinker ( goRoot , goVersion , tempDir string ) ( string , func ( ) , error ) {
patchesVer , modFiles , patches , err := loadLinkerPatches ( )
patchesVer , modFiles , patches , err := loadLinkerPatches ( )
if err != nil {
if err != nil {
panic ( fmt . Errorf ( "cannot retrieve linker patches: %v" , err ) )
panic ( fmt . Errorf ( "cannot retrieve linker patches: %v" , err ) )
}
}
outputLinkPath , err := cachePath ( goExe )
outputLinkPath , err := cachePath ( )
if err != nil {
if err != nil {
return "" , nil , err
return "" , nil , err
}
}