Skip to content

Commit d30093f

Browse files
committed
refactorings and fix libpaths maybe
1 parent bc8f44a commit d30093f

File tree

8 files changed

+1063
-1009
lines changed

8 files changed

+1063
-1009
lines changed

bin/lib/cmake_cache_extractor.py

Lines changed: 585 additions & 0 deletions
Large diffs are not rendered by default.

bin/lib/compiler_cache.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
from pathlib import Path
44
from typing import Dict, Optional
55

6-
from lib.compiler_utils import CMakeCacheExtractor, CompilerPropertyManager, PlatformEnvironmentManager, ScriptExecutor
6+
from lib.cmake_cache_extractor import CMakeCacheExtractor
7+
from lib.compiler_info import CompilerInfo
8+
from lib.compiler_properties import CompilerPropertyManager
79
from lib.library_platform import LibraryPlatform
10+
from lib.platform_environment import PlatformEnvironmentManager
11+
from lib.script_executor import ScriptExecutor
812

913

1014
class CompilerCacheExtractor:
@@ -61,8 +65,6 @@ def setup_compiler_environment(self, compiler_id: str, compiler_props: dict) ->
6165
compiler_info = self.property_manager.get_compiler_info("c++", compiler_id)
6266
if not compiler_info:
6367
# Fallback to creating CompilerInfo from props if not found in manager
64-
from lib.compiler_utils import CompilerInfo
65-
6668
compiler_info = CompilerInfo(compiler_id, compiler_props)
6769

