Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
package_sdk Namespace Reference

Functions

 read_version ()
 detect_platform ()
 copy_tree (src, dst, ignore=None)
 ensure_dir (path)
 write_manifest (path, version, platform)
 patch_build_script_for_sdk (build_script_path)
 main ()

Variables

 REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
 BUILD_ROOT = os.path.join(REPO_ROOT, "Build")
 INSTALL_ROOT = os.path.join(BUILD_ROOT, "Installed")
 PACKAGE_ROOT = os.path.join(BUILD_ROOT, "Packages")
 SDK_TEMP_ROOT = os.path.join(BUILD_ROOT, "SDK")
 LOGS_ROOT = os.path.join(BUILD_ROOT, "Logs")
 VERSION_HEADER
list DOC_FILES

Function Documentation

◆ copy_tree()

package_sdk.copy_tree ( src,
dst,
ignore = None )

Definition at line 100 of file package_sdk.py.

100def copy_tree(src, dst, ignore=None):
101 if not os.path.exists(src):
102 logging.warning(f"Source path does not exist, skipping: {src}")
103 return
104 if os.path.exists(dst):
105 shutil.rmtree(dst)
106 shutil.copytree(src, dst, ignore=ignore)
107 logging.info(f"Copied tree: {src} -> {dst}")
108
109

◆ detect_platform()

package_sdk.detect_platform ( )
Return a human-readable platform string.

Definition at line 88 of file package_sdk.py.

88def detect_platform():
89 """Return a human-readable platform string."""
90 p = sys.platform
91 if p.startswith("win"):
92 return "Windows"
93 elif p.startswith("linux"):
94 return "Linux"
95 elif p.startswith("freebsd"):
96 return "FreeBSD"
97 return "Unknown"
98
99

◆ ensure_dir()

package_sdk.ensure_dir ( path)

Definition at line 110 of file package_sdk.py.

110def ensure_dir(path):
111 os.makedirs(path, exist_ok=True)
112 return path
113
114

◆ main()

package_sdk.main ( )

Definition at line 157 of file package_sdk.py.

