()
| 23 | } |
| 24 | |
| 25 | func (t *Toolchain) Validate() error { |
| 26 | // Validate toolchain download url. |
| 27 | if t.Url == "" { |
| 28 | return fmt.Errorf("toolchain.url would be http url or local file url, but it's empty") |
| 29 | } |
| 30 | if t.Url == "file:////usr/bin" { |
| 31 | t.displayName = t.Name |
| 32 | } else { |
| 33 | t.displayName = fileio.Base(t.Url) |
| 34 | } |
| 35 | |
| 36 | // Validate toolchain.sha256. |
| 37 | if !strings.HasPrefix(t.Url, "file:///") && t.SHA256 == "" { |
| 38 | return fmt.Errorf("toolchain.sha256 is empty, it's required for verification and caching") |
| 39 | } |
| 40 | |
| 41 | // Validate toolchain.name. |
| 42 | if strings.TrimSpace(t.Name) == "" { |
| 43 | return fmt.Errorf("toolchain.name is empty") |
| 44 | } |
| 45 | t.Name = strings.ToLower(t.Name) |
| 46 | |
| 47 | if !slices.Contains(supportedToolchains, t.Name) { |
| 48 | return fmt.Errorf("toolchain.name should be %s", strings.Join(supportedToolchains, ", ")) |
| 49 | } |
| 50 | |
| 51 | // Validate toolchain.system_name. |
| 52 | if strings.TrimSpace(t.SystemName) == "" { |
| 53 | return fmt.Errorf("toolchain.system_name is empty") |
| 54 | } |
| 55 | t.SystemName = strings.ToLower(t.SystemName) |
| 56 | |
| 57 | // Validate toolchain.system_processor. |
| 58 | if strings.TrimSpace(t.SystemProcessor) == "" { |
| 59 | return fmt.Errorf("toolchain.system_processor is empty") |
| 60 | } |
| 61 | |
| 62 | // Validate toolchain.crosstool_prefix path and convert to absolute path. |
| 63 | if strings.TrimSpace(t.CrosstoolPrefix) == "" { |
| 64 | return fmt.Errorf("toolchain.crosstool_prefix should be like 'x86_64-linux-gnu-', but it's empty") |
| 65 | } |
| 66 | |
| 67 | // Validate toolchain.c_standard. |
| 68 | if strings.TrimSpace(t.CStandard) != "" && !slices.Contains(buildsystems.CStandards, t.CStandard) { |
| 69 | return fmt.Errorf("toolchain.c_standard should be one of %s", strings.Join(buildsystems.CStandards, ", ")) |
| 70 | } |
| 71 | |
| 72 | // Validate toolchain.cxx_standard. |
| 73 | if strings.TrimSpace(t.CXXStandard) != "" && !slices.Contains(buildsystems.CXXStandards, t.CXXStandard) { |
| 74 | return fmt.Errorf("toolchain.cxx_standard should be one of %s", strings.Join(buildsystems.CXXStandards, ", ")) |
| 75 | } |
| 76 | |
| 77 | // Validate toolchain.host. |
| 78 | if strings.TrimSpace(t.Host) == "" { |
| 79 | return fmt.Errorf("toolchain.host should be like 'x86_64-linux-gnu', but it's empty") |
| 80 | } |
| 81 | |
| 82 | // Validate toolchain.cc. |
no test coverage detected