@ -33,19 +33,16 @@ const (
baseSrcSubdir = "src"
baseSrcSubdir = "src"
)
)
//go:embed patches/* .patch
//go:embed patches/* /* .patch
var linkerPatchesFS embed . FS
var linkerPatchesFS embed . FS
func loadLinkerPatches ( ) ( version string , modFiles map [ string ] bool , patches [ ] [ ] byte , err error ) {
func loadLinkerPatches ( majorGoVersion string ) ( version string , modFiles map [ string ] bool , patches [ ] [ ] byte , err error ) {
modFiles = make ( map [ string ] bool )
modFiles = make ( map [ string ] bool )
versionHash := sha256 . New ( )
versionHash := sha256 . New ( )
err = fs . WalkDir ( linkerPatchesFS , "." , func ( path string , d fs . DirEntry , err error ) error {
if err := fs . WalkDir ( linkerPatchesFS , "patches/" + majorGoVersion , func ( path string , d fs . DirEntry , err error ) error {
if err != nil {
if err != nil || d . IsDir ( ) {
return err
return err
}
}
if d . IsDir ( ) {
return nil
}
patchBytes , err := linkerPatchesFS . ReadFile ( path )
patchBytes , err := linkerPatchesFS . ReadFile ( path )
if err != nil {
if err != nil {
@ -68,10 +65,8 @@ func loadLinkerPatches() (version string, modFiles map[string]bool, patches [][]
}
}
patches = append ( patches , patchBytes )
patches = append ( patches , patchBytes )
return nil
return nil
} )
} ) ; err != nil {
return "" , nil , nil , err
if err != nil {
return
}
}
version = base64 . RawStdEncoding . EncodeToString ( versionHash . Sum ( nil ) )
version = base64 . RawStdEncoding . EncodeToString ( versionHash . Sum ( nil ) )
return
return
@ -230,7 +225,11 @@ func buildLinker(workingDir string, overlay map[string]string, outputLinkPath st
}
}
func PatchLinker ( goRoot , goVersion , tempDir string ) ( string , func ( ) , error ) {
func PatchLinker ( goRoot , goVersion , tempDir string ) ( string , func ( ) , error ) {
patchesVer , modFiles , patches , err := loadLinkerPatches ( )
// rxVersion looks for a version like "go1.19" or "go1.20"
rxVersion := regexp . MustCompile ( ` go\d+\.\d+ ` )
majorGoVersion := rxVersion . FindString ( goVersion )
patchesVer , modFiles , patches , err := loadLinkerPatches ( majorGoVersion )
if err != nil {
if err != nil {
panic ( fmt . Errorf ( "cannot retrieve linker patches: %v" , err ) )
panic ( fmt . Errorf ( "cannot retrieve linker patches: %v" , err ) )
}
}