157def main():
158 # Init logging
159 ensure_dir(LOGS_ROOT)
160 logging.basicConfig(
161 filename=os.path.join(LOGS_ROOT, "packaging.log"),
162 level=logging.INFO,
163 format="%(asctime)s %(levelname)s: %(message)s",
164 )
165 logging.info("=== SDK Packaging Started ===")
166
167 try:
168 version = read_version()
169 platform = detect_platform()
170
171 sdk_name = f"RenderingEngine-v{version}-SDK-{platform}"
172 sdk_root = os.path.join(SDK_TEMP_ROOT, sdk_name)
173
174 # Clean previous SDK for this version/platform
175 if os.path.exists(sdk_root):
176 shutil.rmtree(sdk_root)
177 ensure_dir(sdk_root)
178
179 logging.info(f"Version : {version}")
180 logging.info(f"Platform: {platform}")
181 logging.info(f"SDK root: {sdk_root}")
182
183 # Paths inside SDK
184 sdk_rendering_engine_root = ensure_dir(os.path.join(sdk_root, "RenderingEngine"))
185 sdk_render_lib_root = ensure_dir(os.path.join(sdk_rendering_engine_root, "RenderingLibrary"))
186 sdk_material_compiler_root = ensure_dir(os.path.join(sdk_rendering_engine_root, "MaterialCompiler"))
187 sdk_scripts_root = ensure_dir(os.path.join(sdk_rendering_engine_root, "Scripts"))
188
189 # --------------------------------------------------------------
190 # 1. RenderingLibrary: headers + libs + cmake files
191 # --------------------------------------------------------------
192 installed_engine_root = os.path.join(INSTALL_ROOT, "RenderingEngine")
193
194 # RenderingLibrary
195 installed_render_lib = os.path.join(installed_engine_root, "RenderingLibrary")
196
197 copy_tree(
198 os.path.join(installed_render_lib, "Include"),
199 os.path.join(sdk_render_lib_root, "Include"),
200 )
201
202 copy_tree(
203 os.path.join(installed_render_lib, "Library"),
204 os.path.join(sdk_render_lib_root, "Library"),
205 )
206
207 # --------------------------------------------------------------
208 # 2. MaterialCompiler (tool + its local DLL)
209 # --------------------------------------------------------------
210 installed_mc_root = os.path.join(installed_engine_root, "MaterialCompiler")
211 copy_tree(installed_mc_root, sdk_material_compiler_root)
212
213 # --------------------------------------------------------------
214 # 3. External vendored headers (glm, boost, json, vulkan,...)
215 # --------------------------------------------------------------
216 installed_external_root = os.path.join(installed_engine_root, "External")
217 copy_tree(installed_external_root, os.path.join(sdk_rendering_engine_root, "External"))
218
219 # --------------------------------------------------------------
220 # 4. Scripts (Templates)
221 # --------------------------------------------------------------
222 copy_tree(
223 os.path.join(REPO_ROOT, "RenderingEngine", "Scripts", "Templates"),
224 os.path.join(sdk_scripts_root, "Templates"),
225 )
226
227 # --------------------------------------------------------------
228 # 4. Modify CMakeLists.txt.in inside SDK to set RE_DEV_MODE OFF
229 # --------------------------------------------------------------
230 cmake_template_path = os.path.join(sdk_scripts_root, "Templates", "CMakeLists.txt.in")
231
232 # Always copy the Templates directory
233 copy_tree(
234 os.path.join(REPO_ROOT, "RenderingEngine", "Scripts", "Templates"),
235 os.path.join(sdk_scripts_root, "Templates"),
236 )
237
238 # Always copy create_project.py
239 create_project_src = os.path.join(REPO_ROOT, "RenderingEngine", "Scripts", "create_project.py")
240 if os.path.isfile(create_project_src):
241 shutil.copy2(create_project_src, os.path.join(sdk_scripts_root, "create_project.py"))
242 logging.info("Copied script: create_project.py")
243 else:
244 logging.warning(f"create_project.py not found at {create_project_src}")
245
246 # Modify RE_DEV_MODE default in CMakeLists template
247 cmake_template_path = os.path.join(sdk_scripts_root, "Templates", "CMakeLists.txt.in")
248
249 with open(cmake_template_path, "r", encoding="utf-8") as f:
250 text = f.read()
251
252 text = re.sub(
253 r'option\‍(RE_DEV_MODE\s+"[^"]+"\s+ON\‍)',
254 'option(RE_DEV_MODE "Build using RenderingEngine directly from source tree (Windows only)" OFF)',
255 text
256 )
257
258 with open(cmake_template_path, "w", encoding="utf-8") as f:
259 f.write(text)
260
261 logging.info("Updated CMakeLists.txt.in to set RE_DEV_MODE=OFF")
262
263
264 # --------------------------------------------------------------
265 # 5. Documentation
266 # --------------------------------------------------------------
267 doc_dst = ensure_dir(os.path.join(sdk_root, "Doc"))
268 for doc in DOC_FILES:
269 src = os.path.join(REPO_ROOT, doc)
270 if os.path.isfile(src):
271 shutil.copy2(src, doc_dst)
272 logging.info(f"Copied documentation: {src}")
273 else:
274 logging.warning(f"Documentation file missing, skipped: {src}")
275
276 # --------------------------------------------------------------
277 # 6. Content Examples (copied directly from root-level folder)
278 # --------------------------------------------------------------
279 examples_src_root = os.path.join(REPO_ROOT, "ContentExamples")
280 examples_dst_root = ensure_dir(os.path.join(sdk_root, "ContentExamples"))
281
282 def ignore_example(dirpath, names):
283 ignore = []
284 for n in names:
285 if n in ("Build", "Intermediate", ".vs", ".vscode", "x64"):
286 ignore.append(n)
287 elif n.endswith(".user") or n.endswith(".vcxproj") or n.endswith(".vcxproj.filters"):
288 ignore.append(n)
289 return ignore
290
291 if os.path.isdir(examples_src_root):
292 copy_tree(examples_src_root, examples_dst_root, ignore=ignore_example)
293 logging.info("Copied ContentExamples folder.")
294
295 # Patch build_project.sh in each example
296 for proj in os.listdir(examples_dst_root):
297 proj_path = os.path.join(examples_dst_root, proj)
298 if os.path.isdir(proj_path):
299 build_script = os.path.join(proj_path, "build_project.sh")
300 patch_build_script_for_sdk(build_script)
301 else:
302 logging.warning("No ContentExamples folder found.")
303
304 # --------------------------------------------------------------
305 # 7. UserApplications (empty placeholder)
306 # --------------------------------------------------------------
307 ensure_dir(os.path.join(sdk_root, "UserApplications"))
308
309 # --------------------------------------------------------------
310 # 7. Manifest
311 # --------------------------------------------------------------
312 write_manifest(os.path.join(sdk_root, "Manifest.txt"), version, platform)
313
314 # --------------------------------------------------------------
315 # 8. Create Archive
316 # --------------------------------------------------------------
317 ensure_dir(PACKAGE_ROOT)
318 archive_path = os.path.join(PACKAGE_ROOT, sdk_name)
319
320 # Clean old archive if exists
321 for ext in (".tar.gz", ".zip", ".tgz"):
322 old = archive_path + ext
323 if os.path.exists(old):
324 os.remove(old)
325
326 shutil.make_archive(archive_path, "gztar", root_dir=SDK_TEMP_ROOT)
327 logging.info(f"Archive created: {archive_path}.tar.gz")
328 logging.info("=== SDK Packaging Complete ===")
329
330 except Exception as e:
331 logging.error(f"SDK packaging failed: {e}", exc_info=True)
332 print(f"SDK packaging failed: {e}")
333
334
int main(int argc, char *argv[])