6870
# Use the shared environment manager with default toolchain and arch
@@ -87,8 +89,6 @@ def extract_cache_for_compiler(
8789
compiler_info = self.property_manager.get_compiler_info("c++", compiler_id)
8890
if not compiler_info:
8991
# Fallback to creating CompilerInfo from props if not found in manager
90-
from lib.compiler_utils import CompilerInfo
91-
9292
compiler_info = CompilerInfo(compiler_id, compiler_props)
9393

9494
# Create compiler-specific output directory
@@ -114,6 +114,7 @@ def extract_cache_for_compiler(
114114
keep_temp_dir=False,
115115
compiler_id=compiler_id,
116116
upload_to_s3=upload_to_s3,
117+
compiler_info=compiler_info,
117118
)
118119

119120
if success:

bin/lib/compiler_info.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python3
2+
3+
from pathlib import Path
4+
5+
6+
class CompilerInfo:
7+
"""Typed wrapper around compiler properties with convenience methods."""
8+
9+
def __init__(self, compiler_id: str, props: dict):
10+
self.id = compiler_id
11+
self._props = props
12+
13+
@property
14+
def executable(self) -> str:
15+
return self._props.get("exe", "")
16+
17+
@property
18+
def compiler_type(self) -> str:
19+
return self._props.get("compilerType", "")
20+
21+
@property
22+
def options(self) -> str:
23+
return self._props.get("options", "")
24+
25+
@property
26+
def include_path(self) -> str:
27+
return self._props.get("includePath", "")
28+
29+
@property
30+
def lib_path(self) -> str:
31+
return self._props.get("libPath", "")
32+
33+
@property
34+
def ld_path(self) -> str:
35+
return self._props.get("ldPath", "")
36+
37+
@property
38+
def is_msvc(self) -> bool:
39+
return self.compiler_type == "win32-vc"
40+
41+
@property
42+
def is_mingw_gcc(self) -> bool:
43+
return self.compiler_type == "win32-mingw-gcc"
44+
45+
@property
46+
def is_mingw_clang(self) -> bool:
47+
return self.compiler_type == "win32-mingw-clang"
48+
49+
@property
50+
def is_windows_compiler(self) -> bool:
51+
return self.is_msvc or self.is_mingw_gcc or self.is_mingw_clang
52+
53+
@property
54+
def is_clang(self) -> bool:
55+
return self.compiler_type == "clang"
56+
57+
@property
58+
def is_gcc_like(self) -> bool:
59+
return self.compiler_type in ["", "gcc"]
60+
61+
@property
62+
def exists(self) -> bool:
63+
"""Check if the compiler executable exists on the filesystem."""
64+
return bool(self.executable and Path(self.executable).exists())
65+
66+
def get_c_compiler(self) -> str:
67+
"""
68+
Derive C compiler path from C++ compiler path.
69+
This logic is extracted from library_builder.py writebuildscript()
70+
"""
71+
exe = self.executable
72+
73+
# Special case for EDG compilers
74+
if self.compiler_type == "edg":
75+
return exe
76+
77+
# Windows executable handling
78+
if exe.endswith(".exe"):
79+
compilerexecc = exe.replace("++.exe", "")
80+
if exe.endswith("clang++.exe"):
81+
compilerexecc = f"{compilerexecc}.exe"
82+
elif exe.endswith("g++.exe"):
83+
compilerexecc = f"{compilerexecc}cc.exe"
84+
elif self.compiler_type == "edg":
85+
compilerexecc = exe
86+
else:
87+
if not compilerexecc.endswith(".exe"):
88+
compilerexecc = compilerexecc + ".exe"
89+
return compilerexecc
90+
91+
# Linux/Unix executable handling
92+
else:
93+
compilerexecc = exe[:-2] # Remove last 2 chars (++)
94+
if exe.endswith("clang++"):
95+
compilerexecc = f"{compilerexecc}" # clang++ -> clang
96+
elif exe.endswith("g++"):
97+
compilerexecc = f"{compilerexecc}cc" # g++ -> gcc
98+
elif self.compiler_type == "edg":
99+
compilerexecc = exe
100+
return compilerexecc

bin/lib/compiler_properties.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
3+
from typing import Dict, Optional, Tuple
4+
5+
from lib.amazon_properties import get_properties_compilers_and_libraries
6+
from lib.compiler_info import CompilerInfo
7+
from lib.library_platform import LibraryPlatform
8+
9+
10+
class CompilerPropertyManager:
11+
"""Manages loading and caching of compiler properties."""
12+
13+
def __init__(self, logger, platform: LibraryPlatform):
14+
self.logger = logger
15+
self.platform = platform
16+
self._props_cache: Dict[str, Tuple[Dict[str, dict], Dict[str, dict]]] = {}
17+
18+
def get_compiler_properties(
19+
self, language: str, force_reload: bool = False
20+
) -> Tuple[Dict[str, dict], Dict[str, dict]]:
21+
"""Load and cache compiler properties for a language."""
22+
cache_key = f"{language}_{self.platform.value}"
23+
24+
if not force_reload and cache_key in self._props_cache:
25+
return self._props_cache[cache_key]
26+
27+
result = get_properties_compilers_and_libraries(language, self.logger, self.platform, True)
28+
self._props_cache[cache_key] = result
29+
30+
self.logger.info(f"Loaded {len(result[0])} total compilers for {self.platform.value}")
31+
return result
32+
33+
def get_compiler_info(self, language: str, compiler_id: str) -> Optional[CompilerInfo]:
34+
"""Get a CompilerInfo object for a specific compiler."""
35+
compilers, _ = self.get_compiler_properties(language)
36+
37+
if compiler_id not in compilers:
38+
return None
39+
40+
return CompilerInfo(compiler_id, compilers[compiler_id])
41+
42+
def get_supported_compilers(self, language: str, platform_filter: bool = True) -> Dict[str, CompilerInfo]:
43+
"""Get all supported compilers for a language, optionally filtered by platform compatibility."""
44+
compilers, _ = self.get_compiler_properties(language)
45+
supported = {}
46+
47+
for compiler_id, props in compilers.items():
48+
compiler_info = CompilerInfo(compiler_id, props)
49+
50+
# Check if compiler exists
51+
if not compiler_info.exists:
52+
self.logger.debug(f"Skipping {compiler_id}: executable {compiler_info.executable} not found")
53+
continue
54+
55+
# Platform-specific filtering
56+
if platform_filter:
57+
if self.platform == LibraryPlatform.Windows:
58+
# For Windows, support MSVC, MinGW GCC, and MinGW Clang compilers
59+
if not compiler_info.is_windows_compiler:
60+
continue
61+
else:
62+
# For Linux, support GCC, Clang, and other Unix compilers (exclude Windows compilers)
63+
if compiler_info.is_windows_compiler:
64+
continue
65+
66+
supported[compiler_id] = compiler_info
67+
68+
self.logger.info(f"Found {len(supported)} supported compilers on {self.platform.value}")
69+
return supported

0 commit comments

Comments
 (0)