Skip to content

Commit

Permalink
feat(patch_generator): read CC /CXX from build_config.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Nov 6, 2023
1 parent 2378bd0 commit 123370f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
18 changes: 18 additions & 0 deletions discopop_library/PatchGenerator/PatchGeneratorArguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
35 changes: 33 additions & 2 deletions discopop_library/PatchGenerator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit 123370f

Please sign in to comment.