(tools []string)
| 18 | } |
| 19 | |
| 20 | func (p Port) GenBuildToolsVersions(tools []string) (string, error) { |
| 21 | // Ensure tools are validated and their paths are set in PATH, |
| 22 | if err := buildtools.CheckTools(p.ctx, tools...); err != nil { |
| 23 | return "", fmt.Errorf("failed to check tools -> %w", err) |
| 24 | } |
| 25 | |
| 26 | var buffer strings.Builder |
| 27 | |
| 28 | for _, tool := range tools { |
| 29 | toolName, _, _ := strings.Cut(tool, "@") |
| 30 | args, ok := toolVersionArgs[toolName] |
| 31 | if !ok { |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | // For python3:xxx tools, use the Python executable from virtual environment. |
| 36 | cmdName, _, _ := strings.Cut(toolName, ":") |
| 37 | if cmdName == "python3" && buildtools.PythonTool != nil { |
| 38 | cmdName = buildtools.PythonTool.Path |
| 39 | } |
| 40 | |
| 41 | // Try to execute the command to get the version. |
| 42 | executor := cmd.NewExecutor("", cmdName, args...) |
| 43 | out, err := executor.ExecuteOutput() |
| 44 | if err != nil { |
| 45 | return "", fmt.Errorf("failed to get tool version of %s", tool) |
| 46 | } |
| 47 | |
| 48 | line := strings.TrimSpace(strings.Split(out, "\n")[0]) |
| 49 | if line != "" { |
| 50 | if buffer.Len() > 0 { |
| 51 | buffer.WriteString("\n") |
| 52 | } |
| 53 | buffer.WriteString(tool) |
| 54 | buffer.WriteString(": ") |
| 55 | buffer.WriteString(line) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return buffer.String(), nil |
| 60 | } |
nothing calls this directly
no test coverage detected