Skip to content

Commit 13065af

Browse files
committed
Fix path issues (dirs no created automatically etc.)
1 parent dc5fc10 commit 13065af

File tree

8 files changed

+62
-44
lines changed

8 files changed

+62
-44
lines changed

.github/workflows/auto-sync.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
3131
- name: Build llvm-tblgen
3232
run: |
33-
git clone https://github.com/capstone-engine/llvm-capstone.git
34-
cd llvm-capstone
33+
git clone https://github.com/capstone-engine/llvm-capstone.git vendor/llvm_root
34+
cd vendor/llvm_root
3535
mkdir build
3636
cd build
3737
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
3838
cmake --build . --target llvm-tblgen --config Debug
39-
cd ../../
39+
cd ../../../
4040
4141
- name: Test generationof inc files
4242
run: |

suite/auto-sync/src/autosync/PathVarHandler.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def __call__(cls, *args, **kwargs):
1616

1717

1818
class PathVarHandler(metaclass=Singleton):
19-
paths = {}
2019

2120
def __init__(self) -> None:
2221
try:
@@ -30,6 +29,7 @@ def __init__(self) -> None:
3029
exit(1)
3130
repo_root = res.stdout.decode("utf8").strip("\n")
3231
# The main directories
32+
self.paths: dict[str:Path] = dict()
3333
self.paths["{CS_ROOT}"] = Path(repo_root)
3434
self.paths["{AUTO_SYNC_ROOT}"] = Path(repo_root).joinpath("suite/auto-sync/")
3535
self.paths["{AUTO_SYNC_SRC}"] = self.paths["{AUTO_SYNC_ROOT}"].joinpath(
@@ -41,20 +41,27 @@ def __init__(self) -> None:
4141
with open(path_config_file) as f:
4242
vars = json.load(f)
4343

44+
paths = vars["paths"]
45+
create_during_runtime = vars["create_during_runtime"]
46+
4447
missing = list()
45-
for p_name, path in vars.items():
48+
for p_name, path in paths.items():
4649
resolved = path
4750
for var_id in re.findall(r"\{.+}", resolved):
4851
if var_id not in self.paths:
4952
log.fatal(
5053
f"{var_id} hasn't been added to the PathVarsHandler, yet. The var must be defined in a previous entry."
5154
)
5255
exit(1)
53-
resolved = re.sub(var_id, str(self.paths[var_id]), resolved)
56+
resolved: str = re.sub(var_id, str(self.paths[var_id]), resolved)
5457
log.debug(f"Set {p_name} = {resolved}")
55-
if not Path(resolved).exists():
58+
if not Path(resolved).exists() and (
59+
p_name not in create_during_runtime
60+
):
5661
missing.append(resolved)
57-
self.paths[p_name] = resolved
62+
elif var_id in create_during_runtime:
63+
self.create_path(var_id, resolved)
64+
self.paths[p_name] = Path(resolved)
5865
if len(missing) > 0:
5966
log.fatal(f"Some paths from config file are missing!")
6067
for m in missing:
@@ -69,5 +76,25 @@ def get_path(self, name: str) -> Path:
6976
def complete_path(self, path_str: str) -> Path:
7077
resolved = path_str
7178
for p_name in re.findall(r"\{.+}", path_str):
72-
resolved = re.sub(p_name, self.get_path(p_name), resolved)
79+
resolved = re.sub(p_name, str(self.get_path(p_name)), resolved)
7380
return Path(resolved)
81+
82+
@staticmethod
83+
def create_path(var_id: str, path: str):
84+
pp = Path(path)
85+
if pp.exists():
86+
return
87+
88+
postfix = var_id.strip("}").split("_")[-1]
89+
if postfix == "FILE":
90+
if not pp.parent.exists():
91+
pp.parent.mkdir(parents=True)
92+
pp.touch()
93+
elif postfix == "DIR":
94+
pp.mkdir(parents=True)
95+
else:
96+
from autosync.Helper import fail_exit
97+
98+
fail_exit(
99+
f"The var_id: {var_id} must end in _FILE or _DIR. It ends in '{postfix}'"
100+
)

suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def __init__(self, configure: Configurator):
181181
self.src_paths: [Path] = [
182182
get_path(sp["in"]) for sp in self.conf["files_to_translate"]
183183
]
184-
t_out_dir: Path = get_path(self.conf_general["translation_out_dir"])
184+
t_out_dir: Path = get_path("{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}")
185185
self.out_paths: [Path] = [
186186
t_out_dir.joinpath(sp["out"]) for sp in self.conf["files_to_translate"]
187187
]

suite/auto-sync/src/autosync/cpptranslator/Differ.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self, configurator: Configurator, no_auto_apply: bool):
176176
self.parser = self.configurator.get_parser()
177177
self.differ = dl.Differ()
178178

179-
t_out_dir: Path = get_path(self.conf_general["translation_out_dir"])
179+
t_out_dir: Path = get_path("{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}")
180180
self.translated_files = [
181181
t_out_dir.joinpath(sp["out"]) for sp in self.conf_arch["files_to_translate"]
182182
]
@@ -191,9 +191,7 @@ def __init__(self, configurator: Configurator, no_auto_apply: bool):
191191
self.load_persistence_file()
192192

