mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-22 07:37:40 +00:00
feat(developer): move kmc-kmn to KeymanCompiler interface
Part of #9473. KmnCompiler now implements KeymanCompiler, including the returned artifacts. Also establishes the common types for the compiler interfaces and consolidates and renames various API surfaces for kmc-kmn.
This commit is contained in:
parent
e81b18fc44
commit
6bebefda10
14 changed files with 172 additions and 101 deletions
|
|
@ -27,6 +27,13 @@ export { defaultCompilerOptions, CompilerBaseOptions, CompilerCallbacks, Compile
|
|||
compilerExceptionToString, compilerErrorFormatCode,
|
||||
compilerLogLevelToSeverity, CompilerLogLevel, compilerEventFormat, ALL_COMPILER_LOG_LEVELS,
|
||||
ALL_COMPILER_LOG_FORMATS, CompilerLogFormat,
|
||||
|
||||
KeymanCompilerArtifact,
|
||||
KeymanCompilerArtifactOptional,
|
||||
KeymanCompilerArtifacts,
|
||||
KeymanCompilerResult,
|
||||
KeymanCompiler
|
||||
|
||||
} from './util/compiler-interfaces.js';
|
||||
export { CommonTypesMessages } from './util/common-events.js';
|
||||
|
||||
|
|
|
|||
|
|
@ -253,6 +253,40 @@ export interface CompilerCallbackOptions {
|
|||
compilerWarningsAsErrors?: boolean;
|
||||
};
|
||||
|
||||
export interface KeymanCompilerArtifact {
|
||||
data: Uint8Array;
|
||||
filename: string;
|
||||
};
|
||||
|
||||
export type KeymanCompilerArtifactOptional = KeymanCompilerArtifact | undefined;
|
||||
|
||||
export interface KeymanCompilerArtifacts {
|
||||
readonly [type:string]: KeymanCompilerArtifactOptional;
|
||||
};
|
||||
|
||||
export interface KeymanCompilerResult {
|
||||
artifacts: KeymanCompilerArtifacts;
|
||||
};
|
||||
|
||||
export interface KeymanCompiler {
|
||||
init(callbacks: CompilerCallbacks, options: CompilerOptions): Promise<boolean>;
|
||||
/**
|
||||
* Run the compiler, and save the result in memory arrays. Note that while
|
||||
* `outputFilename` is provided here, the output file is not written to in
|
||||
* this function.
|
||||
* @param inputFilename
|
||||
* @param outputFilename The intended output filename, optional, if missing,
|
||||
* calculated from inputFilename
|
||||
* @param data
|
||||
*/
|
||||
run(inputFilename:string, outputFilename?:string /*, data?: any*/): Promise<KeymanCompilerResult>;
|
||||
/**
|
||||
* Writes the compiled output files to disk
|
||||
* @param artifacts
|
||||
*/
|
||||
write(artifacts: KeymanCompilerArtifacts): Promise<boolean>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract interface for callbacks, to abstract out file i/o
|
||||
*/
|
||||
|
|
@ -369,10 +403,7 @@ export interface CompilerBaseOptions {
|
|||
* Format of output for log to console
|
||||
*/
|
||||
logFormat?: CompilerLogFormat;
|
||||
/**
|
||||
* Optional output file for activities that generate output
|
||||
*/
|
||||
outFile?: string;
|
||||
outFile?: string; //TODO:REMOVE
|
||||
/**
|
||||
* Colorize log output, default is detected from console
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@ export async function getOskFromKmnFile(callbacks: CompilerCallbacks, filename:
|
|||
let touchLayoutFilename: string;
|
||||
|
||||
const kmnCompiler = new KmnCompiler();
|
||||
if(!await kmnCompiler.init(callbacks)) {
|
||||
if(!await kmnCompiler.init(callbacks, {
|
||||
shouldAddCompilerVersion: false,
|
||||
saveDebug: false,
|
||||
})) {
|
||||
// kmnCompiler will report errors
|
||||
return null;
|
||||
}
|
||||
|
||||
let result = kmnCompiler.runCompiler(filename, {
|
||||
shouldAddCompilerVersion: false,
|
||||
saveDebug: false,
|
||||
});
|
||||
let result = await kmnCompiler.run(filename, null);
|
||||
|
||||
if(!result) {
|
||||
// kmnCompiler will report any errors
|
||||
|
|
@ -29,7 +29,7 @@ export async function getOskFromKmnFile(callbacks: CompilerCallbacks, filename:
|
|||
}
|
||||
|
||||
const reader = new KmxFileReader();
|
||||
const keyboard: KMX.KEYBOARD = reader.read(result.kmx.data);
|
||||
const keyboard: KMX.KEYBOARD = reader.read(result.artifacts.kmx.data);
|
||||
const touchLayoutStore = keyboard.stores.find(store => store.dwSystemID == KMX.KMXFile.TSS_LAYOUTFILE);
|
||||
|
||||
if(touchLayoutStore) {
|
||||
|
|
|
|||
|
|
@ -6,17 +6,12 @@ TODO: implement additional interfaces:
|
|||
*/
|
||||
|
||||
// TODO: rename wasm-host?
|
||||
import { UnicodeSetParser, UnicodeSet, Osk, VisualKeyboard, KvkFileReader } from '@keymanapp/common-types';
|
||||
import { UnicodeSetParser, UnicodeSet, Osk, VisualKeyboard, KvkFileReader, KeymanCompiler, KeymanCompilerArtifacts, KeymanCompilerArtifactOptional, KeymanCompilerResult, KeymanCompilerArtifact } from '@keymanapp/common-types';
|
||||
import { CompilerCallbacks, CompilerEvent, CompilerOptions, KeymanFileTypes, KvkFileWriter, KvksFileReader } from '@keymanapp/common-types';
|
||||
import loadWasmHost from '../import/kmcmplib/wasm-host.js';
|
||||
import { CompilerMessages, mapErrorFromKmcmplib } from './kmn-compiler-messages.js';
|
||||
import { WriteCompiledKeyboard } from '../kmw-compiler/kmw-compiler.js';
|
||||
|
||||
export interface CompilerResultFile {
|
||||
filename: string;
|
||||
data: Uint8Array;
|
||||
};
|
||||
|
||||
//
|
||||
// Matches kmcmplibapi.h definitions
|
||||
//
|
||||
|
|
@ -46,7 +41,7 @@ export const COMPILETARGETS__MASK = 0x03;
|
|||
/**
|
||||
* Data in CompilerResultExtra comes from kmcmplib
|
||||
*/
|
||||
export interface CompilerResultExtra {
|
||||
export interface KmnCompilerResultExtra {
|
||||
/**
|
||||
* A bitmask, consisting of COMPILETARGETS_KMX and/or COMPILETARGETS_JS
|
||||
*/
|
||||
|
|
@ -61,11 +56,15 @@ export interface CompilerResultExtra {
|
|||
// Internal in-memory result from a successful compilation
|
||||
//
|
||||
|
||||
export interface CompilerResult {
|
||||
kmx?: CompilerResultFile;
|
||||
kvk?: CompilerResultFile;
|
||||
js?: CompilerResultFile;
|
||||
extra: CompilerResultExtra;
|
||||
export interface KmnCompilerArtifacts extends KeymanCompilerArtifacts {
|
||||
kmx?: KeymanCompilerArtifactOptional;
|
||||
kvk?: KeymanCompilerArtifactOptional;
|
||||
js?: KeymanCompilerArtifactOptional;
|
||||
};
|
||||
|
||||
export interface KmnCompilerResult extends KeymanCompilerResult {
|
||||
artifacts: KmnCompilerArtifacts;
|
||||
extra: KmnCompilerResultExtra;
|
||||
displayMap?: Osk.PuaMap;
|
||||
};
|
||||
|
||||
|
|
@ -97,18 +96,20 @@ interface MallocAndFree {
|
|||
let
|
||||
Module: any;
|
||||
|
||||
export class KmnCompiler implements UnicodeSetParser {
|
||||
export class KmnCompiler implements KeymanCompiler, UnicodeSetParser {
|
||||
callbackID: string; // a unique numeric id added to globals with prefixed names
|
||||
callbacks: CompilerCallbacks;
|
||||
wasmExports: MallocAndFree;
|
||||
options: KmnCompilerOptions;
|
||||
|
||||
constructor() {
|
||||
this.callbackID = callbackPrefix + callbackProcIdentifier.toString();
|
||||
callbackProcIdentifier++;
|
||||
}
|
||||
|
||||
public async init(callbacks: CompilerCallbacks): Promise<boolean> {
|
||||
public async init(callbacks: CompilerCallbacks, options: KmnCompilerOptions): Promise<boolean> {
|
||||
this.callbacks = callbacks;
|
||||
this.options = options;
|
||||
if(!Module) {
|
||||
try {
|
||||
Module = await loadWasmHost();
|
||||
|
|
@ -140,20 +141,22 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
return true;
|
||||
}
|
||||
|
||||
public run(infile: string, options?: KmnCompilerOptions): boolean {
|
||||
let result = this.runCompiler(infile, options);
|
||||
if(result) {
|
||||
if(result.kmx) {
|
||||
this.callbacks.fs.writeFileSync(result.kmx.filename, result.kmx.data);
|
||||
}
|
||||
if(result.kvk) {
|
||||
this.callbacks.fs.writeFileSync(result.kvk.filename, result.kvk.data);
|
||||
}
|
||||
if(result.js) {
|
||||
this.callbacks.fs.writeFileSync(result.js.filename, result.js.data);
|
||||
}
|
||||
public async write(artifacts: KmnCompilerArtifacts): Promise<boolean> {
|
||||
if(!artifacts) {
|
||||
throw Error('artifacts must be defined');
|
||||
}
|
||||
return !!result;
|
||||
|
||||
if(artifacts.kmx) {
|
||||
this.callbacks.fs.writeFileSync(artifacts.kmx.filename, artifacts.kmx.data);
|
||||
}
|
||||
if(artifacts.kvk) {
|
||||
this.callbacks.fs.writeFileSync(artifacts.kvk.filename, artifacts.kvk.data);
|
||||
}
|
||||
if(artifacts.js) {
|
||||
this.callbacks.fs.writeFileSync(artifacts.js.filename, artifacts.js.data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private compilerMessageCallback = (line: number, code: number, msg: string): number => {
|
||||
|
|
@ -196,9 +199,10 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
return 1;
|
||||
}
|
||||
|
||||
private copyWasmResult(wasm_result: any): CompilerResult {
|
||||
let result: CompilerResult = {
|
||||
private copyWasmResult(wasm_result: any): KmnCompilerResult {
|
||||
let result: KmnCompilerResult = {
|
||||
// We cannot Object.assign or {...} on a wasm-defined object, so...
|
||||
artifacts: {},
|
||||
extra: {
|
||||
targets: wasm_result.extra.targets,
|
||||
displayMapFilename: wasm_result.extra.displayMapFilename,
|
||||
|
|
@ -234,15 +238,15 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
return new Uint8Array(new Uint8Array(Module.HEAP8.buffer, offset, size));
|
||||
}
|
||||
|
||||
public runCompiler(infile: string, options: KmnCompilerOptions): CompilerResult {
|
||||
public async run(infile: string, outfile: string): Promise<KmnCompilerResult> {
|
||||
if(!this.verifyInitialized()) {
|
||||
/* c8 ignore next 2 */
|
||||
return null;
|
||||
}
|
||||
|
||||
options = {...baseOptions, ...options};
|
||||
const options = {...baseOptions, ...this.options};
|
||||
|
||||
options.outFile = options.outFile ?? infile.replace(/\.kmn$/i, '.kmx');
|
||||
outfile = outfile ?? infile.replace(/\.kmn$/i, '.kmx');
|
||||
|
||||
(globalThis as any)[this.callbackID] = {
|
||||
message: this.compilerMessageCallback,
|
||||
|
|
@ -264,11 +268,11 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
return null;
|
||||
}
|
||||
|
||||
const result: CompilerResult = this.copyWasmResult(wasm_result);
|
||||
const result: KmnCompilerResult = this.copyWasmResult(wasm_result);
|
||||
|
||||
if(result.extra.targets & COMPILETARGETS_KMX) {
|
||||
result.kmx = {
|
||||
filename: options.outFile,
|
||||
result.artifacts.kmx = {
|
||||
filename: outfile,
|
||||
data: this.copyWasmBuffer(wasm_result.kmx, wasm_result.kmxSize)
|
||||
};
|
||||
}
|
||||
|
|
@ -286,8 +290,8 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
}
|
||||
|
||||
if(result.extra.kvksFilename) {
|
||||
result.kvk = this.runKvkCompiler(result.extra.kvksFilename, infile, options.outFile, result.displayMap);
|
||||
if(!result.kvk) {
|
||||
result.artifacts.kvk = this.runKvkCompiler(result.extra.kvksFilename, infile, outfile, result.displayMap);
|
||||
if(!result.artifacts.kvk) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -308,12 +312,12 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
if(!wasm_result.result) {
|
||||
return null;
|
||||
}
|
||||
const kmw_result: CompilerResult = this.copyWasmResult(wasm_result);
|
||||
const kmw_result: KmnCompilerResult = this.copyWasmResult(wasm_result);
|
||||
kmw_result.displayMap = result.displayMap; // we can safely re-use the kmx compile displayMap
|
||||
|
||||
const web_kmx = this.copyWasmBuffer(wasm_result.kmx, wasm_result.kmxSize);
|
||||
result.js = this.runWebCompiler(infile, options.outFile, web_kmx, result.kvk?.data, kmw_result, options);
|
||||
if(!result.js) {
|
||||
result.artifacts.js = this.runWebCompiler(infile, outfile, web_kmx, result.artifacts.kvk?.data, kmw_result, options);
|
||||
if(!result.artifacts.js) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -338,9 +342,9 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
kmxFilename: string,
|
||||
web_kmx: Uint8Array,
|
||||
kvk: Uint8Array,
|
||||
kmxResult: CompilerResult,
|
||||
kmxResult: KmnCompilerResult,
|
||||
options: CompilerOptions
|
||||
): CompilerResultFile {
|
||||
): KeymanCompilerArtifact {
|
||||
const data = WriteCompiledKeyboard(this.callbacks, kmnFilename, web_kmx, kvk, kmxResult, options.saveDebug);
|
||||
if(!data) {
|
||||
return null;
|
||||
|
|
@ -348,7 +352,7 @@ export class KmnCompiler implements UnicodeSetParser {
|
|||
|
||||
return {
|
||||
filename: this.callbacks.path.join(this.callbacks.path.dirname(kmxFilename),
|
||||
this.keyboardIdFromKmnFilename(kmnFilename) + KeymanFileTypes.Binary.WebKeyboard),
|
||||
this.keyboardIdFromKmnFilename(kmnFilename) + KeymanFileTypes.Binary.WebKeyboard),
|
||||
data: new TextEncoder().encode(data)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { KMX, CompilerCallbacks, CompilerOptions } from "@keymanapp/common-types";
|
||||
import { CompilerResult } from "../compiler/compiler.js";
|
||||
import { KmnCompilerResult } from "../compiler/compiler.js";
|
||||
|
||||
export let FTabStop: string;
|
||||
export let nl: string;
|
||||
export let FCompilerWarningsAsErrors = false;
|
||||
export let kmxResult: CompilerResult;
|
||||
export let kmxResult: KmnCompilerResult;
|
||||
export let fk: KMX.KEYBOARD;
|
||||
export let FMnemonic: boolean;
|
||||
export let options: CompilerOptions;
|
||||
|
|
@ -19,7 +19,7 @@ export function setupGlobals(
|
|||
_options: CompilerOptions,
|
||||
_tab: string,
|
||||
_nl: string,
|
||||
_kmxResult: CompilerResult,
|
||||
_kmxResult: KmnCompilerResult,
|
||||
_keyboard: KMX.KEYBOARD,
|
||||
_kmnfile: string
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { JavaScript_ContextMatch, JavaScript_KeyAsString, JavaScript_Name, JavaS
|
|||
import { KmwCompilerMessages } from "./kmw-compiler-messages.js";
|
||||
import { ValidateLayoutFile } from "./validate-layout-file.js";
|
||||
import { VisualKeyboardFromFile } from "./visual-keyboard-compiler.js";
|
||||
import { CompilerResult, STORETYPE_DEBUG, STORETYPE_OPTION, STORETYPE_RESERVED } from "../compiler/compiler.js";
|
||||
import { KmnCompilerResult, STORETYPE_DEBUG, STORETYPE_OPTION, STORETYPE_RESERVED } from "../compiler/compiler.js";
|
||||
|
||||
function requote(s: string): string {
|
||||
return "'" + s.replaceAll(/(['\\])/g, "\\$1") + "'";
|
||||
|
|
@ -41,7 +41,7 @@ export function WriteCompiledKeyboard(
|
|||
kmnfile: string,
|
||||
keyboardData: Uint8Array,
|
||||
kvkData: Uint8Array,
|
||||
kmxResult: CompilerResult,
|
||||
kmxResult: KmnCompilerResult,
|
||||
FDebug: boolean = false
|
||||
): string {
|
||||
let opts: CompilerOptions = {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { dirname } from 'path';
|
|||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
|
||||
import { CompilerResult, KmnCompiler } from '../../src/compiler/compiler.js';
|
||||
import { KmnCompilerResult, KmnCompiler } from '../../src/compiler/compiler.js';
|
||||
import { ETLResult, extractTouchLayout as parseWebTestResult } from './util.js';
|
||||
import { KeymanFileTypes } from '@keymanapp/common-types';
|
||||
|
||||
|
|
@ -27,7 +27,10 @@ describe('KeymanWeb Compiler', function() {
|
|||
const kmnCompiler: KmnCompiler = new KmnCompiler();
|
||||
|
||||
this.beforeAll(async function() {
|
||||
assert.isTrue(await kmnCompiler.init(callbacks));
|
||||
assert.isTrue(await kmnCompiler.init(callbacks, {
|
||||
shouldAddCompilerVersion: false,
|
||||
saveDebug: true,
|
||||
}));
|
||||
});
|
||||
|
||||
this.afterEach(function() {
|
||||
|
|
@ -79,18 +82,16 @@ describe('KeymanWeb Compiler', function() {
|
|||
});
|
||||
|
||||
|
||||
function run_test_keyboard(kmnCompiler: KmnCompiler, id: string): { result: CompilerResult, actualCode: string, actual: ETLResult, expectedCode: string, expected: ETLResult } {
|
||||
async function run_test_keyboard(kmnCompiler: KmnCompiler, id: string):
|
||||
Promise<{ result: KmnCompilerResult, actualCode: string, actual: ETLResult, expectedCode: string, expected: ETLResult }> {
|
||||
const filenames = generateTestFilenames(id);
|
||||
|
||||
let result = kmnCompiler.runCompiler(filenames.source, {
|
||||
shouldAddCompilerVersion: false,
|
||||
saveDebug: true,
|
||||
});
|
||||
let result = await kmnCompiler.run(filenames.source, null);
|
||||
assert.isNotNull(result);
|
||||
|
||||
let value = {
|
||||
result,
|
||||
actualCode: new TextDecoder().decode(result.js.data),
|
||||
actualCode: new TextDecoder().decode(result.artifacts.js.data),
|
||||
expectedCode: fs.readFileSync(filenames.fixture, 'utf8'),
|
||||
expected: <ETLResult>null,
|
||||
actual: <ETLResult>null,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ describe('Compiler class', function() {
|
|||
const compiler = new KmnCompiler();
|
||||
const callbacks : any = null; // ERROR
|
||||
try {
|
||||
await compiler.init(callbacks)
|
||||
await compiler.init(callbacks, null)
|
||||
assert.fail('Expected exception');
|
||||
} catch(e) {
|
||||
assert.ok(e);
|
||||
|
|
@ -26,21 +26,27 @@ describe('Compiler class', function() {
|
|||
it('should start', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, null));
|
||||
assert(compiler.verifyInitialized());
|
||||
});
|
||||
|
||||
it('should compile a basic keyboard', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, {saveDebug: true, shouldAddCompilerVersion: false}));
|
||||
assert(compiler.verifyInitialized());
|
||||
|
||||
const fixtureName = baselineDir + 'k_000___null_keyboard.kmx';
|
||||
const infile = baselineDir + 'k_000___null_keyboard.kmn';
|
||||
const outFile = __dirname + '/k_000___null_keyboard.kmx';
|
||||
|
||||
assert(compiler.run(infile, {saveDebug: true, outFile, shouldAddCompilerVersion: false}));
|
||||
if(fs.existsSync(outFile)) {
|
||||
fs.rmSync(outFile);
|
||||
}
|
||||
|
||||
const result = await compiler.run(infile, outFile);
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(await compiler.write(result.artifacts));
|
||||
|
||||
assert(fs.existsSync(outFile));
|
||||
const outfileData = fs.readFileSync(outFile);
|
||||
|
|
@ -54,7 +60,7 @@ describe('Compiler class', function() {
|
|||
it('should build all baseline fixtures', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, {saveDebug: true, shouldAddCompilerVersion: false}));
|
||||
assert(compiler.verifyInitialized());
|
||||
|
||||
const files = fs.readdirSync(baselineDir);
|
||||
|
|
@ -64,7 +70,13 @@ describe('Compiler class', function() {
|
|||
const infile = baselineDir + file.replace(/x$/, 'n');
|
||||
const outFile = __dirname + '/' + file;
|
||||
|
||||
assert(compiler.run(infile, {saveDebug: true, outFile, shouldAddCompilerVersion: false}));
|
||||
if(fs.existsSync(outFile)) {
|
||||
fs.rmSync(outFile);
|
||||
}
|
||||
|
||||
const result = await compiler.run(infile, outFile);
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(await compiler.write(result.artifacts));
|
||||
|
||||
assert(fs.existsSync(outFile));
|
||||
const outfileData = fs.readFileSync(outFile);
|
||||
|
|
@ -78,7 +90,10 @@ describe('Compiler class', function() {
|
|||
it('should compile a keyboard with visual keyboard', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert.isTrue(await compiler.init(callbacks));
|
||||
assert.isTrue(await compiler.init(callbacks, {
|
||||
saveDebug: true,
|
||||
shouldAddCompilerVersion: false,
|
||||
}));
|
||||
assert.isTrue(compiler.verifyInitialized());
|
||||
|
||||
const fixtureDir = keyboardsDir + 'caps_lock_layer_3620/'
|
||||
|
|
@ -89,11 +104,17 @@ describe('Compiler class', function() {
|
|||
const resultingKmxfile = __dirname + '/caps_lock_layer_3620.kmx';
|
||||
const resultingKvkfile = __dirname + '/caps_lock_layer_3620.kvk';
|
||||
|
||||
assert.isTrue(compiler.run(infile, {
|
||||
saveDebug: true,
|
||||
shouldAddCompilerVersion: false,
|
||||
outFile: resultingKmxfile,
|
||||
}));
|
||||
if(fs.existsSync(resultingKmxfile)) {
|
||||
fs.rmSync(resultingKmxfile);
|
||||
}
|
||||
|
||||
if(fs.existsSync(resultingKvkfile)) {
|
||||
fs.rmSync(resultingKvkfile);
|
||||
}
|
||||
|
||||
const result = await compiler.run(infile, resultingKmxfile);
|
||||
assert.isNotNull(result);
|
||||
assert.isTrue(await compiler.write(result.artifacts));
|
||||
|
||||
assert.isTrue(fs.existsSync(resultingKmxfile));
|
||||
assert.isTrue(fs.existsSync(resultingKvkfile));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe('Keyboard compiler features', async function() {
|
|||
this.beforeAll(async function() {
|
||||
compiler = new KmnCompiler();
|
||||
callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, {saveDebug: true}));
|
||||
assert(compiler.verifyInitialized());
|
||||
});
|
||||
|
||||
|
|
@ -29,15 +29,15 @@ describe('Keyboard compiler features', async function() {
|
|||
];
|
||||
|
||||
for(const v of versions) {
|
||||
it(`should build a version ${v[0]} keyboard`, function() {
|
||||
it(`should build a version ${v[0]} keyboard`, async function() {
|
||||
const fixtureName = makePathToFixture('features', `version_${v[1]}.kmn`);
|
||||
|
||||
const result = compiler.runCompiler(fixtureName, {outFile: `version_${v[1]}.kmx`, saveDebug: true});
|
||||
const result = await compiler.run(fixtureName, `version_${v[1]}.kmx`);
|
||||
if(result === null) callbacks.printMessages();
|
||||
assert.isNotNull(result);
|
||||
|
||||
const reader = new KmxFileReader();
|
||||
const keyboard = reader.read(result.kmx.data);
|
||||
const keyboard = reader.read(result.artifacts.kmx.data);
|
||||
assert.equal(keyboard.fileVersion, v[2]);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ describe('CompilerMessages', function () {
|
|||
callbacks.clear();
|
||||
|
||||
const compiler = new KmnCompiler();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, {saveDebug: true, shouldAddCompilerVersion: false}));
|
||||
assert(compiler.verifyInitialized());
|
||||
|
||||
const kmnPath = makePathToFixture(...fixture);
|
||||
|
||||
// Note: throwing away compile results (just to memory)
|
||||
compiler.runCompiler(kmnPath, {saveDebug: true, shouldAddCompilerVersion: false});
|
||||
await compiler.run(kmnPath, null);
|
||||
|
||||
if(messageId) {
|
||||
assert.isTrue(callbacks.hasMessage(messageId), `messageId ${messageId.toString(16)} not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@ describe('Compiler UnicodeSet function', function() {
|
|||
it('should start', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, null));
|
||||
assert(compiler.verifyInitialized());
|
||||
});
|
||||
|
||||
it('should compile a basic uset', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, null));
|
||||
assert(compiler.verifyInitialized());
|
||||
|
||||
const pat = "[abc]";
|
||||
|
|
@ -50,7 +50,7 @@ describe('Compiler UnicodeSet function', function() {
|
|||
it('should compile a more complex uset', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, null));
|
||||
assert(compiler.verifyInitialized());
|
||||
|
||||
const pat = "[[🙀A-C]-[CB]]";
|
||||
|
|
@ -70,7 +70,7 @@ describe('Compiler UnicodeSet function', function() {
|
|||
it('should compile an even more complex uset', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, null));
|
||||
assert(compiler.verifyInitialized());
|
||||
|
||||
const pat = "[\\u{10FFFD}\\u{2019}\\u{22}\\u{a}\\u{ead}\\u{1F640}]";
|
||||
|
|
@ -97,7 +97,7 @@ describe('Compiler UnicodeSet function', function() {
|
|||
it('should fail in various ways', async function() {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new TestCompilerCallbacks();
|
||||
assert(await compiler.init(callbacks));
|
||||
assert(await compiler.init(callbacks, null));
|
||||
assert(compiler.verifyInitialized());
|
||||
// map from string to failing error
|
||||
const failures = {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export class LdmlKeyboardCompiler {
|
|||
if (this.usetparser === undefined) {
|
||||
// initialize
|
||||
const compiler = new KmnCompiler();
|
||||
const ok = await compiler.init(this.callbacks);
|
||||
const ok = await compiler.init(this.callbacks, null);
|
||||
if (ok) {
|
||||
this.usetparser = compiler;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,16 +11,12 @@ export class BuildKmnKeyboard extends BuildActivity {
|
|||
public get sourceExtension(): KeymanFileTypes.Source { return KeymanFileTypes.Source.KeymanKeyboard; }
|
||||
public get compiledExtension(): KeymanFileTypes.Binary { return KeymanFileTypes.Binary.Keyboard; }
|
||||
public get description(): string { return 'Build a Keyman keyboard'; }
|
||||
public async build(infile: string, callbacks: CompilerCallbacks, options: CompilerOptions): Promise<boolean> {
|
||||
let compiler = new KmnCompiler();
|
||||
if(!await compiler.init(callbacks)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public async build(infile: string, /*TODO: outfile?: string,*/ callbacks: CompilerCallbacks, options: CompilerOptions): Promise<boolean> {
|
||||
// We need to resolve paths to absolute paths before calling kmc-kmn
|
||||
if(options.outFile) {
|
||||
options.outFile = getPosixAbsolutePath(options.outFile);
|
||||
const folderName = path.dirname(options.outFile);
|
||||
let outfile = options.outFile;//TODO: remove here
|
||||
if(outfile) {
|
||||
outfile = getPosixAbsolutePath(outfile);
|
||||
const folderName = path.dirname(outfile);
|
||||
try {
|
||||
fs.mkdirSync(folderName, {recursive: true});
|
||||
} catch(e) {
|
||||
|
|
@ -29,7 +25,18 @@ export class BuildKmnKeyboard extends BuildActivity {
|
|||
}
|
||||
}
|
||||
infile = getPosixAbsolutePath(infile);
|
||||
return compiler.run(infile, options);
|
||||
|
||||
const compiler = new KmnCompiler();
|
||||
if(!await compiler.init(callbacks, options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const result = await compiler.run(infile, outfile);
|
||||
if(!result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return await compiler.write(result.artifacts);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export class TestKeymanSentry {
|
|||
if(cli.includes('kmcmplib')) {
|
||||
const compiler = new KmnCompiler();
|
||||
const callbacks = new NodeCompilerCallbacks({});
|
||||
if(!await compiler.init(callbacks)) {
|
||||
if(!await compiler.init(callbacks, null)) {
|
||||
throw new Error('Failed to instantiate WASM compiler');
|
||||
}
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue