Rendering Engine 0.2.17
Modular Graphics Rendering Engine | v0.2.17
Loading...
Searching...
No Matches
register_project.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# This file is part of the Rendering Engine project.
4# Author: Alexander Obzherin <alexanderobzherin@gmail.com>
5# Copyright (c) 2026 Alexander Obzherin
6# Distributed under the terms of the zlib License. See LICENSE.md for details.
7#
8# This script registers an external UserApplication with a Rendering Engine
9# environment.
10#
11# The registration is stored in the machine-local Local/ directory and is
12# therefore not committed to the Rendering Engine repository.
13#
14# Usage:
15# python3 register_project.py <ProjectPath>
16
17import os
18import sys
19
20
21SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
22ENGINE_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, "..", ".."))
23
24LOCAL_DIR = os.path.join(ENGINE_ROOT, "Local")
25REGISTRY_FILE = os.path.join(LOCAL_DIR, "registered_projects.cmake")
26
27
29 """
30 @brief Convert a path to an absolute CMake-friendly path.
31
32 @param path Path to normalize.
33
34 @return Absolute normalized path using forward slashes.
35 """
36 return os.path.abspath(path).replace("\\", "/")
37
38
40 """
41 @brief Read external UserApplication paths from the local registry.
42
43 @return List of registered project paths.
44 """
45 if not os.path.exists(REGISTRY_FILE):
46 return []
47
48 projects = []
49
50 with open(REGISTRY_FILE, "r") as registry_file:
51 for line in registry_file:
52 line = line.strip()
53
54 if line.startswith('"') and line.endswith('"'):
55 projects.append(line[1:-1])
56
57 return projects
58
59
61 """
62 @brief Write external UserApplication paths to the local registry.
63
64 @param projects List of registered project paths.
65 """
66 os.makedirs(LOCAL_DIR, exist_ok=True)
67
68 with open(REGISTRY_FILE, "w") as registry_file:
69 registry_file.write(
70 "# This file is generated by register_project.py.\n"
71 "# Machine-local Rendering Engine application registrations.\n"
72 "\n"
73 "set(RE_EXTERNAL_APPLICATIONS\n"
74 )
75
76 for project in projects:
77 registry_file.write(f' "{project}"\n')
78
79 registry_file.write(")\n")
80
81
83 """
84 @brief Write the machine-local Rendering Engine configuration
85 for a UserApplication.
86
87 @param project_path Path to the UserApplication.
88 """
89 local_dir = os.path.join(project_path, "Local")
90 config_file = os.path.join(local_dir, "rendering_engine.cmake")
91
92 os.makedirs(local_dir, exist_ok=True)
93
94 engine_root = normalize_path(ENGINE_ROOT)
95
96 with open(config_file, "w") as config:
97 config.write(
98 "# This file is generated by register_project.py.\n"
99 "# Machine-local Rendering Engine configuration.\n"
100 "\n"
101 "set(RENDERING_ENGINE_ROOT\n"
102 f' "{engine_root}"\n'
103 ")\n"
104 )
105
106 return config_file
107
108
109def register_project(project_path):
110 """
111 @brief Register an external UserApplication with this Rendering Engine.
112
113 @param project_path Path to the UserApplication.
114 """
115 project_path = normalize_path(project_path)
116
117 if not os.path.isdir(project_path):
118 print(f"Error: Project directory does not exist: '{project_path}'.")
119 return False
120
121 cmake_file = os.path.join(project_path, "CMakeLists.txt")
122
123 if not os.path.isfile(cmake_file):
124 print(
125 f"Error: Project '{project_path}' does not contain "
126 "a CMakeLists.txt file."
127 )
128 return False
129
130 projects = read_registered_projects()
131
132 if project_path not in projects:
133 projects.append(project_path)
135 print(f"Registered project: {project_path}")
136 else:
137 print(f"Project is already registered: {project_path}")
138
139 project_config = write_project_engine_config(project_path)
140
141 print(f"Project configuration: {project_config}")
142 print(f"Registration file: {REGISTRY_FILE}")
143
144 return True
145
146
147if __name__ == "__main__":
148 if len(sys.argv) != 2:
149 print("Usage: register_project.py <ProjectPath>")
150 sys.exit(1)
151
152 if not register_project(sys.argv[1]):
153 sys.exit(1)
write_registered_projects(projects)
write_project_engine_config(project_path)