@@ -988,23 +988,6 @@ func fixupGoBuildpackARM64(ctx context.Context, config *builder.Config) error {
988988// The paketo go-dist buildpack refer to the amd64 version of Go.
989989// This function replaces these references with references to the arm64 version.
990990func fixupGoDistPkgRefs (buildpackToml , arch string ) error {
991- tomlBytes , err := os .ReadFile (buildpackToml )
992- if err != nil {
993- return err
994- }
995-
996- var config any
997- err = toml .Unmarshal (tomlBytes , & config )
998- if err != nil {
999- return err
1000- }
1001- deps := config .(map [string ]any )["metadata" ].(map [string ]any )["dependencies" ].([]map [string ]any )
1002-
1003- versions := make (map [string ]struct {}, len (deps ))
1004- for _ , dep := range deps {
1005- versions [dep ["version" ].(string )] = struct {}{}
1006- }
1007-
1008991 resp , err := http .Get ("https://go.dev/dl/?mode=json&include=all" )
1009992 if err != nil {
1010993 return err
@@ -1026,47 +1009,52 @@ func fixupGoDistPkgRefs(buildpackToml, arch string) error {
10261009 return err
10271010 }
10281011
1029- var replacements = make ([]struct {
1030- Old string
1031- New string
1032- }, 0 , len (releases ))
1033-
1012+ rels := make (map [string ]struct {
1013+ file string
1014+ checksum string
1015+ })
10341016 for _ , r := range releases {
1035- if _ , ok := versions [strings .TrimPrefix (r .Version , "go" )]; ! ok {
1036- continue
1037- }
1038- var newSha256 , newFilename , oldSha256 , oldFilename string
10391017 for _ , f := range r .Files {
10401018 if f .OS != "linux" {
10411019 continue
10421020 }
1043- switch f .Arch {
1044- case "amd64" :
1045- oldSha256 , oldFilename = f .Sha256 , f .Filename
1046- case arch :
1047- newSha256 , newFilename = f .Sha256 , f .Filename
1048- default :
1049- continue
1021+ if f .Arch == arch {
1022+ rels [strings .TrimPrefix (r .Version , "go" )] = struct {
1023+ file string
1024+ checksum string
1025+ }{file : f .Filename , checksum : f .Sha256 }
10501026 }
10511027 }
1052- replacements = append (replacements ,
1053- struct {
1054- Old string
1055- New string
1056- }{Old : oldSha256 , New : newSha256 },
1057- struct {
1058- Old string
1059- New string
1060- }{Old : "/" + oldFilename , New : "/" + newFilename })
1028+ }
1029+
1030+ tomlBytes , err := os .ReadFile (buildpackToml )
1031+ if err != nil {
1032+ return err
1033+ }
1034+
1035+ var config any
1036+ err = toml .Unmarshal (tomlBytes , & config )
1037+ if err != nil {
1038+ return err
1039+ }
1040+ deps := config .(map [string ]any )["metadata" ].(map [string ]any )["dependencies" ].([]map [string ]any )
10611041
1042+ re := regexp .MustCompile (`checksum=([a-fA-F0-9]+)` )
1043+
1044+ for _ , dep := range deps {
1045+ rel := rels [dep ["version" ].(string )]
1046+ dep ["purl" ] = re .ReplaceAllLiteralString (dep ["purl" ].(string ), "checksum=" + rel .checksum )
1047+ dep ["checksum" ] = "sha256:" + rel .checksum
1048+ dep ["uri" ] = "https://go.dev/dl/" + rel .file
1049+ dep ["arch" ] = arch
10621050 }
10631051
1064- tomlStr := string ( tomlBytes )
1065- for _ , r := range replacements {
1066- tomlStr = strings . ReplaceAll ( tomlStr , r . Old , r . New )
1052+ tomlBytes , err = toml . Marshal ( config )
1053+ if err != nil {
1054+ return err
10671055 }
10681056
1069- err = os .WriteFile (buildpackToml , [] byte ( tomlStr ) , 0644 )
1057+ err = os .WriteFile (buildpackToml , tomlBytes , 0644 )
10701058 if err != nil {
10711059 return err
10721060 }
@@ -1473,6 +1461,7 @@ func fixupCPythonDistPkgRefs(ctx context.Context, buildpackToml string) error {
14731461 }
14741462 dep ["uri" ] = uri
14751463 dep ["checksum" ] = checksum
1464+ dep ["arch" ] = "arm64"
14761465 }
14771466
14781467 bs , err := toml .Marshal (config )
0 commit comments