Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev' into feature/#151/represent-local-env
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-dubreuil committed Apr 26, 2021
2 parents 1e4043d + b26a224 commit 4b3cf30
Show file tree
Hide file tree
Showing 185 changed files with 1,581 additions and 1,206 deletions.
2 changes: 2 additions & 0 deletions conf/script/src/build_system/build_target/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .build_target_cls import *
from .compiler_instance_targets import *
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import dataclasses
import pathlib
__all__ = ['BuildTarget']

from dataclasses import dataclass
from pathlib import Path
from typing import Final, Optional

import build_system.compiler.build_option.build_type
import build_system.compiler.build_option.sanitizer
import build_system.compiler.installed_instance
from ..compiler import *


@dataclasses.dataclass(order=True)
@dataclass(order=True)
class BuildTarget:
compiler_instance: Final[build_system.compiler.installed_instance.CompilerInstance]
target_build_type: Final[build_system.compiler.build_option.build_type.TargetBuildType]
sanitizer: Final[build_system.compiler.build_option.sanitizer.CompilerSanitizer]
compiler_instance: Final[CompilerInstance]
target_build_type: Final[TargetBuildType]
sanitizer: Final[CompilerSanitizer]

dir: Optional[pathlib.Path]
script_dir: Optional[pathlib.Path]
export_shell_env_symlink: Optional[pathlib.Path]
compiler_env_file: Optional[pathlib.Path]
dir: Optional[Path]
script_dir: Optional[Path]
export_shell_env_symlink: Optional[Path]
compiler_env_file: Optional[Path]

def __init__(self,
compiler_instance: build_system.compiler.installed_instance.CompilerInstance,
target_build_type: build_system.compiler.build_option.build_type.TargetBuildType,
sanitizer: build_system.compiler.build_option.sanitizer.CompilerSanitizer = build_system.compiler.build_option.sanitizer.CompilerSanitizer.NONE) \
compiler_instance: CompilerInstance,
target_build_type: TargetBuildType,
sanitizer: CompilerSanitizer = CompilerSanitizer.NONE) \
-> None:
self.compiler_instance = compiler_instance
self.target_build_type = target_build_type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import dataclasses
__all__ = ['CompilerInstanceTargets']

import build_system.build_target.build_target
import build_system.compiler.installed_instance
from dataclasses import dataclass

from .build_target_cls import *
from ..compiler import *

@dataclasses.dataclass(order=True, frozen=True)

@dataclass(order=True, frozen=True)
class CompilerInstanceTargets:
compiler_instance: build_system.compiler.installed_instance.CompilerInstance
build_targets: list[build_system.build_target.build_target.BuildTarget]
compiler_instance: CompilerInstance
build_targets: list[BuildTarget]

def __iter__(self):
return self.build_targets.__iter__()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .location import *
from .version import *
20 changes: 11 additions & 9 deletions conf/script/src/build_system/cmd/compiler/host/get_info/cli.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
__all__ = ['fetch_compiler_info',
'fetch_compiler_info_with_default_path']

import argparse
from pathlib import Path
from typing import Any, Callable, Optional

import build_system.compiler.family
import utils.cli.arg_parsing
import utils.cli.try_cmd
from build_system.compiler import *
from ext.cli import *


