Run openscad from /home (w/ symlinks to libs) and force user files to relative

This commit is contained in:
ochafik 2023-03-26 22:33:14 +01:00
commit bcebd5ae00
10 changed files with 68 additions and 122 deletions

View file

@ -26,8 +26,8 @@ export const checkSyntax =
const result = await job;
// console.log(result);
res(processMergedOutputs(result.mergedOutputs, {shiftSourceLines: {
[sourcePath]: 1,
[sourcePath.split('/').slice(-1)[0]]: 1
sourcePath,
skipLines: 1,
}}));
} catch (e) {
console.error(e);
@ -52,7 +52,7 @@ export const render =
turnIntoDelayableExecution(renderDelay, (params: RenderArgs) => {
const args = [
params.sourcePath,
"-o", "/home/out.stl",
"-o", "out.stl",
"--export-format=binstl",
...(params.features ?? []).map(f => `--enable=${f}`),
...(params.extraArgs ?? [])
@ -68,7 +68,7 @@ export const render =
// wasmMemory,
inputs: [[params.sourcePath, source]],
args,
outputPaths: ['/home/out.stl']
outputPaths: ['out.stl']
});
return AbortablePromise<RenderOutput>((resolve, reject) => {
@ -79,8 +79,8 @@ export const render =
const {logText, markers} = processMergedOutputs(result.mergedOutputs, {
shiftSourceLines: {
[params.sourcePath]: prefixLines.length,
[params.sourcePath.split('/').slice(-1)[0]]: prefixLines.length
sourcePath: params.sourcePath,
skipLines: prefixLines.length
}
});

View file

@ -2,7 +2,7 @@
import OpenSCAD from "../wasm/openscad.js";
import { createEditorFS, getBrowserFSLibrariesMounts, librariesFolder, symlinkLibraries } from "../fs/filesystem";
import { createEditorFS, getBrowserFSLibrariesMounts, symlinkLibraries } from "../fs/filesystem";
import { OpenSCADInvocation, OpenSCADInvocationResults } from "./openscad-runner";
import { zipArchives } from "../fs/zip-archives";
declare var BrowserFS: BrowserFSInterface
@ -17,7 +17,7 @@ export type MergedOutputs = {stdout?: string, stderr?: string, error?: string}[]
addEventListener('message', async (e) => {
const { inputs, args, outputPaths, wasmMemory, workingDir } = e.data as OpenSCADInvocation;
const { inputs, args, outputPaths, wasmMemory } = e.data as OpenSCADInvocation;
const mergedOutputs: MergedOutputs = [];
try {

View file

@ -1,4 +1,5 @@
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import { getFileName } from '../fs/filesystem';
import { MergedOutputs } from "./openscad-worker";
const ignoredLogs = new Set([
@ -6,7 +7,10 @@ const ignoredLogs = new Set([
]);
type MergedOutputsOptions = {
shiftSourceLines: {[path: string]: number}
shiftSourceLines?: {
sourcePath: string,
skipLines: number,
}
}
export const processMergedOutputs = (outputs: MergedOutputs, opts: MergedOutputsOptions) => ({
logText: joinMergedOutputs(outputs, opts),
@ -41,9 +45,14 @@ export function parseMergedOutputs(mergedOutputs: MergedOutputs, opts: MergedOut
severity: monaco.MarkerSeverity.Error
})
}
const shiftSourceName = opts.shiftSourceLines && getFileName(opts.shiftSourceLines.sourcePath);
const getLine = (path: string, lineStr: string) => {
const shift = opts.shiftSourceLines[path] ?? 0;
return Number(lineStr) - shift;
const line = Number(lineStr);
if (shiftSourceName && getFileName(path) == shiftSourceName) {
return line - opts.shiftSourceLines!.skipLines;
} else {
return line;
}
}
for (const {stderr, stdout, error} of mergedOutputs){
if (stderr) {