MCPcopy Create free account
hub / github.com/celer-pkg/celer / CheckTools

Function CheckTools

buildtools/build_tools.go:30–156  ·  view source on GitHub ↗

CheckTools checks if tools exist and repair them if necessary, finally make sure tool paths are in PATH

(ctx context.Context, tools ...string)

Source from the content-addressed store, hash-verified

28
29// CheckTools checks if tools exist and repair them if necessary, finally make sure tool paths are in PATH
30func CheckTools(ctx context.Context, tools ...string) error {
31 // Remove duplicated tools.
32 var uniqueTools []string
33 for _, tool := range tools {
34 if !slices.Contains(uniqueTools, tool) {
35 uniqueTools = append(uniqueTools, tool)
36 }
37 }
38
39 // Determine current architecture.
40 arch := runtime.GOARCH
41 switch arch {
42 case "amd64", "x86_64":
43 arch = "x86_64"
44 case "arm64":
45 arch = "aarch64"
46 }
47
48 // Read and decode static file.
49 staticFile := fmt.Sprintf("static/%s-%s.toml", arch, runtime.GOOS)
50 bytes, err := static.ReadFile(staticFile)
51 if err != nil {
52 return err
53 }
54 var buildTools BuildTools
55 if err := toml.Unmarshal(bytes, &buildTools); err != nil {
56 return err
57 }
58
59 confToolsFile := filepath.Join(dirs.WorkspaceDir, "conf", "buildtools", arch+"-"+runtime.GOOS+".toml")
60 if fileio.PathExists(confToolsFile) {
61 bytes, err := os.ReadFile(confToolsFile)
62 if err != nil {
63 return err
64 }
65 var confBuildTools BuildTools
66 if err := toml.Unmarshal(bytes, &confBuildTools); err != nil {
67 return err
68 }
69 buildTools = buildTools.merge(confBuildTools)
70 }
71
72 // Check if need to install python3 and msys2.
73 for _, tool := range uniqueTools {
74 len := strings.Count(tool, ":")
75 if len == 0 {
76 continue
77 }
78 if len != 1 {
79 return fmt.Errorf("invalid tool format: %s", tool)
80 }
81
82 if strings.HasPrefix(tool, "msys2:") && !slices.Contains(uniqueTools, "msys2") {
83 uniqueTools = append(uniqueTools, "msys2")
84 continue
85 }
86 if strings.HasPrefix(tool, "python3:") && !slices.Contains(uniqueTools, "python3") {
87 uniqueTools = append(uniqueTools, "python3")

Callers 15

checkAllToolsMethod · 0.92
DetectMethod · 0.92
GenBuildToolsVersionsMethod · 0.92
CloneConfMethod · 0.92
clonePortsMethod · 0.92
DetectMethod · 0.92
runInstallMethod · 0.92
executeMethod · 0.92
doUpdateMethod · 0.92

Calls 12

mergeMethod · 0.95
containsMethod · 0.95
findToolMethod · 0.95
PathExistsFunction · 0.92
IfFunction · 0.92
shouldUseCondaFunction · 0.85
CheckSystemToolsFunction · 0.85
pip3InstallFunction · 0.85
setupMSYS2Function · 0.85
SprintfMethod · 0.80
PythonConfigMethod · 0.65
validateMethod · 0.45