Skip to content

Commit f300e0c

Browse files
authored
Merge pull request #8 from compiler-explorer/add-build-test-feature
Add GO library support
2 parents 7759ca7 + 4069a3d commit f300e0c

13 files changed

Lines changed: 2970 additions & 42 deletions

cli/main.py

Lines changed: 513 additions & 28 deletions
Large diffs are not rendered by default.

cli/questions.py

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import re
2+
from pathlib import Path
3+
14
import inquirer
25

6+
from core.cpp_handler import CppHandler
7+
from core.go_handler import GoHandler, detect_import_path, resolve_go_module
38
from core.library_utils import filter_main_cmake_targets
49
from core.models import BuildTool, Language, LibraryConfig, LibraryType, LinkType
510

@@ -41,10 +46,83 @@ def ask_library_questions() -> LibraryConfig:
4146
config = LibraryConfig(
4247
language=language, name=rust_name_answer["name"], version=rust_version_answer["version"]
4348
)
44-
# Rust versions don't need git tag checking since they use crates.io
4549
return config
4650

47-
# For non-Rust languages, ask for GitHub URL
51+
# Special handling for Go - need module path and version
52+
if language == Language.GO:
53+
go_module_question = [
54+
inquirer.Text(
55+
"module",
56+
message="What's the Go module path? (e.g., github.com/google/uuid)",
57+
validate=lambda _, x: len(x.strip()) > 0 and "/" in x,
58+
)
59+
]
60+
go_module_answer = inquirer.prompt(go_module_question)
61+
62+
go_version_question = [
63+
inquirer.Text(
64+
"version",
65+
message="What's the version(s)? (e.g., v1.6.0, comma-separated for multiple)",
66+
validate=lambda _, x: len(x.strip()) > 0,
67+
)
68+
]
69+
go_version_answer = inquirer.prompt(go_version_question)
70+
71+
module_path = go_module_answer["module"]
72+
version_str = go_version_answer["version"]
73+
first_version = version_str.split(",")[0].strip()
74+
75+
# Resolve module path (handles subpackage paths)
76+
print("\nResolving module path...")
77+
resolved_module, resolved_import = resolve_go_module(module_path, first_version)
78+
if resolved_module != module_path:
79+
print(f"Resolved subpackage to module: {resolved_module}")
80+
print(f" import path: {resolved_import}")
81+
module_path = resolved_module
82+
83+
suggested_id = GoHandler.suggest_library_id_static(module_path)
84+
85+
go_id_question = [
86+
inquirer.Text(
87+
"library_id",
88+
message="What should be the library ID? (lowercase with underscores)",
89+
default=suggested_id,
90+
validate=lambda _, x: bool(re.match(r"^[a-z][a-z0-9_]*$", x.strip()))
91+
or "Must start with a letter, lowercase alphanumeric and underscores only",
92+
)
93+
]
94+
go_id_answer = inquirer.prompt(go_id_question)
95+
96+
# Auto-detect import path if not already resolved from subpackage
97+
detected_import_path = resolved_import
98+
if not detected_import_path:
99+
print("\nChecking module structure...")
100+
detected_import_path = detect_import_path(module_path, first_version)
101+
if detected_import_path:
102+
print(f"Root package not importable, detected: {detected_import_path}")
103+
else:
104+
print("Root package is importable")
105+
106+
go_import_path_question = [
107+
inquirer.Text(
108+
"import_path",
109+
message="Import path override (leave empty if root is importable)",
110+
default=detected_import_path or "",
111+
)
112+
]
113+
go_import_path_answer = inquirer.prompt(go_import_path_question)
114+
import_path = go_import_path_answer["import_path"].strip() or None
115+
116+
config = LibraryConfig(
117+
language=language,
118+
module=module_path,
119+
version=version_str,
120+
library_id=go_id_answer["library_id"],
121+
import_path=import_path,
122+
)
123+
return config
124+
125+
# For non-Rust/Go languages, ask for GitHub URL
48126
github_question = [
49127
inquirer.Text(
50128
"github_url",
@@ -76,10 +154,6 @@ def ask_library_questions() -> LibraryConfig:
76154

77155
# C++ specific questions
78156
if language == Language.CPP:
79-
# First, ask for library ID
80-
from core.cpp_handler import CppHandler
81-
82-
# Use a temporary instance just for ID suggestion (no path needed)
83157
suggested_id = CppHandler.suggest_library_id_static(github_answer["github_url"])
84158

85159
library_id_question = [
@@ -94,11 +168,7 @@ def ask_library_questions() -> LibraryConfig:
94168
library_id_answer = inquirer.prompt(library_id_question)
95169
config_data["library_id"] = library_id_answer["library_id"]
96170

97-
# Detect library type by cloning and checking
98171
print("\nAnalyzing repository to detect library type...")
99-
# Create a temporary handler just for detection (no ce_install setup needed)
100-
from pathlib import Path
101-
102172
cpp_handler = CppHandler(Path.home(), setup_ce_install=False, debug=False)
103173
is_valid, detected_type, cmake_targets = cpp_handler.detect_library_type(
104174
github_answer["github_url"], library_id_answer["library_id"]

0 commit comments

Comments
 (0)