Using FileConfig instead of ToolchainConfig, unique_folder_name separation

This commit is contained in:
MaXFeeD
2025-05-09 17:06:03 +03:00
parent 8b50098638
commit 4cff548641
4 changed files with 17 additions and 17 deletions
+2 -10
View File
@@ -5,11 +5,6 @@ from typing import Callable, Final, List, Optional
from .config import Config, FileConfig
from .shell import abort
try:
from hashlib import blake2s as encode
except ImportError:
from hashlib import md5 as encode
class ToolchainConfig(FileConfig):
def __init__(self, path: str, defaults: Optional[Config] = None) -> None:
@@ -72,11 +67,8 @@ class MakeConfig(ToolchainConfig):
abort(f"Not found {basename(path)!r}, are you sure that selected project exists?")
self.current_project = defaults.get_value("currentProject")
super().__init__(path, defaults=defaults)
self.project_unique_name = self.unique_folder_name(self.directory)
from .output_directory import unique_folder_name
self.project_unique_name = unique_folder_name(self.directory)
def get_build_path(self, relative_path: str) -> str:
return self.defaults.get_relative_path(join("build", self.project_unique_name, relative_path))
@staticmethod
def unique_folder_name(path: str) -> str:
return basename(path) + "-" + encode(bytes(path, "utf-8")).hexdigest()[-5:]
+4 -5
View File
@@ -6,9 +6,8 @@ from os.path import abspath, basename, exists, isdir, isfile, join, relpath
from typing import Collection, Dict, List, Optional
from . import GLOBALS, PROPERTIES
from .config import Config
from .config import Config, FileConfig
from .language import get_language_directories
from .make_config import ToolchainConfig
from .native_setup import arch_to_abi, prepare_compiler_executable
from .shell import abort, debug, error, info, pretty_print, warn
from .utils import (RuntimeCodeError, copy_directory, copy_file,
@@ -46,12 +45,12 @@ def collect_stdincludes_directories(directories: Optional[Collection[str]]) -> L
warn(f"* Header {filename} should be inside any of stdincludes directory, otherwise it will be ignored.")
return stdincludes
def get_manifest(directory: str) -> ToolchainConfig:
return ToolchainConfig(join(directory, "manifest"))
def get_manifest(directory: str) -> FileConfig:
return FileConfig(join(directory, "manifest"))
def get_name_from_manifest(directory: str) -> Optional[str]:
try:
return get_manifest(directory).get_value("shared.name", basename(directory))
return get_manifest(directory).get_value("shared.name", lambda: basename(directory))
except:
return None
+9
View File
@@ -0,0 +1,9 @@
from os.path import basename
try:
from hashlib import blake2s as encode
except ImportError:
from hashlib import md5 as encode
def unique_folder_name(path: str) -> str:
return basename(path) + "-" + encode(bytes(path, "utf-8")).hexdigest()[-5:]
+2 -2
View File
@@ -423,9 +423,9 @@ def task_remove_project() -> int:
try:
location = GLOBALS.TOOLCHAIN_CONFIG.get_path(who)
GLOBALS.PROJECT_MANAGER.remove_project(folder=who)
from .make_config import MakeConfig
from .output_directory import unique_folder_name
from .package import cleanup_relative_directory
cleanup_relative_directory("build/" + MakeConfig.unique_folder_name(location))
cleanup_relative_directory("build/" + unique_folder_name(location))
except ValueError:
abort(f"Folder {who!r} not found!")