Files
chinook/chinook/compiler/_compiler.py
T
SoraKatadzuma b7b99783c8 Added testing
Preparing profiles and dependencies, but added testing to separate them from regular targets and avoid the need for a 'testing' profile which could negatively impact configuration size and readability.
2026-06-26 03:45:38 +00:00

76 lines
1.7 KiB
Python

from dataclasses import dataclass
from dataclasses import field
from logging import getLogger
from logging import Logger
from pathlib import Path
from ..models import Abi
from ..models import Result
from ..models import Tooling
from ._clang import ClangDriver
from ._driver import CompilerDriver
from ._gnuc import GnucDriver
from ._mingw import MingwDriver
from ._msvc import MsvcDriver
from ._options import CompilerOptions
_logger = getLogger("chinook")
@dataclass
class Compiler:
__COMPILER_MAPPING = {
Abi.GNU: GnucDriver,
Abi.MSVC: MsvcDriver,
Abi.MINGW: MingwDriver,
Abi.ANDROID: ClangDriver,
Abi.ELF: GnucDriver,
}
tooling: Tooling
logger: Logger = field(default=_logger)
_driver: CompilerDriver = field(init=False)
def __post_init__(self) -> None:
self._driver = Compiler._driver_for(self.tooling, self.logger)
def compile_program(
self,
options: CompilerOptions,
dstpath: Path
) -> Result:
return self._driver.compile_program(options, dstpath)
def compile_archive(
self,
options: CompilerOptions,
dstpath: Path
) -> Result:
return self._driver.compile_archive(options, dstpath)
def compile_library(
self,
options: CompilerOptions,
dstpath: Path
) -> Result:
return self._driver.compile_library(options, dstpath)
def compile_object(
self,
options: CompilerOptions,
srcpath: Path,
dstPath: Path
) -> Result:
return self._driver.compile_object(options, srcpath, dstPath)
@classmethod
def _driver_for(
cls,
tooling: Tooling,
logger: Logger
) -> CompilerDriver:
from ..models import Triple
triples = tooling.when or [Triple.current()]
driver = cls.__COMPILER_MAPPING.get(triples[0].abi, GnucDriver)
return driver(tooling, logger)