summaryrefslogtreecommitdiff
path: root/support/openscad
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2014-12-12 18:07:28 +0100
committerMichael Schwarz <michi.schwarz@gmail.com>2014-12-12 18:07:28 +0100
commit88fef813b0d1013e90c9aa4156cbc836481377a3 (patch)
tree128b26f48b4a5abfbb803d85ecae48237cb0a238 /support/openscad
parentc02392b65243b3842e273cec36468e21ee376787 (diff)
parentb69003800917a93c5c2b240ede6f83b80f1095cc (diff)
downloadpogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.gz
pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.bz2
pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.zip
Merge branch 'master' into no-examples
Diffstat (limited to 'support/openscad')
-rw-r--r--support/openscad/__init__.py0
-rw-r--r--support/openscad/__main__.py37
2 files changed, 37 insertions, 0 deletions
diff --git a/support/openscad/__init__.py b/support/openscad/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/support/openscad/__init__.py
diff --git a/support/openscad/__main__.py b/support/openscad/__main__.py
new file mode 100644
index 0000000..08b2ab6
--- /dev/null
+++ b/support/openscad/__main__.py
@@ -0,0 +1,37 @@
+import os, sys
+from lib import util
+
+
+def _openscad(in_path, out_path, deps_path):
+ util.command([os.environ['OPENSCAD'], '-o', out_path, '-d', deps_path, in_path])
+
+
+def _write_dependencies(path, target, dependencies):
+ util.write_file(path, '{}: {}\n'.format(target, ' '.join(dependencies)).encode())
+
+
+def main(in_path, out_path, deps_path):
+ cwd = os.getcwd()
+
+ def relpath(path):
+ return os.path.relpath(path, cwd)
+
+ with util.TemporaryDirectory() as temp_dir:
+ temp_deps_path = os.path.join(temp_dir, 'deps')
+ temp_mk_path = os.path.join(temp_dir, 'mk')
+ temp_files_path = os.path.join(temp_dir, 'files')
+
+ _openscad(in_path, out_path, temp_deps_path)
+
+ mk_content = '%:; echo "$@" >> {}'.format(util.bash_escape_string(temp_files_path))
+
+ util.write_file(temp_mk_path, mk_content.encode())
+ util.command(['make', '-s', '-B', '-f', temp_mk_path, '-f', temp_deps_path])
+
+ deps = set(map(relpath, util.read_file(temp_files_path).decode().splitlines()))
+ ignored_files = set(map(relpath, [temp_deps_path, temp_mk_path, in_path, out_path]))
+
+ _write_dependencies(deps_path, relpath(out_path), deps - ignored_files)
+
+
+main(*sys.argv[1:])