Switching more into importation.
This commit is contained in:
@ -94,14 +94,10 @@ rule mkdir
|
||||
description = mkdir
|
||||
command = mkdir -p $out
|
||||
|
||||
rule source_to_string
|
||||
description = source_to_string
|
||||
command = ../tools/source_to_string.js $name $version $revision $in >$out
|
||||
|
||||
rule importation
|
||||
description = import
|
||||
description = importation
|
||||
depfile = $out.dd
|
||||
command = ../tools/importation.py $in $out -I . -I .. --depsout $out.dd --set-version $version --set-revision $revision
|
||||
command = ../tools/importation.py $in $out -I . -I .. --name $name --header $header_mode --depsout $out.dd --set-version $version --set-revision $revision
|
||||
|
||||
build gen: mkdir
|
||||
|
||||
@ -113,23 +109,20 @@ build gen: mkdir
|
||||
'libs': ' '.join(LIBS),
|
||||
}
|
||||
|
||||
def ForthHeader(target, name, source):
|
||||
def ForthHeader(target, name, source, header_mode='cpp'):
|
||||
source = '../' + source
|
||||
global output
|
||||
output += """
|
||||
build %(target)s: source_to_string %(target)s.merged | gen
|
||||
name = %(name)s
|
||||
|
||||
build %(target)s.merged: importation %(source)s | gen
|
||||
""" % {
|
||||
'target': target,
|
||||
'source': os.path.join('..', source),
|
||||
'name': name,
|
||||
}
|
||||
output += f"""
|
||||
build {target}: importation {source} | gen
|
||||
name = {name}
|
||||
header_mode = {header_mode}
|
||||
"""
|
||||
|
||||
ForthHeader('gen/posix_boot.h', 'boot', 'posix/posix_boot.fs')
|
||||
ForthHeader('gen/window_boot.h', 'boot', 'windows/windows_boot.fs')
|
||||
ForthHeader('gen/window_boot_extra.h', 'boot_extra', 'windows/windows_boot_extra.fs')
|
||||
ForthHeader('gen/window_boot.h', 'boot', 'windows/windows_boot.fs', header_mode='win')
|
||||
ForthHeader('gen/window_boot_extra.h', 'boot_extra', 'windows/windows_boot_extra.fs', header_mode='win')
|
||||
ForthHeader('gen/pico_ice_boot.h', 'boot', 'pico-ice/pico_ice_boot.fs')
|
||||
ForthHeader('gen/esp32_boot.h', 'boot', 'esp32/esp32_boot.fs')
|
||||
ForthHeader('gen/web_boot.js', 'boot', 'esp32/esp32_boot.fs', header_mode='web')
|
||||
|
||||
print(output)
|
||||
|
||||
@ -15,6 +15,8 @@ parser.add_argument('--set-revision')
|
||||
parser.add_argument('--depsout')
|
||||
parser.add_argument('--no-out', action='store_true')
|
||||
parser.add_argument('--keep-first-comment', action='store_true')
|
||||
parser.add_argument('--name')
|
||||
parser.add_argument('--header')
|
||||
args = parser.parse_args()
|
||||
bases = args.I or []
|
||||
|
||||
@ -88,6 +90,25 @@ def Process():
|
||||
# Emit expanded file.
|
||||
if not args.no_out:
|
||||
with open(args.output, 'w') as fh:
|
||||
fh.write('\n'.join(output) + '\n')
|
||||
if args.header == 'web':
|
||||
fh.write('const ' + args.name + ' = `\n' +
|
||||
'\n'.join(output) + '\n`;\n')
|
||||
elif args.header == 'cpp':
|
||||
fh.write('const char ' + args.name + '[] = R"""(\n' +
|
||||
'\n'.join(output) + '\n)""";\n')
|
||||
elif args.header == 'win':
|
||||
fixed = []
|
||||
for line in output:
|
||||
line = line.replace('\\', '\\\\')
|
||||
line = line.replace('"', '\\"')
|
||||
line = '"' + line + '\\n"'
|
||||
if line.startswith('"(') and line.endswith(')\\n"'):
|
||||
line = '// ' + line
|
||||
if line:
|
||||
fixed.append(line)
|
||||
fh.write('const char ' + args.name + '[] =\n' +
|
||||
'\n'.join(fixed) + '\n;\n')
|
||||
else:
|
||||
fh.write('\n'.join(output) + '\n')
|
||||
|
||||
Process()
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
#! /usr/bin/env nodejs
|
||||
// Copyright 2021 Bradley D. Nelson
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
function DropCopyright(source) {
|
||||
var lines = source.split('\n');
|
||||
var cleaned = [];
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
if (lines[i].search('Copyright') >= 0) {
|
||||
while (lines[i] != '') {
|
||||
++i;
|
||||
}
|
||||
} else {
|
||||
cleaned.push(lines[i]);
|
||||
}
|
||||
}
|
||||
return cleaned.join('\n');
|
||||
}
|
||||
|
||||
var is_windows = false;
|
||||
var is_web = false;
|
||||
|
||||
var args = process.argv.slice(2);
|
||||
if (args.length > 0 && args[0] == '-win') {
|
||||
is_windows = true;
|
||||
args.shift();
|
||||
}
|
||||
if (args.length > 0 && args[0] == '-web') {
|
||||
is_web = true;
|
||||
args.shift();
|
||||
}
|
||||
var name = args.shift();
|
||||
var version = args.shift();
|
||||
var revision = args.shift();
|
||||
var source = '';
|
||||
while (args.length > 0) {
|
||||
source += DropCopyright(fs.readFileSync(args.shift()).toString());
|
||||
}
|
||||
|
||||
source = source.replace('{{VERSION}}', version);
|
||||
source = source.replace('{{REVISION}}', revision);
|
||||
|
||||
if (is_windows) {
|
||||
source = source.replace(/\\/g, '\\\\');
|
||||
source = source.replace(/["]/g, '\\"');
|
||||
source = '"' + source.split('\n').join('\\n"\n"') + '\\n"';
|
||||
source = source.replace(/["] ["]/g, '');
|
||||
source = source.replace(/["] [(] ([^)]*)[)] ["]/g, '// $1');
|
||||
source = 'const char ' + name + '[] =\n' + source + ';\n';
|
||||
} else if (is_web) {
|
||||
source = 'const ' + name + ' = `\n' + source + '`;\n';
|
||||
} else {
|
||||
source = 'const char ' + name + '[] = R"""(\n' + source + ')""";\n';
|
||||
}
|
||||
|
||||
process.stdout.write(source);
|
||||
Reference in New Issue
Block a user