89 lines
4.7 KiB
JavaScript
89 lines
4.7 KiB
JavaScript
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
const crypto = require("crypto");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { pathToFileURL } = require("url");
|
|
|
|
const buildDirectory = path.resolve(process.argv[2] || "build-web/configure/bin");
|
|
const sourceRevision = "837f44197c879e41198b7e3bed55c897a9920520";
|
|
|
|
async function main()
|
|
{
|
|
globalThis.__dirname = `${buildDirectory}${path.sep}`;
|
|
globalThis.require = require;
|
|
const moduleUrl = pathToFileURL(path.join(buildDirectory, "FreeCADWebOpenSCADRuntimeProbe.js")).href;
|
|
const module = await import(moduleUrl);
|
|
const probe = await module.default({
|
|
wasmBinary: fs.readFileSync(path.join(buildDirectory, "FreeCADWebOpenSCADRuntimeProbe.wasm")),
|
|
});
|
|
const call = (name, returnType = "number", argTypes = [], args = []) => probe.ccall(name, returnType, argTypes, args);
|
|
const error = () => ({
|
|
code: call("fc_web_openscad_inspect_error_code", "string"),
|
|
field: call("fc_web_openscad_inspect_error_field", "string"),
|
|
message: call("fc_web_openscad_inspect_error_message", "string"),
|
|
});
|
|
const run = () => {
|
|
const details = {
|
|
run: call("fc_web_openscad_inspect_source_inventory", "number", ["string"], [sourceRevision]),
|
|
error: error(),
|
|
sourceRevision: call("fc_web_openscad_inspect_source_revision", "string"),
|
|
summary: call("fc_web_openscad_inspect_summary", "string"),
|
|
sourceEntry: call("fc_web_openscad_inspect_source_entry", "string"),
|
|
registrationEntry: call("fc_web_openscad_inspect_registration_entry", "string"),
|
|
targets: call("fc_web_openscad_inspect_targets_json", "string"),
|
|
registeredTypes: call("fc_web_openscad_inspect_registered_types_json", "string"),
|
|
registeredFormats: call("fc_web_openscad_inspect_registered_formats_json", "string"),
|
|
dependencies: call("fc_web_openscad_inspect_dependencies_json", "string"),
|
|
guiExcluded: call("fc_web_openscad_inspect_gui_excluded_json", "string"),
|
|
readOnly: call("fc_web_openscad_inspect_read_only"),
|
|
objectTypeCount: call("fc_web_openscad_inspect_object_type_count"),
|
|
formatExtensionCount: call("fc_web_openscad_inspect_format_extension_count"),
|
|
formatEvidenceCount: call("fc_web_openscad_inspect_format_evidence_count"),
|
|
pythonApiCount: call("fc_web_openscad_inspect_python_api_count"),
|
|
guiPythonApiCount: call("fc_web_openscad_inspect_gui_python_api_count"),
|
|
moduleHandleBeforeRelease: call("fc_web_openscad_inspect_module_handle_before_release"),
|
|
moduleHandleAfterRelease: call("fc_web_openscad_inspect_module_handle_after_release"),
|
|
documentCountBefore: call("fc_web_openscad_inspect_document_count_before"),
|
|
documentCountAfter: call("fc_web_openscad_inspect_document_count_after"),
|
|
persistenceApplicable: call("fc_web_openscad_inspect_persistence_applicable"),
|
|
persistenceReason: call("fc_web_openscad_inspect_persistence_reason", "string"),
|
|
};
|
|
details.resultSha256 = crypto.createHash("sha256").update(details.summary).digest("hex");
|
|
return details;
|
|
};
|
|
|
|
const first = run();
|
|
const second = run();
|
|
const invalidRevision = call("fc_web_openscad_inspect_source_inventory", "number", ["string"], ["wrong-revision"]);
|
|
const invalidError = error();
|
|
const valid = (details) => details.run === 1
|
|
&& details.error.code === ""
|
|
&& details.sourceRevision === sourceRevision
|
|
&& details.sourceEntry === "src/Mod/OpenSCAD/Init.py"
|
|
&& details.registrationEntry === "src/Mod/OpenSCAD/Init.py:31-43"
|
|
&& details.targets === "[\"OpenSCAD\"]"
|
|
&& details.registeredTypes === "[]"
|
|
&& details.registeredFormats === "[\"csg\",\"CSG\",\"scad\"]"
|
|
&& details.readOnly === 1
|
|
&& details.objectTypeCount === 0
|
|
&& details.formatExtensionCount === 4
|
|
&& details.formatEvidenceCount === 1
|
|
&& details.pythonApiCount === 2
|
|
&& details.guiPythonApiCount === 0
|
|
&& details.moduleHandleBeforeRelease === 1
|
|
&& details.moduleHandleAfterRelease === 0
|
|
&& details.documentCountBefore === details.documentCountAfter
|
|
&& details.persistenceApplicable === 0;
|
|
if (!valid(first) || !valid(second) || JSON.stringify(first) !== JSON.stringify(second)
|
|
|| invalidRevision !== 0 || invalidError.code !== "revision_mismatch") {
|
|
throw new Error(JSON.stringify({first, second, invalidRevision, invalidError}));
|
|
}
|
|
console.log(JSON.stringify({result: "pass", action: "inspect/source-inventory", runs: 2, details: first}));
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|