◆ patch_build_script_for_sdk()

package_sdk.patch_build_script_for_sdk ( build_script_path)
Force RE_DEV_MODE=OFF inside build_project.sh

Definition at line 131 of file package_sdk.py.

131def patch_build_script_for_sdk(build_script_path):
132 """Force RE_DEV_MODE=OFF inside build_project.sh"""
133 if not os.path.isfile(build_script_path):
134 return
135
136 with open(build_script_path, "r", encoding="utf-8") as f:
137 content = f.read()
138
139 # Patch the cmake configuration line:
140 # cmake -S "$PROJECT_SOURCE_DIR" -B "$PROJECT_BUILD_DIR" -DCMAKE_BUILD_TYPE=...
141 content = re.sub(
142 r'cmake\s+-S\s+"\$PROJECT_SOURCE_DIR"\s+-B\s+"\$PROJECT_BUILD_DIR"\s+-DCMAKE_BUILD_TYPE=\$BUILD_MODE',
143 r'cmake -S "$PROJECT_SOURCE_DIR" -B "$PROJECT_BUILD_DIR" -DCMAKE_BUILD_TYPE=$BUILD_MODE -DRE_DEV_MODE=OFF',
144 content
145 )
146
147 with open(build_script_path, "w", encoding="utf-8") as f:
148 f.write(content)
149
150 logging.info(f"Patched build_project.sh for SDK: {build_script_path}")
151
152# --------------------------------------------------------------------
153# Main Packaging Logic
154# --------------------------------------------------------------------
155
156

◆ read_version()

package_sdk.read_version ( )
Parse version.h and extract MAJOR.MINOR.PATCH as a string.

Definition at line 67 of file package_sdk.py.

