Browse Source

Add JS-based configure utils

pull/2258/head
Sami Vaarala 5 years ago
parent
commit
f81ee6710b
  1. 19
      src-tools/lib/configure/duk_version.js
  2. 46
      src-tools/lib/configure/scan_used_stridx_bidx.js
  3. 208
      src-tools/lib/configure/source_files.js
  4. 28
      src-tools/lib/configure/util.js

19
src-tools/lib/configure/duk_version.js

@ -0,0 +1,19 @@
'use strict';
const { readFileUtf8 } = require('../util/fs');
// Parse Duktape version from duktape.h.in.
function getDukVersion(filename) {
var data = readFileUtf8(filename);
var m = /^#define\s+DUK_VERSION\s+(.*?)L?\s*$/m.exec(data);
if (m) {
var dukVersion = Math.floor(Number(m[1]));
var dukMajor = Math.floor(dukVersion / 10000)
var dukMinor = Math.floor((dukVersion % 10000) / 100)
var dukPatch = Math.floor(dukVersion % 100)
var dukVersionFormatted = dukMajor + '.' + dukMinor + '.' + dukPatch;
return { dukVersion, dukMajor, dukMinor, dukPatch, dukVersionFormatted };
}
throw new TypeError('cannot figure out Duktape version from ' + filename);
}
exports.getDukVersion = getDukVersion;

46
src-tools/lib/configure/scan_used_stridx_bidx.js

@ -0,0 +1,46 @@
'use strict';
const { readFileUtf8 } = require('../util/fs');
// Scan source files for:
// - strings which need a stridx (to thr->strs[])
// - objects which need a bidx (to thr->builtins[])
// - DUK_USE_xxx config options referenced
function scanUsedStridxBidx(filenameList) {
var strDefs = {};
var objDefs = {};
var optDefs = {};
function matchAll(data, re, map) {
var m;
while ((m = re.exec(data)) !== null) {
map[m[1]] = true;
}
}
for (let fn of filenameList) {
const re_str_stridx = /DUK_STRIDX_(\w+)/gm;
const re_str_heap = /DUK_HEAP_STRING_(\w+)/gm;
const re_str_hthread = /DUK_HTHREAD_STRING_(\w+)/gm;
const re_obj_bidx = /DUK_BIDX_(\w+)/gm;
const re_duk_use = /DUK_USE_(\w+)/gm;
let data = readFileUtf8(fn);
matchAll(data, re_str_stridx, strDefs);
matchAll(data, re_str_heap, strDefs);
matchAll(data, re_str_hthread, strDefs);
matchAll(data, re_obj_bidx, objDefs);
matchAll(data, re_duk_use, optDefs);
}
var strUsed = Object.keys(strDefs).sort().map((v) => 'DUK_STRIDX_' + v);
var objUsed = Object.keys(objDefs).sort().map((v) => 'DUK_BIDX_' + v);
var optUsed = Object.keys(optDefs).sort().map((v) => 'DUK_USE_' + v);
return {
usedStridxDefines: strUsed,
usedBidxDefines: objUsed,
usedDukUseOptions: optUsed,
};
}
exports.scanUsedStridxBidx = scanUsedStridxBidx;

208
src-tools/lib/configure/source_files.js

