feat: generate shuttle index JSON

includes information about all projects:
- repo
- commit
- mux index
- mux position (X/Y)
This commit is contained in:
Uri Shaked
2023-07-21 09:43:33 +03:00
parent d41972b4bb
commit f558f4d321
2 changed files with 21 additions and 3 deletions
+20 -3
View File
@@ -4,6 +4,7 @@ import yaml
import json import json
import glob import glob
import shutil import shutil
import git
def copy_print(src: str, dest: str): def copy_print(src: str, dest: str):
logging.info(f" -> {dest}") logging.info(f" -> {dest}")
@@ -14,6 +15,7 @@ def copy_print_glob(pattern: str, dest_dir: str):
for file in glob.glob(pattern): for file in glob.glob(pattern):
copy_print(file, os.path.join(dest_dir, os.path.basename(file))) copy_print(file, os.path.join(dest_dir, os.path.basename(file)))
class CaravelConfig(): class CaravelConfig():
def __init__(self, config, projects, modules_yaml_name: str): def __init__(self, config, projects, modules_yaml_name: str):
@@ -54,7 +56,13 @@ class CaravelConfig():
for module in placed_modules['modules']: for module in placed_modules['modules']:
mux_address = (module['y'] << 5) + module['x'] mux_address = (module['y'] << 5) + module['x']
module_name = 'tt_um_' + module['name'] module_name = 'tt_um_' + module['name']
mux_index[mux_address] = module_name mux_index[mux_address] = {
"macro": "module_name",
"x": module['x'],
"y": module['y'],
"repo": project.git_url,
"commit": project.commit_id,
},
mux_index_reverse[module_name] = mux_address mux_index_reverse[module_name] = mux_address
for project in self.projects: for project in self.projects:
@@ -63,8 +71,17 @@ class CaravelConfig():
exit(1) exit(1)
project.mux_address = mux_index_reverse[project.top_module] project.mux_address = mux_index_reverse[project.top_module]
with open('mux_index.json', 'w') as mux_index_file: repo = git.Repo(".")
json.dump(mux_index, mux_index_file)
shuttle_index_data = {
"shuttle": self.config["name"],
"repo": list(repo.remotes[0].urls)[0],
"commit": repo.commit().hexsha,
"mux": mux_index,
}
with open('shuttle_index.json', 'w') as shuttle_index_file:
json.dump(shuttle_index_data, shuttle_index_file, indent=2)
def list(self): def list(self):
for project in self.projects: for project in self.projects:
+1
View File
@@ -42,6 +42,7 @@ class Projects():
commit_id_data = json.load(open(commit_id_file)) commit_id_data = json.load(open(commit_id_file))
project = Project(index, commit_id_data['repo'], project_dir, args) project = Project(index, commit_id_data['repo'], project_dir, args)
project.commit_id = commit_id_data['commit']
# projects should now be installed, so load all the data from the yaml files # projects should now be installed, so load all the data from the yaml files
# fill projects will load from the fill project's directory # fill projects will load from the fill project's directory