-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
50 lines (40 loc) · 1.41 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Compile all OpenSCAD files into a build directory and package it with docs.
(a.k.a.: "make is hard"
SPDX-FileCopyrightText: © 2024 Brian S. Stephan <[email protected]>
SPDX-License-Identifier: GPL-3.0-or-later
"""
import os
import os.path
import re
import subprocess
PROJECT_ROOT = os.path.abspath(os.getcwd())
BUILD_DIR = os.path.join(PROJECT_ROOT, 'build/')
SOURCE_DIR = os.path.join(PROJECT_ROOT, 'src/')
EXCLUDES = ['components.scad', 'parameters.scad']
# set up our environment to point openscad at the right stuff
os.environ['OPENSCADPATH'] = SOURCE_DIR
# track processes to wait on
processes = []
os.chdir(SOURCE_DIR)
for root, dirs, files in os.walk('.'):
print(f"{root} {dirs} {files}")
# make the current directory so that openscad can write stuff into it
try:
os.makedirs(os.path.join(BUILD_DIR, root))
except FileExistsError:
pass
input_dir = os.path.join(SOURCE_DIR, root)
output_dir = os.path.join(BUILD_DIR, root)
for file in files:
if not re.match(r'.*\.scad$', file):
continue
if file in EXCLUDES:
continue
stl_file = re.sub(r'\.scad$', '.stl', file)
input_ = os.path.join(input_dir, file)
output = os.path.join(output_dir, stl_file)
cmd = f'openscad -o {output} {input_}'
print(cmd)
processes.append(subprocess.Popen(cmd.split(' ')))
for process in processes:
process.wait()