def fetch_compiler_info(compiler_family: build_system.compiler.family.CompilerFamily,
def fetch_compiler_info(compiler_family: CompilerFamily,
fetch_compiler_info_func: Callable[[Optional[Path]], Any],
default_compiler_path: Optional[Path] = None,
desc_compiler_info: str = 'version',
help_path_meaning: str = 'executable') -> None:
arg_parser = argparse.ArgumentParser(description=f"Fetches {compiler_family.name} compiler's {desc_compiler_info}")
utils.cli.arg_parsing.add_optional_path_arg(arg_parser, path_arg_default_value=default_compiler_path,
path_arg_help=f"The {compiler_family.name} compiler's {help_path_meaning} path")
add_optional_path_arg(arg_parser, path_arg_default_value=default_compiler_path,
path_arg_help=f"The {compiler_family.name} compiler's {help_path_meaning} path")

compiler_path: Optional[Path] = utils.cli.arg_parsing.parse_optional_path_arg(arg_parser)
compiler_path: Optional[Path] = parse_optional_path_arg(arg_parser)
arg_parser.parse_args()

def cli_cmd():
compiler_info = fetch_compiler_info_func(compiler_path)
print(compiler_info, end=str())

utils.cli.try_cmd.try_cmd_except_managed_errors(cli_cmd, arg_parser)
try_cmd_except_managed_errors(cli_cmd, arg_parser)


def fetch_compiler_info_with_default_path(compiler_family: build_system.compiler.family.CompilerFamily, fetch_compiler_info_func: Callable[[Path], Any]) -> None:
def fetch_compiler_info_with_default_path(compiler_family: CompilerFamily, fetch_compiler_info_func: Callable[[Path], Any]) -> None:
fetch_compiler_info(compiler_family, fetch_compiler_info_func, compiler_family.value)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .msvc import *
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from build_system.cmd.compiler.host.get_info.location.msvc.impl import find_location
from .cli import *
from .impl import *
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import build_system.cmd.compiler.host.get_info.location.msvc.cli
import utils.cli.main
from ext.cli import *
from . import *


def main():
build_system.cmd.compiler.host.get_info.location.msvc.cli.find()
cli_find_msvc_location()


utils.cli.main.wrap_main(main)
wrap_main(main)
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
__all__ = ['cli_find_msvc_location']

from pathlib import Path
from typing import NoReturn, Optional, Union

import build_system.cmd.compiler.host.get_info.cli
import build_system.compiler.family
import utils.error.cls_def
from ...cli import *
from .impl import *
from build_system.compiler import *
from ext.error import *


def _find_no_arg(compiler_installation_path: Optional[Path] = None) -> Union[Path, NoReturn]:
compiler_installation_path: Optional[Path] = build_system.cmd.compiler.host.get_info.location.msvc.find_location(compiler_installation_path)
compiler_installation_path: Optional[Path] = find_msvc_location(compiler_installation_path)

if compiler_installation_path is None:
raise utils.error.cls_def.CompilerNotFoundError()
raise CompilerNotFoundError()

return compiler_installation_path


def find() -> None:
build_system.cmd.compiler.host.get_info.cli.fetch_compiler_info(build_system.compiler.family.CompilerFamily.MSVC,
_find_no_arg, desc_compiler_info='location',
help_path_meaning='installation')
def cli_find_msvc_location() -> None:
fetch_compiler_info(CompilerFamily.MSVC,
_find_no_arg, desc_compiler_info='location',
help_path_meaning='installation')
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
__all__ = ['find_msvc_location']

from pathlib import Path
from typing import Final, Optional

import vswhere

import utils.error.cls_def
import utils.error.try_external_errors
from ext.error import *
from ext.error.utils import *

_DEFAULT_REQUIRES: Final[list[str]] = [
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
Expand All @@ -20,7 +22,7 @@
_PROP_INSTALLATION_PATH: Final[str] = 'installationPath'


def find_location(compiler_installation_path: Optional[Path] = None) -> Optional[Path]:
def find_msvc_location(compiler_installation_path: Optional[Path] = None) -> Optional[Path]:
if compiler_installation_path is None:
found_compiler_installation_path = vswhere.find_first(latest=True, prerelease=True, products=_ALL_PRODUCTS, prop=_PROP_INSTALLATION_PATH, requires=_DEFAULT_REQUIRES)
else:
Expand All @@ -29,8 +31,8 @@ def find_location(compiler_installation_path: Optional[Path] = None) -> Optional
if found_compiler_installation_path is not None:
found_compiler_installation_path = Path(found_compiler_installation_path.strip())

utils.error.try_external_errors.try_manage_strict_path_resolving(path_to_resolve=found_compiler_installation_path,
external_errors_to_manage={(Exception,): utils.error.cls_def.CompilerNotFoundError})
try_manage_strict_path_resolving(path_to_resolve=found_compiler_installation_path,
external_errors_to_manage={(Exception,): CompilerNotFoundError})

found_compiler_installation_path = found_compiler_installation_path.absolute()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .clang import *
from .gcc import *
from .msvc import *
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from build_system.cmd.compiler.host.get_info.version.clang.impl import fetch_version
from .cli import *
from .impl import *
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import build_system.cmd.compiler.host.get_info.version.clang.cli
import utils.cli.main
from ext.cli import *
from . import *


def main():
build_system.cmd.compiler.host.get_info.version.clang.cli.fetch_gcc_version()
cli_fetch_clang_version()


utils.cli.main.wrap_main(main)
wrap_main(main)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path
__all__ = ['cli_fetch_clang_version']

import build_system.cmd.compiler.host.get_info.version.gnu.cli
import build_system.compiler.family
from build_system.compiler import *
from ..gnu import *


def fetch_gcc_version() -> None:
build_system.cmd.compiler.host.get_info.version.gnu.cli.fetch_version(compiler_family=build_system.compiler.family.CompilerFamily.CLANG)
def cli_fetch_clang_version() -> None:
cli_fetch_gnu_version(compiler_family=CompilerFamily.CLANG)
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import build_system.cmd.compiler.host.get_info.version.gnu
import build_system.compiler.family
import build_system.compiler.version
__all__ = ['fetch_clang_version']

from build_system.compiler import *
from ..gnu import *

def fetch_version() -> build_system.compiler.version.CompilerVersion:
return build_system.cmd.compiler.host.get_info.version.gnu.fetch_version(build_system.compiler.family.CompilerFamily.CLANG.value)

def fetch_clang_version() -> CompilerVersion:
return fetch_gnu_version(CompilerFamily.CLANG.value)
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import build_system.cmd.compiler.host.get_info.version.clang
import build_system.cmd.compiler.host.get_info.version.gcc
import build_system.cmd.compiler.host.get_info.version.msvc
import build_system.compiler.family
import build_system.compiler.version
__all__ = ['fetch_compiler_version_by_family']

fetch_func_by_compiler_family = {build_system.compiler.family.CompilerFamily.MSVC: build_system.cmd.compiler.host.get_info.version.msvc.fetch_version,
build_system.compiler.family.CompilerFamily.CLANG: build_system.cmd.compiler.host.get_info.version.clang.fetch_version,
build_system.compiler.family.CompilerFamily.GCC: build_system.cmd.compiler.host.get_info.version.gcc.fetch_version}
from build_system.compiler import *
from . import *

_fetch_func = {CompilerFamily.MSVC: fetch_msvc_version,
CompilerFamily.CLANG: fetch_clang_version,
CompilerFamily.GCC: fetch_gcc_version}

def fetch_by_compiler_family(compiler_family: build_system.compiler.family.CompilerFamily) -> build_system.compiler.version.CompilerVersion:
return fetch_func_by_compiler_family[compiler_family]()

def fetch_compiler_version_by_family(compiler_family: CompilerFamily) -> CompilerVersion:
return _fetch_func[compiler_family]()
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from build_system.cmd.compiler.host.get_info.version.gcc.impl import fetch_version
from .cli import *
from .impl import *
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import build_system.cmd.compiler.host.get_info.version.gcc.cli
import utils.cli.main
from ext.cli import *
from . import *


def main():
build_system.cmd.compiler.host.get_info.version.gcc.cli.fetch_gcc_version()
cli_fetch_gcc_version()


utils.cli.main.wrap_main(main)
wrap_main(main)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path
__all__ = ['cli_fetch_gcc_version']

import build_system.cmd.compiler.host.get_info.version.gnu.cli
import build_system.compiler.family
from build_system.compiler import *
from ..gnu import *


def fetch_gcc_version() -> None:
build_system.cmd.compiler.host.get_info.version.gnu.cli.fetch_version(compiler_family=build_system.compiler.family.CompilerFamily.GCC)
def cli_fetch_gcc_version() -> None:
cli_fetch_gnu_version(compiler_family=CompilerFamily.GCC)
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import build_system.cmd.compiler.host.get_info.version.gnu
import build_system.compiler.family
import build_system.compiler.version
__all__ = ['fetch_gcc_version']

from build_system.compiler import *
from ..gnu import *

def fetch_version() -> build_system.compiler.version.CompilerVersion:
return build_system.cmd.compiler.host.get_info.version.gnu.fetch_version(build_system.compiler.family.CompilerFamily.GCC.value)

def fetch_gcc_version() -> CompilerVersion:
return fetch_gnu_version(CompilerFamily.GCC.value)
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
__all__ = ['verify_compiler_path',
'interpret_fetched_compiler_version',
'fetch_compiler_version']

from pathlib import Path
from typing import AnyStr, Callable

import build_system.compiler.version
import utils.cmd_integrity
import utils.error.cls_def
from build_system.compiler import *
from ext.cmd_integrity import *
from ext.error import *


def assure_path_integrity(compiler_path: Path) -> None:
def verify_compiler_path(compiler_path: Path) -> None:
"""Assures the integrity of the supplied :param:`compiler_path`
:param compiler_path: The path to the compiler executable file. It must not be a directory.
"""
if not utils.cmd_integrity.cmd_exists(str(compiler_path)):
raise utils.error.cls_def.CompilerNotFoundError()
if not cmd_exists(str(compiler_path)):
raise CompilerNotFoundError()


def interpret_fetched_version(compiler_version_str: AnyStr) -> build_system.compiler.version.CompilerVersion:
return build_system.compiler.version.CompilerVersion.create_from_str(compiler_version_str.strip())
def interpret_fetched_compiler_version(compiler_version_str: AnyStr) -> CompilerVersion:
return CompilerVersion.create_from_str(compiler_version_str.strip())


def fetch(compiler: Path, fetch_compiler_version_func: Callable[[Path], AnyStr]) -> build_system.compiler.version.CompilerVersion:
def fetch_compiler_version(compiler: Path, fetch_compiler_version_func: Callable[[Path], AnyStr]) -> CompilerVersion:
compiler_version_str: AnyStr = fetch_compiler_version_func(compiler)
return interpret_fetched_version(compiler_version_str)
return interpret_fetched_compiler_version(compiler_version_str)
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from build_system.cmd.compiler.host.get_info.version.gnu.impl import fetch_version
from .cli import *
from .impl import *
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import Path
__all__ = ['cli_fetch_gnu_version']

import build_system.cmd.compiler.host.get_info.cli
import build_system.compiler.family
from build_system.compiler import *
from .impl import *
from ...cli import *


def fetch_version(compiler_family: build_system.compiler.family.CompilerFamily) -> None:
build_system.cmd.compiler.host.get_info.cli.fetch_compiler_info_with_default_path(compiler_family=compiler_family,
fetch_compiler_info_func=build_system.cmd.compiler.host.get_info.version.gnu.fetch_version)
def cli_fetch_gnu_version(compiler_family: CompilerFamily) -> None:
fetch_compiler_info_with_default_path(compiler_family=compiler_family,
fetch_compiler_info_func=fetch_gnu_version)
Loading

0 comments on commit 4b3cf30

Please sign in to comment.