From 123370f5e0045331f58406b8b1320d69594ec989 Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Mon, 6 Nov 2023 09:58:15 +0100 Subject: [PATCH] feat(patch_generator): read CC /CXX from build_config.txt --- .../PatchGenerator/PatchGeneratorArguments.py | 18 ++++++++++ discopop_library/PatchGenerator/__main__.py | 35 +++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/discopop_library/PatchGenerator/PatchGeneratorArguments.py b/discopop_library/PatchGenerator/PatchGeneratorArguments.py index 6887aeb05..8f7eac8e3 100644 --- a/discopop_library/PatchGenerator/PatchGeneratorArguments.py +++ b/discopop_library/PatchGenerator/PatchGeneratorArguments.py @@ -5,6 +5,7 @@ # This software may be modified and distributed under the terms of # the 3-Clause BSD License. See the LICENSE file in the package base # directory for details. +import os.path from dataclasses import dataclass @@ -13,10 +14,27 @@ class PatchGeneratorArguments(object): """Container Class for the arguments passed to the discopop_patch_generator""" verbose: bool + discopop_build_path: str + CC: str + CXX: str def __post_init__(self): self.__validate() def __validate(self): """Validate the arguments passed to the discopop_explorer, e.g check if given files exist""" + if self.verbose: + print("Configuration:") + print("\tDP BUILD PATH: ", self.discopop_build_path) + print("\tCC: ", self.CC) + print("\tCXX: ", self.CXX) + # check if build directory exists + if not os.path.exists(self.discopop_build_path): + raise FileNotFoundError(self.discopop_build_path) + # check if CC and CXX exist + if not os.path.exists(self.CC): + raise FileNotFoundError(self.CC) + if not os.path.exists(self.CXX): + raise FileNotFoundError(self.CXX) + pass diff --git a/discopop_library/PatchGenerator/__main__.py b/discopop_library/PatchGenerator/__main__.py index 8b171928f..b3417aedf 100644 --- a/discopop_library/PatchGenerator/__main__.py +++ b/discopop_library/PatchGenerator/__main__.py @@ -5,8 +5,9 @@ # This software may be modified and distributed under the terms of # the 3-Clause BSD License. See the LICENSE file in the package base # directory for details. - +import os.path from argparse import ArgumentParser +from pathlib import Path from discopop_library.PatchGenerator.PatchGeneratorArguments import PatchGeneratorArguments from discopop_library.PatchGenerator.patch_generator import run @@ -24,12 +25,42 @@ def parse_args() -> PatchGeneratorArguments: # fmt: off parser.add_argument("--verbose", action="store_true", help="Enable verbose output.") + parser.add_argument( + "--dp-build-path", type=str, required=True, + help="Path to DiscoPoP build folder" + ) # EXPERIMENTAL FLAGS: # fmt: on arguments = parser.parse_args() - return PatchGeneratorArguments(verbose=arguments.verbose) + # determine CC and CXX + with open(os.path.join(arguments.dp_build_path, "build_config.txt"), "r") as f: + for line in f.readlines(): + if line.startswith("LLVM_BIN_DIR="): + line = line.replace("\n", "") + llvm_bin_dir = line[len("LLVM_BIN_DIR=") :] + # determine CC + if os.path.exists(os.path.join(llvm_bin_dir, "clang")): + arguments.cc = os.path.join(llvm_bin_dir, "clang") + elif os.path.exists(os.path.join(llvm_bin_dir, "clang-11")): + arguments.cc = os.path.join(llvm_bin_dir, "clang-11") + else: + raise ValueError("Could not determine CC from discopop build path: ", arguments.dp_build_path) + + # determine CXX + if os.path.exists(os.path.join(llvm_bin_dir, "clang++")): + arguments.cxx = os.path.join(llvm_bin_dir, "clang++") + elif os.path.exists(os.path.join(llvm_bin_dir, "clang++-11")): + arguments.cxx = os.path.join(llvm_bin_dir, "clang++-11") + else: + raise ValueError("Could not determine CXX from discopop build path: ", arguments.dp_build_path) + + break + + return PatchGeneratorArguments( + verbose=arguments.verbose, discopop_build_path=arguments.dp_build_path, CC=arguments.cc, CXX=arguments.cxx + ) def main():