Skip to content

Commit cd3f26e

Browse files
partoufclaude
andcommitted
Fix version handling and library type detection issues
- Fix double 'v' prefix issue by implementing git tag lookup for version format detection - Improve library type detection to respect existing configuration (both local and remote) - Add --type parameter support to CLI for direct library type specification - Add CSHARED to LibraryType enum for C shared libraries - Update documentation with --type parameter examples 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 85a0c2d commit cd3f26e

6 files changed

Lines changed: 66 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ gh auth login
4646
# Add a Rust library
4747
./run.sh --lang=rust --lib=serde --ver=1.0.195
4848

49-
# Add a C++ library
49+
# Add a C++ library with automatic type detection
5050
./run.sh --lang=cpp --lib=https://github.com/fmtlib/fmt --ver=10.2.1
5151

52+
# Add a header-only C++ library
53+
./run.sh --lang=cpp --lib=https://github.com/bobluppes/graaf --ver=v1.1.1 --type=header-only
54+
5255
# Preview changes first
5356
./run.sh --verify --lang=rust --lib=tokio --ver=1.35.0
5457
```

cli/main.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from core.fortran_handler import FortranHandler
1414
from core.git_operations import GitManager
1515
from core.github_auth import get_github_token_via_gh_cli, get_github_token_via_oauth
16-
from core.models import Language, LibraryConfig
16+
from core.models import Language, LibraryConfig, LibraryType
1717
from core.rust_handler import RustLibraryHandler
1818
from core.subprocess_utils import run_ce_install_command
1919
from core.ui_utils import (
@@ -718,6 +718,13 @@ def process_fortran_library(
718718
)
719719
@click.option("--lib", help="Library name (for Rust) or GitHub URL (for other languages)")
720720
@click.option("--ver", help="Library version (comma-separated for multiple versions)")
721+
@click.option(
722+
"--type",
723+
type=click.Choice(
724+
["header-only", "packaged-headers", "static", "shared", "cshared"], case_sensitive=False
725+
),
726+
help="Library type (for C/C++ libraries)",
727+
)
721728
def main(
722729
debug: bool,
723730
github_token: str | None,
@@ -729,6 +736,7 @@ def main(
729736
lang: str | None,
730737
lib: str | None,
731738
ver: str | None,
739+
type: str | None,
732740
):
733741
"""CLI tool to add libraries to Compiler Explorer"""
734742
if debug:
@@ -782,6 +790,18 @@ def main(
782790
elif language == Language.FORTRAN:
783791
config.library_id = FortranHandler.suggest_library_id_static(lib)
784792

793+
# Set library type if provided
794+
if type:
795+
type_map = {
796+
"header-only": LibraryType.HEADER_ONLY,
797+
"packaged-headers": LibraryType.PACKAGED_HEADERS,
798+
"static": LibraryType.STATIC,
799+
"shared": LibraryType.SHARED,
800+
"cshared": LibraryType.CSHARED,
801+
}
802+
config.library_type = type_map[type.lower()]
803+
click.echo(f"✓ Using specified library type: {config.library_type.value}")
804+
785805
# Normalize versions by checking git tags
786806
click.echo("Checking git tags for version format...")
787807
config.normalize_versions_with_git_lookup()

core/c_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def detect_library_type(
6969
elif existing_config.get("type") == "shared":
7070
logger.info(f"Using existing configuration: {library_id} is shared")
7171
return True, LibraryType.SHARED
72+
elif existing_config.get("type") == "cshared":
73+
logger.info(f"Using existing configuration: {library_id} is cshared")
74+
return True, LibraryType.CSHARED
7275
# If existing config doesn't have clear type info, continue with detection
7376

7477
with tempfile.TemporaryDirectory() as tmpdir:

core/cpp_handler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def detect_library_type(
9494
elif lib_type == "shared":
9595
logger.info(f"Using existing configuration: {library_id} is shared")
9696
return True, LibraryType.SHARED
97+
elif lib_type == "cshared":
98+
logger.info(f"Using existing configuration: {library_id} is cshared")
99+
return True, LibraryType.CSHARED
97100

98101
# If it's type: github with no explicit build_type, it might be header-only by default
99102
if lib_type == "github" and build_type is None:
@@ -153,7 +156,11 @@ def add_library(self, config: LibraryConfig) -> str | None:
153156

154157
if config.library_type:
155158
subcommand.extend(["--type", config.library_type.value])
159+
logger.info(f"Adding library with type: {config.library_type.value}")
160+
else:
161+
logger.warning("No library type specified for cpp-library add command")
156162

163+
logger.info(f"Running command: {' '.join(subcommand)}")
157164
result = run_ce_install_command(subcommand, cwd=self.infra_path, debug=self.debug)
158165

159166
if result.returncode != 0:
@@ -187,6 +194,21 @@ def add_library(self, config: LibraryConfig) -> str | None:
187194

188195
if library_id:
189196
logger.info(f"Successfully added C++ library with ID: {library_id}")
197+
198+
# Debug: Check what was actually written to libraries.yaml
199+
try:
200+
existing_config = check_existing_library_config(
201+
str(config.github_url), library_id, self.infra_path
202+
)
203+
if existing_config:
204+
logger.info(f"Library config in libraries.yaml: {existing_config}")
205+
else:
206+
logger.warning(
207+
f"Could not find {library_id} in libraries.yaml after adding"
208+
)
209+
except Exception as e:
210+
logger.warning(f"Could not check libraries.yaml: {e}")
211+
190212
return library_id
191213
else:
192214
logger.warning("Could not parse library ID from output, using suggested ID")

core/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LibraryType(str, Enum):
3030
PACKAGED_HEADERS = "packaged-headers"
3131
STATIC = "static"
3232
SHARED = "shared"
33+
CSHARED = "cshared"
3334

3435

3536
def check_git_tag_exists(repo_url: str, tag: str) -> bool:

docs/quick-start.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ Get detailed output for troubleshooting:
7171
./run.sh --debug --lang=cpp --lib=https://github.com/nlohmann/json --ver=3.11.3
7272
```
7373

74+
### Specify Library Type (C/C++ only)
75+
Skip automatic detection and specify the library type directly:
76+
```bash
77+
# Header-only library
78+
./run.sh --lang=cpp --lib=https://github.com/bobluppes/graaf --ver=v1.1.1 --type=header-only
79+
80+
# Packaged headers library
81+
./run.sh --lang=cpp --lib=https://github.com/eigen/eigen --ver=3.4.0 --type=packaged-headers
82+
83+
# Shared library (requires compilation)
84+
./run.sh --lang=c --lib=https://github.com/curl/curl --ver=8.5.0 --type=cshared
85+
```
86+
87+
Valid types: `header-only`, `packaged-headers`, `static`, `shared`, `cshared`
88+
7489
### Test Installation (C++ only)
7590
Validate that the library installs correctly:
7691
```bash

0 commit comments

Comments
 (0)