@ -0,0 +1,208 @@
'use strict';
const { listDir, pathJoin } = require('../util/fs');
// Source files included in configure and dist.
const sourceFiles = [
'duk_alloc_default.c',
'duk_api_internal.h',
'duk_api_stack.c',
'duk_api_heap.c',
'duk_api_buffer.c',
'duk_api_call.c',
'duk_api_codec.c',
'duk_api_compile.c',
'duk_api_bytecode.c',
'duk_api_inspect.c',
'duk_api_memory.c',
'duk_api_object.c',
'duk_api_random.c',
'duk_api_string.c',
'duk_api_time.c',
'duk_api_debug.c',
'duk_bi_array.c',
'duk_bi_boolean.c',
'duk_bi_buffer.c',
'duk_bi_cbor.c',
'duk_bi_date.c',
'duk_bi_date_unix.c',
'duk_bi_date_windows.c',
'duk_bi_duktape.c',
'duk_bi_encoding.c',
'duk_bi_error.c',
'duk_bi_function.c',
'duk_bi_global.c',
'duk_bi_json.c',
'duk_bi_math.c',
'duk_bi_number.c',
'duk_bi_object.c',
'duk_bi_performance.c',
'duk_bi_pointer.c',
'duk_bi_protos.h',
'duk_bi_reflect.c',
'duk_bi_regexp.c',
'duk_bi_string.c',
'duk_bi_promise.c',
'duk_bi_proxy.c',
'duk_bi_symbol.c',
'duk_bi_thread.c',
'duk_bi_thrower.c',
'duk_dblunion.h',
'duk_debug_fixedbuffer.c',
'duk_debug.h',
'duk_debug_macros.c',
'duk_debug_vsnprintf.c',
'duk_debugger.c',
'duk_debugger.h',
'duk_error_augment.c',
'duk_error.h',
'duk_error_longjmp.c',
'duk_error_macros.c',
'duk_error_misc.c',
'duk_error_throw.c',
'duk_fltunion.h',
'duk_forwdecl.h',
'duk_harray.h',
'duk_hboundfunc.h',
'duk_hbuffer_alloc.c',
'duk_hbuffer_assert.c',
'duk_hbuffer.h',
'duk_hbuffer_ops.c',
'duk_hbufobj.h',
'duk_hbufobj_misc.c',
'duk_hcompfunc.h',
'duk_heap_alloc.c',
'duk_heap.h',
'duk_heap_hashstring.c',
'duk_heaphdr.h',
'duk_heaphdr_assert.c',
'duk_heap_finalize.c',
'duk_heap_markandsweep.c',
'duk_heap_memory.c',
'duk_heap_misc.c',
'duk_heap_refcount.c',
'duk_heap_stringcache.c',
'duk_heap_stringtable.c',
'duk_hnatfunc.h',
'duk_hobject_alloc.c',
'duk_hobject_assert.c',
'duk_hobject_class.c',
'duk_hobject_enum.c',
'duk_hobject.h',
'duk_hobject_misc.c',
'duk_hobject_pc2line.c',
'duk_hobject_props.c',
'duk_hproxy.h',
'duk_hstring.h',
'duk_hstring_assert.c',
'duk_hstring_misc.c',
'duk_hthread_alloc.c',
'duk_hthread_builtins.c',
'duk_hthread.h',
'duk_hthread_misc.c',
'duk_hthread_stacks.c',
'duk_henv.h',
'duk_internal.h',
'duk_jmpbuf.h',
'duk_exception.h',
'duk_js_arith.c',
'duk_js_bytecode.h',
'duk_js_call.c',
'duk_js_compiler.c',
'duk_js_compiler.h',
'duk_js_executor.c',
'duk_js.h',
'duk_json.h',
'duk_js_ops.c',
'duk_js_var.c',
'duk_lexer.c',
'duk_lexer.h',
'duk_numconv.c',
'duk_numconv.h',
'duk_refcount.h',
'duk_regexp_compiler.c',
'duk_regexp_executor.c',
'duk_regexp.h',
'duk_tval.c',
'duk_tval.h',
'duk_unicode.h',
'duk_unicode_support.c',
'duk_unicode_tables.c',
'duk_util.h',
'duk_util_bitdecoder.c',
'duk_util_bitencoder.c',
'duk_util_hashbytes.c',
'duk_util_tinyrandom.c',
'duk_util_bufwriter.c',
'duk_util_double.c',
'duk_util_cast.c',
'duk_util_memory.c',
'duk_util_memrw.c',
'duk_util_misc.c',
'duk_selftest.c',
'duk_selftest.h',
'duk_strings.h',
'duk_replacements.c',
'duk_replacements.h'
];
exports.sourceFiles = sourceFiles;
// Select source files for amalgamation, taking into consideration some
// ordering constraints.
function selectCombinedSources(srcDirectory) {
// These files must appear before the alphabetically sorted
// ones so that static variables get defined before they're
// used. We can't forward declare them because that would
// cause C++ issues (see GH-63). When changing, verify by
// compiling with g++.
var handpick = [
'duk_replacements.c',
'duk_debug_macros.c',
'duk_builtins.c',
'duk_error_macros.c',
'duk_unicode_support.c',
'duk_util_memrw.c',
'duk_util_misc.c',
'duk_hobject_class.c'
];
// These files are ignored, e.g. autogenerated C files which are
// pulled in using #includes.
var ignore = [
'duk_unicode_caseconv.c',
'duk_unicode_caseconv.h',
'duk_unicode_re_canon_lookup.c',
'duk_unicode_re_canon_lookup.h',
'duk_unicode_re_canon_bitmap.c',
'duk_unicode_re_canon_bitmap.h',
'duk_unicode_ids_noa.c',
'duk_unicode_ids_noa.h',
'duk_unicode_ids_noabmp.c',
'duk_unicode_ids_noabmp.h',
'duk_unicode_ids_m_let_noa.c',
'duk_unicode_ids_m_let_noa.h',
'duk_unicode_ids_m_let_noabmp.c',
'duk_unicode_ids_m_let_noabmp.h',
'duk_unicode_idp_m_ids_noa.c',
'duk_unicode_idp_m_ids_noa.h',
'duk_unicode_idp_m_ids_noabmp.c',
'duk_unicode_idp_m_ids_noabmp.h'
];
var files = [];
handpick.forEach((fn) => { files.push(fn); });
listDir(srcDirectory).sort().forEach((fn) => {
if (!fn.endsWith('.c') || ignore.indexOf(fn) >= 0) {
return;
}
if (files.indexOf(fn) >= 0) {
return;
}
files.push(fn);
});
var res = files.map((fn) => pathJoin(srcDirectory, fn));
return res;
}
exports.selectCombinedSources = selectCombinedSources;

28
src-tools/lib/configure/util.js

@ -0,0 +1,28 @@
'use strict';
const { readFileUtf8, writeFileUtf8, pathJoin, copyFile } = require('../util/fs');
const { stripLastNewline } = require('../util/string_util');
function copyFiles(fileList, srcDir, dstDir) {
for (let fn of fileList.sort()) {
let srcFn = pathJoin(srcDir, fn);
let dstFn = pathJoin(dstDir, fn);
copyFile(srcFn, dstFn);
}
}
exports.copyFiles = copyFiles;
function cBlockQuoteFile(fn) {
var data = stripLastNewline(readFileUtf8(fn));
var lines = data.split('\n').map(function (line) {
return ' * ' + line.replace(/[^\x20-\x7e]/g, function (c) { return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).substr(-4); });
});
return '/*\n' + lines.join('\n') + '\n */';
}
exports.cBlockQuoteFile = cBlockQuoteFile;
function copyAndCQuote(srcFn, dstFn) {
var data = cBlockQuoteFile(srcFn);
writeFileUtf8(dstFn, data);
}
exports.copyAndCQuote = copyAndCQuote;
Loading…
Cancel
Save