| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package cipd | 5 package cipd |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strings" | 8 "strings" |
| 9 | 9 |
| 10 "github.com/luci/luci-go/vpython/api/vpython" | 10 "github.com/luci/luci-go/vpython/api/vpython" |
| 11 ) | 11 ) |
| 12 | 12 |
| 13 // PlatformForPEP425Tag returns the CIPD platform inferred from a given Python | 13 // PlatformForPEP425Tag returns the CIPD platform inferred from a given Python |
| 14 // PEP425 tag. | 14 // PEP425 tag. |
| 15 // | 15 // |
| 16 // If the platform could not be determined, an empoty string will be returned. | 16 // If the platform could not be determined, an empty string will be returned. |
| 17 func PlatformForPEP425Tag(t *vpython.Pep425Tag) string { | 17 func PlatformForPEP425Tag(t *vpython.PEP425Tag) string { |
| 18 » switch archSplit := strings.SplitN(t.Arch, "_", 2); archSplit[0] { | 18 » switch platSplit := strings.SplitN(t.Platform, "_", 2); platSplit[0] { |
| 19 case "linux", "manylinux1": | 19 case "linux", "manylinux1": |
| 20 // Grab the remainder. | 20 // Grab the remainder. |
| 21 // | 21 // |
| 22 // Examples: | 22 // Examples: |
| 23 // - linux_i686 | 23 // - linux_i686 |
| 24 // - manylinux1_x86_64 | 24 // - manylinux1_x86_64 |
| 25 // - linux_arm64 | 25 // - linux_arm64 |
| 26 cpu := "" | 26 cpu := "" |
| 27 » » if len(archSplit) > 1 { | 27 » » if len(platSplit) > 1 { |
| 28 » » » cpu = archSplit[1] | 28 » » » cpu = platSplit[1] |
| 29 } | 29 } |
| 30 switch cpu { | 30 switch cpu { |
| 31 case "i686": | 31 case "i686": |
| 32 return "linux-386" | 32 return "linux-386" |
| 33 case "x86_64": | 33 case "x86_64": |
| 34 return "linux-amd64" | 34 return "linux-amd64" |
| 35 case "arm64": | 35 case "arm64": |
| 36 return "linux-arm64" | 36 return "linux-arm64" |
| 37 case "mipsel", "mips": | 37 case "mipsel", "mips": |
| 38 return "linux-mips32" | 38 return "linux-mips32" |
| 39 case "mips64": | 39 case "mips64": |
| 40 return "linux-mips64" | 40 return "linux-mips64" |
| 41 default: | 41 default: |
| 42 // All remaining "arm*" get the "armv6l" CIPD platform. | 42 // All remaining "arm*" get the "armv6l" CIPD platform. |
| 43 if strings.HasPrefix(cpu, "arm") { | 43 if strings.HasPrefix(cpu, "arm") { |
| 44 return "linux-armv6l" | 44 return "linux-armv6l" |
| 45 } | 45 } |
| 46 return "" | 46 return "" |
| 47 } | 47 } |
| 48 | 48 |
| 49 case "macosx": | 49 case "macosx": |
| 50 // Grab the last token. | 50 // Grab the last token. |
| 51 // | 51 // |
| 52 // Examples: | 52 // Examples: |
| 53 // - macosx_10_10_intel | 53 // - macosx_10_10_intel |
| 54 // - macosx_10_10_i386 | 54 // - macosx_10_10_i386 |
| 55 » » if len(archSplit) == 1 { | 55 » » if len(platSplit) == 1 { |
| 56 return "" | 56 return "" |
| 57 } | 57 } |
| 58 » » suffixSplit := strings.SplitN(archSplit[1], "_", -1) | 58 » » suffixSplit := strings.SplitN(platSplit[1], "_", -1) |
| 59 switch suffixSplit[len(suffixSplit)-1] { | 59 switch suffixSplit[len(suffixSplit)-1] { |
| 60 case "intel", "x86_64", "fat64", "universal": | 60 case "intel", "x86_64", "fat64", "universal": |
| 61 return "mac-amd64" | 61 return "mac-amd64" |
| 62 case "i386", "fat32": | 62 case "i386", "fat32": |
| 63 return "mac-386" | 63 return "mac-386" |
| 64 default: | 64 default: |
| 65 return "" | 65 return "" |
| 66 } | 66 } |
| 67 | 67 |
| 68 case "win32": | 68 case "win32": |
| 69 // win32 | 69 // win32 |
| 70 return "windows-386" | 70 return "windows-386" |
| 71 case "win": | 71 case "win": |
| 72 // Examples: | 72 // Examples: |
| 73 // - win_amd64 | 73 // - win_amd64 |
| 74 » » if len(archSplit) == 1 { | 74 » » if len(platSplit) == 1 { |
| 75 return "" | 75 return "" |
| 76 } | 76 } |
| 77 » » switch archSplit[1] { | 77 » » switch platSplit[1] { |
| 78 case "amd64": | 78 case "amd64": |
| 79 return "windows-amd64" | 79 return "windows-amd64" |
| 80 default: | 80 default: |
| 81 return "" | 81 return "" |
| 82 } | 82 } |
| 83 | 83 |
| 84 default: | 84 default: |
| 85 return "" | 85 return "" |
| 86 } | 86 } |
| 87 } | 87 } |
| OLD | NEW |