| 24 | ) |
| 25 | |
| 26 | func (t *Toolchain) Validate() error { |
| 27 | // Validate toolchain download url. |
| 28 | if t.Url == "" { |
| 29 | return fmt.Errorf("toolchain.url would be http url or local file url, but it's empty") |
| 30 | } |
| 31 | |
| 32 | // Guess toolchain name. |
| 33 | if strings.Contains(t.Url, "Microsoft Visual Studio") { |
| 34 | t.displayName = "Microsoft Visual Studio" |
| 35 | } else { |
| 36 | t.displayName = fileio.Base(t.Url) |
| 37 | } |
| 38 | |
| 39 | // Validate toolchain.sha256. |
| 40 | if !strings.HasPrefix(t.Url, "file:///") && t.SHA256 == "" { |
| 41 | return fmt.Errorf("toolchain.sha256 is empty, it's required for verification and caching") |
| 42 | } |
| 43 | |
| 44 | // Validate toolchain.name. |
| 45 | if strings.TrimSpace(t.Name) == "" { |
| 46 | return fmt.Errorf("toolchain.name is empty") |
| 47 | } |
| 48 | t.Name = strings.ToLower(t.Name) |
| 49 | if t.Name != "msvc" && t.Name != "clang" && t.Name != "clang-cl" { |
| 50 | return fmt.Errorf("toolchain.name should be 'msvc', 'clang' or 'clang-cl'") |
| 51 | } |
| 52 | |
| 53 | // Validate toolchain.system_name. |
| 54 | if strings.TrimSpace(t.SystemName) == "" { |
| 55 | return fmt.Errorf("toolchain.system_name is empty") |
| 56 | } |
| 57 | |
| 58 | // Validate toolchain.system_processor. |
| 59 | if strings.TrimSpace(t.SystemProcessor) == "" { |
| 60 | return fmt.Errorf("toolchain.system_processor is empty") |
| 61 | } |
| 62 | |
| 63 | // Validate toolchain prefix path and convert to absolute path. |
| 64 | if t.Name != "msvc" && t.Name != "clang" && t.Name != "clang-cl" && t.CrosstoolPrefix == "" { |
| 65 | return fmt.Errorf("toolchain.crosstool_prefix should be like 'x86_64-linux-gnu-', but it's empty") |
| 66 | } |
| 67 | |
| 68 | // Validate toolchain.host. |
| 69 | if strings.TrimSpace(t.Host) == "" { |
| 70 | t.Host = "x86_64-w64-mingw32" |
| 71 | } |
| 72 | |
| 73 | // Validate toolchain.cc. |
| 74 | if strings.TrimSpace(t.CC) == "" { |
| 75 | switch t.Name { |
| 76 | case "msvc": |
| 77 | t.CC = "cl.exe" |
| 78 | case "clang": |
| 79 | t.CC = "clang.exe" |
| 80 | case "clang-cl": |
| 81 | t.CC = "clang-cl.exe" |
| 82 | default: |
| 83 | return fmt.Errorf("toolchain.cc is empty") |