@@ -988,23 +988,6 @@ func fixupGoBuildpackARM64(ctx context.Context, config *builder.Config) error {
988
988
// The paketo go-dist buildpack refer to the amd64 version of Go.
989
989
// This function replaces these references with references to the arm64 version.
990
990
func 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
-
1008
991
resp , err := http .Get ("https://go.dev/dl/?mode=json&include=all" )
1009
992
if err != nil {
1010
993
return err
@@ -1026,47 +1009,52 @@ func fixupGoDistPkgRefs(buildpackToml, arch string) error {
1026
1009
return err
1027
1010
}
1028
1011
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
+ })
1034
1016
for _ , r := range releases {
1035
- if _ , ok := versions [strings .TrimPrefix (r .Version , "go" )]; ! ok {
1036
- continue
1037
- }
1038
- var newSha256 , newFilename , oldSha256 , oldFilename string
1039
1017
for _ , f := range r .Files {
1040
1018
if f .OS != "linux" {
1041
1019
continue
1042
1020
}
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 }
1050
1026
}
1051
1027
}
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 )
1061
1041
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
1062
1050
}
1063
1051
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
1067
1055
}
1068
1056
1069
- err = os .WriteFile (buildpackToml , [] byte ( tomlStr ) , 0644 )
1057
+ err = os .WriteFile (buildpackToml , tomlBytes , 0644 )
1070
1058
if err != nil {
1071
1059
return err
1072
1060
}
@@ -1473,6 +1461,7 @@ func fixupCPythonDistPkgRefs(ctx context.Context, buildpackToml string) error {
1473
1461
}
1474
1462
dep ["uri" ] = uri
1475
1463
dep ["checksum" ] = checksum
1464
+ dep ["arch" ] = "arm64"
1476
1465
}
1477
1466
1478
1467
bs , err := toml .Marshal (config )
0 commit comments