67def read_version():
68 """Parse version.h and extract MAJOR.MINOR.PATCH as a string."""
69 if not os.path.isfile(VERSION_HEADER):
70 raise RuntimeError(f"version.h not found at: {VERSION_HEADER}")
71
72 with open(VERSION_HEADER, "r", encoding="utf-8") as f:
73 text = f.read()
74
75 major = re.search(r"#define\s+RENDERING_ENGINE_VERSION_MAJOR\s+(\d+)", text)
76 minor = re.search(r"#define\s+RENDERING_ENGINE_VERSION_MINOR\s+(\d+)", text)
77 patch = re.search(r"#define\s+RENDERING_ENGINE_VERSION_PATCH\s+(\d+)", text)
78
79 if not (major and minor and patch):
80 raise RuntimeError(
81 "version.h missing required version macros "
82 "(RENDERING_ENGINE_VERSION_MAJOR/MINOR/PATCH)."
83 )
84
85 return f"{major.group(1)}.{minor.group(1)}.{patch.group(1)}"
86
87

◆ write_manifest()

package_sdk.write_manifest ( path,
version,
platform )

Definition at line 115 of file package_sdk.py.

115def write_manifest(path, version, platform):
116 with open(path, "w", encoding="utf-8") as f:
117 f.write("Rendering Engine SDK Manifest\n")
118 f.write("=====================================\n\n")
119 f.write(f"Version : {version}\n")
120 f.write(f"Platform: {platform}\n")
121 f.write(f"Date : {datetime.datetime.now()}\n\n")
122 f.write("Layout:\n")
123 f.write("- RenderingEngine/RenderingLibrary : core engine library + headers + cmake files\n")
124 f.write("- RenderingEngine/MaterialCompiler : material compiler tool + local engine DLL\n")
125 f.write("- RenderingEngine/Scripts : project generation scripts + templates\n")
126 f.write("- ContentExamples/ : sample projects\n")
127 f.write("- UserApplications/ : place for user-created apps\n")
128 f.write("- Doc/ : documentation\n")
129 logging.info(f"Manifest written: {path}")
130

Variable Documentation

◆ BUILD_ROOT

package_sdk.BUILD_ROOT = os.path.join(REPO_ROOT, "Build")

Definition at line 40 of file package_sdk.py.

◆ DOC_FILES

list package_sdk.DOC_FILES
Initial value:
1= [
2 "README.md",
3 "Doc/app_config_guide.md",
4 "Doc/debugging_guide.md",
5 "Doc/developer_guide.md",
6 "Doc/docker_container.md",
7 "Doc/prepare_environment.md",
8 "Doc/project_creation_guide.md",
9 "Doc/project_packaging_guide.md",
10 "Doc/sdk_packaging_guide.md",
11]

Definition at line 50 of file package_sdk.py.

◆ INSTALL_ROOT

package_sdk.INSTALL_ROOT = os.path.join(BUILD_ROOT, "Installed")

Definition at line 41 of file package_sdk.py.

◆ LOGS_ROOT

package_sdk.LOGS_ROOT = os.path.join(BUILD_ROOT, "Logs")

Definition at line 44 of file package_sdk.py.

◆ PACKAGE_ROOT

package_sdk.PACKAGE_ROOT = os.path.join(BUILD_ROOT, "Packages")

Definition at line 42 of file package_sdk.py.

◆ REPO_ROOT

package_sdk.REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))

Definition at line 39 of file package_sdk.py.

◆ SDK_TEMP_ROOT

package_sdk.SDK_TEMP_ROOT = os.path.join(BUILD_ROOT, "SDK")

Definition at line 43 of file package_sdk.py.

◆ VERSION_HEADER

package_sdk.VERSION_HEADER
Initial value:
1= os.path.join(
2 BUILD_ROOT, "Intermediate", "Generated", "version.h"
3)

Definition at line 46 of file package_sdk.py.