From de6f0d04958b0687393a5b3d7dc9679ba56f8f42 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Mon, 21 Aug 2023 19:04:39 -0400 Subject: [PATCH] Compile all parts in project, optionally using GNU parallel if available. --- app/data/cfg.json | 2 +- app/package-lock.json | 2 +- app/package.json | 2 +- data/cfg.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- processing/mcopy/cfg.json | 2 +- scripts/common.sh | 17 +++++++++++++++++ scripts/openscadPart.sh | 8 ++++++++ scripts/scad.sh | 32 ++++++++++++-------------------- 10 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 scripts/common.sh create mode 100644 scripts/openscadPart.sh diff --git a/app/data/cfg.json b/app/data/cfg.json index e10d960..db147ac 100644 --- a/app/data/cfg.json +++ b/app/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.3", + "version": "1.8.4", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/app/package-lock.json b/app/package-lock.json index b3edb63..795fae0 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.3", + "version": "1.8.4", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/app/package.json b/app/package.json index 0928427..710b10e 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.3", + "version": "1.8.4", "description": "GUI for the mcopy small gauge film optical printer platform", "main": "main.js", "scripts": { diff --git a/data/cfg.json b/data/cfg.json index e10d960..db147ac 100644 --- a/data/cfg.json +++ b/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.3", + "version": "1.8.4", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/package-lock.json b/package-lock.json index 551f0ff..583e111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcopy", - "version": "1.8.3", + "version": "1.8.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mcopy", - "version": "1.8.3", + "version": "1.8.4", "license": "MIT", "dependencies": { "arduino": "file:app/lib/arduino", diff --git a/package.json b/package.json index 6115404..5d50c5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcopy", - "version": "1.8.3", + "version": "1.8.4", "description": "Small gauge film optical printer platform", "main": "build.js", "directories": { diff --git a/processing/mcopy/cfg.json b/processing/mcopy/cfg.json index e10d960..db147ac 100644 --- a/processing/mcopy/cfg.json +++ b/processing/mcopy/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.3", + "version": "1.8.4", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..b4b3256 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +listParts () { + cat "${1}" | grep 'PART ==' | grep -v 'debug' | awk -F'"' '{print $2}' +} + +allParts () { + PARTS=($(listParts "scad/${1}.scad")) + for part in "${PARTS[@]}"; do + bash ./scripts/openscadPart.sh "${1}.scad" "${part}" "${1}_${part}.stl" + done +} + +parallelParts () { + PARTS=($(listParts "scad/${1}.scad")) + parallel --use-cpus-instead-of-cores bash ./scripts/openscadPart.sh "${1}.scad" "{}" "${1}_{}.stl" ::: "${PARTS[@]}" +} \ No newline at end of file diff --git a/scripts/openscadPart.sh b/scripts/openscadPart.sh new file mode 100644 index 0000000..68579fd --- /dev/null +++ b/scripts/openscadPart.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +openscad -o "./stl/${3}" -D"PART=\"${2}\"" "./scad/${1}" +echo "Compiled ${3} from ${1}" +if [ -f "./scad/common/c14n_stl.py" ]; then + python3 ./scad/common/c14n_stl.py "./stl/${3}" + echo "Normalized ${3}" +fi \ No newline at end of file diff --git a/scripts/scad.sh b/scripts/scad.sh index f2fa761..40fd7ed 100644 --- a/scripts/scad.sh +++ b/scripts/scad.sh @@ -1,5 +1,7 @@ #!/bin/bash +source ./scripts/common.sh + FILES=( arri_s bellows @@ -8,25 +10,11 @@ FILES=( mcopy_projector ) -openscadPart () { - openscad -o "./stl/${3}" -D"PART=\"${2}\"" "./scad/${1}" - echo "Compiled ${3} from ${1}" - if [ -f "./scad/common/c14n_stl.py" ]; then - python3 ./scad/common/c14n_stl.py "./stl/${3}" - echo "Normalized ${3}" - fi -} - -listParts () { - cat "${1}" | grep 'PART ==' | grep -v 'debug' | awk -F'"' '{print $2}' -} - -allParts () { - PARTS=($(listParts "scad/${1}.scad")) - for part in "${PARTS[@]}"; do - echo opencadPart "${1}.scad" "${part}" "${1}_${part}.stl" - done -} +PARALLEL=0 +HAS_PARALLEL=$(which parallel) +if [[ "${HAS_PARALLEL}" != "" ]]; then + PARALLEL=1 +fi if [[ "${1}" == "all" ]]; then for file in "${FILES[@]}"; do @@ -34,7 +22,11 @@ if [[ "${1}" == "all" ]]; then done else if [ -f "scad/${1}.scad" ]; then - allParts "${1}" + if [ ${PARALLEL} -eq 1 ]; then + parallelParts "${1}" + else + allParts "${1}" + fi elif [[ "${1}" != "" ]]; then echo "File scad/${1}.scad not found" exit 2