193193
def load_persistence_file(self) -> None:
194-
self.persistence_filepath = get_path(
195-
self.conf_general["patch_persistence_file"]
196-
)
194+
self.persistence_filepath = get_path("{CPP_TRANSLATOR_PATH_PERSISTENCE_FILE}")
197195
if not self.persistence_filepath.exists():
198196
self.saved_patches = dict()
199197
return
@@ -224,7 +222,7 @@ def copy_files(self) -> None:
224222
Copy translated files to diff directory for editing.
225223
"""
226224
log.info("Copy files for editing")
227-
diff_dir: Path = get_path(self.conf_general["diff_out_dir"])
225+
diff_dir: Path = get_path("{CPP_TRANSLATOR_DIFF_OUT_DIR}")
228226
for f in self.translated_files:
229227
dest = diff_dir.joinpath(f.name)
230228
copy2(f, dest)

suite/auto-sync/src/autosync/cpptranslator/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ The configuration for each architecture is set in `arch_config.json`.
1313
The config values have the following meaning:
1414

1515
- `General`: Settings valid for all architectures.
16-
- `patch_persistent_file`: Path to the file which saves the selections from the `Differ`.
17-
- `translation_out_dir`: Path to the directory where the `CppTranslator` stores its files.
18-
- `diff_out_dir`: Path to the directory where the `Differ` stores its files.
1916
- `diff_color_new`: Color in the `Differ` for translated content.
2017
- `diff_color_old`: Color in the `Differ` for old/current Capstone content.
2118
- `diff_color_saved`: Color in the `Differ` for saved content.

suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"General": {
3-
"patch_persistence_file": "",
4-
"translation_out_dir": "",
5-
"diff_out_dir": "",
63
"diff_color_new": "green",
74
"diff_color_old": "light_blue",
85
"diff_color_saved": "yellow",

suite/auto-sync/src/autosync/cpptranslator/arch_config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"General": {
3-
"patch_persistence_file": "{CPP_TRANSLATOR_DIR}/saved_patches.json",
4-
"translation_out_dir": "{BUILD_DIR}/translate_out/",
5-
"diff_out_dir": "{BUILD_DIR}/diff_out/",
63
"diff_color_new": "green",
74
"diff_color_old": "light_blue",
85
"diff_color_saved": "yellow",
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
{
2-
"{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root//",
3-
"{LLVM_TARGET_DIR}": "{LLVM_ROOT}/llvm/lib/Target/",
4-
"{LLVM_TBLGEN_BIN}": "{LLVM_ROOT}/build/bin/llvm-tblgen",
5-
"{LLVM_INCLUDE_DIR}": "{LLVM_ROOT}/llvm/include",
6-
7-
"{VENDOR_DIR}": "{AUTO_SYNC_ROOT}/vendor/",
8-
9-
"{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/",
10-
"{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json",
11-
"{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/",
12-
"{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json",
13-
"{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/",
14-
15-
"{CS_INCLUDE_DIR}": "{CS_ROOT}/include/capstone/",
16-
"{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/",
17-
"{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format",
18-
19-
"{BUILD_DIR}": "{AUTO_SYNC_ROOT}/build/",
20-
"{C_INC_OUT_DIR}": "{BUILD_DIR}/llvm_c_inc/",
21-
"{CPP_INC_OUT_DIR}": "{BUILD_DIR}/llvm_cpp_inc/"
2+
"paths": {
3+
"{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root//",
4+
"{LLVM_TARGET_DIR}": "{LLVM_ROOT}/llvm/lib/Target/",
5+
"{LLVM_TBLGEN_BIN}": "{LLVM_ROOT}/build/bin/llvm-tblgen",
6+
"{LLVM_INCLUDE_DIR}": "{LLVM_ROOT}/llvm/include/",
7+
"{VENDOR_DIR}": "{AUTO_SYNC_ROOT}/vendor/",
8+
"{BUILD_DIR}": "{AUTO_SYNC_ROOT}/build/",
9+
"{C_INC_OUT_DIR}": "{BUILD_DIR}/llvm_c_inc/",
10+
"{CPP_INC_OUT_DIR}": "{BUILD_DIR}/llvm_cpp_inc/",
11+
"{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/",
12+
"{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json",
13+
"{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/",
14+
"{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json",
15+
"{CPP_TRANSLATOR_PATH_PERSISTENCE_FILE}": "{CPP_TRANSLATOR_DIR}/saved_patches.json",
16+
"{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}": "{BUILD_DIR}/translate_out/",
17+
"{CPP_TRANSLATOR_DIFF_OUT_DIR}": "{BUILD_DIR}/diff_out/",
18+
"{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/",
19+
"{CS_INCLUDE_DIR}": "{CS_ROOT}/include/capstone/",
20+
"{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/",
21+
"{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format"
22+
},
23+
"create_during_runtime": ["{BUILD_DIR}", "{C_INC_OUT_DIR}", "{CPP_INC_OUT_DIR}", "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}", "{CPP_TRANSLATOR_DIFF_OUT_DIR}"]
2224
}
2325

0 commit comments

Comments
 (0)