From f3f79806629ce23b7be70aaaf12d4bfe93a6206a Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Wed, 8 Dec 2021 16:15:21 +0000 Subject: [PATCH] [WS] Inform about unexisting compilers and qemu git-svn-id: svn://kolibrios.org@9411 a494cfbc-eb01-0410-851d-a64ba20cac60 --- _tools/lib/logging.py | 17 +++++++++++++++++ _tools/lib/tupfile_parser.py | 28 ++++++++++++++++++++++++++++ _tools/workspace/build.py | 5 ++++- _tools/workspace/run.py | 4 +++- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/_tools/lib/logging.py b/_tools/lib/logging.py index 3576f2c158..b221457211 100644 --- a/_tools/lib/logging.py +++ b/_tools/lib/logging.py @@ -1,4 +1,21 @@ +import shutil + def log(s, end = "\n"): print(s, end = end, flush = True) +def require_tools(names): + assert(type(names) == list or type(names) == tuple) + for name in names: + assert(type(name) == str) + + not_found = [] + for name in names: + if shutil.which(name) is None: + not_found.append(name) + + if len(not_found) != 0: + log("Sorry, I can't find some tools:") + for name in not_found: + print(f"- {name}") + exit(1) diff --git a/_tools/lib/tupfile_parser.py b/_tools/lib/tupfile_parser.py index 0560ff306f..c960e01685 100644 --- a/_tools/lib/tupfile_parser.py +++ b/_tools/lib/tupfile_parser.py @@ -62,6 +62,20 @@ def parse_rule_output(src, ptr): # Now we can read the string return get_strnig(src, ptr) +def parse_required_compiler(src, ptr): + # Get straignt to the first argument + ptr += len("tup.getconfig") + # Get to parenthese + ptr = get_to(src, ptr, "(") + # Get to start of the requirement string + ptr = get_to(src, ptr, "\"") + # Read the requirement string (like NO_FASM) + requirement_string = get_strnig(src, ptr) + if requirement_string.startswith("NO_"): + return requirement_string[len("NO_"):].lower().replace("_", "-") + else: + return None + def parse_tupfile_outputs(file_name): outputs = [] with open(file_name) as f: @@ -72,3 +86,17 @@ def parse_tupfile_outputs(file_name): # Find the next tup.rule call rule_begin_index = tupfile.find("tup.rule(", rule_begin_index + len("tup.rule(")) return outputs + +def parse_required_compilers(file_name): + compilers = [] + with open(file_name) as f: + tupfile = f.read() + rule_begin_index = tupfile.find("tup.getconfig(") + while (rule_begin_index != -1): + required_compiler = parse_required_compiler(tupfile, rule_begin_index) + if required_compiler is not None: + compilers.append(required_compiler) + # Find the next tup.getconfig call + rule_begin_index = tupfile.find("tup.getconfig(", rule_begin_index + len("tup.getconfig")) + return compilers + diff --git a/_tools/workspace/build.py b/_tools/workspace/build.py index d3d9b86faf..21eb87c805 100644 --- a/_tools/workspace/build.py +++ b/_tools/workspace/build.py @@ -5,7 +5,8 @@ path_to_tools_workspace = os.path.dirname(os.path.abspath(__file__)) path_to_tools = os.path.dirname(path_to_tools_workspace) sys.path.append(path_to_tools) -from lib.tupfile_parser import parse_tupfile_outputs +from lib.tupfile_parser import parse_required_compilers, parse_tupfile_outputs +from lib.logging import require_tools def get_executable_file(output_file_list): for name in output_file_list: @@ -14,6 +15,8 @@ def get_executable_file(output_file_list): return name def build(): + required_compilers = parse_required_compilers("Tupfile.lua") + require_tools(required_compilers) os.system("tup") output_file_list = parse_tupfile_outputs("Tupfile.lua") return get_executable_file(output_file_list) diff --git a/_tools/workspace/run.py b/_tools/workspace/run.py index 31f38ea883..1c0ab24179 100644 --- a/_tools/workspace/run.py +++ b/_tools/workspace/run.py @@ -14,11 +14,13 @@ from workspace.build import build from lib.builds import builds_get, builds_get_contents from lib.makeflop import Floppy from lib.platform import is_win32, path -from lib.logging import log +from lib.logging import log, require_tools from lib.constants import tools_cache_kolibri_img # TODO: Move into _tools/lib def run_qemu(start_dir = "workspace"): + require_tools(("qemu-system-i386",)) + qemu_command = f"qemu-system-i386" flags = "" flags += "-L . " # IDK why it does not work without this