Improve revision handling.

This commit is contained in:
Brad Nelson
2024-01-01 17:58:20 -08:00
parent b222a19994
commit 67898d2a03
6 changed files with 85 additions and 24 deletions

View File

@ -26,10 +26,6 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = SCRIPT_DIR
NINJA_BUILD = os.path.join(ROOT_DIR, 'build.ninja')
REVISION = 'TODO'
#REVISION=$(shell git rev-parse HEAD | head -c 20)
#REVSHORT=$(shell echo $(REVISION) | head -c 7)
CFLAGS_COMMON = [
'-O2',
'-I', '$src',
@ -144,7 +140,8 @@ dst = {DST_DIR}
ninjadir = {NINJA_DIR}
builddir = $dst
VERSION = {VERSION}
REVISION = {REVISION}
STABLE_VERSION = {STABLE_VERSION}
OLD_STABLE_VERSION = {OLD_STABLE_VERSION}
CFLAGS = {' '.join(CFLAGS)}
STRIP_ARGS = {' '.join(STRIP_ARGS)}
LIBS = {' '.join(LIBS)}
@ -168,11 +165,23 @@ rule config
description = CONFIG
command = $src/configure.py -q
rule revstamp
description = REVSTAMP
command = $in $src $out
build $dst/gen/REVISION $dst/gen/REVSHORT: revstamp $src/tools/revstamp.py
rule importation
description = IMPORTATION $in
depfile = $out.d
deps = gcc
command = $src/tools/importation.py -i $in -o $out -I $dst -I $src $options --depsout $depfile -DVERSION=$VERSION -DREVISION=$REVERSION
command = $src/tools/importation.py -i $in -o $out -I $dst -I $src $options \
--depsout $depfile \
-DVERSION=$VERSION \
-DSTABLE_VERSION=$STABLE_VERSION \
-DOLD_STABLE_VERSION=$OLD_STABLE_VERSION \
-FREVISION=$dst/gen/REVISION \
-FREVSHORT=$dst/gen/REVSHORT
rule compile
description = CXX $in
@ -261,15 +270,14 @@ build allclean: all_clean
"""
def Importation(target, source, header_mode='cpp', name=None, keep=False, deps=None, implicit=[]):
def Importation(target, source, header_mode='cpp', name=None, keep=False, deps=None, implicit=[], options=''):
global output
options = ''
if keep:
options += '--keep-first-comment'
options += ' --keep-first-comment'
if name:
options += ' --name ' + name + ' --header ' + header_mode
implicit = ' '.join(implicit)
output += f'build {target}: importation {source} | {implicit}\n'
output += f'build {target}: importation {source} | $dst/gen/REVISION $dst/gen/REVSHORT {implicit}\n'
if options:
output += f' options = {options}\n'
if deps:

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
OPTIONS = '-I $src/esp32'
ESP32_FILES = []
ESP32_ZIP_FILES = []
@ -21,7 +22,7 @@ ESP32_ZIP_FILES += [
'$src/esp32/README.txt'),
Importation('$dst/esp32/ESP32forth/ESP32forth.ino',
'$src/esp32/ESP32forth.ino',
implicit=['$dst/gen/esp32_boot.h'], keep=True),
implicit=['$dst/gen/esp32_boot.h'], keep=True, options=OPTIONS),
]
Importation('$dst/gen/esp32_boot.h', '$src/esp32/esp32_boot.fs', name='boot')

View File

@ -20,22 +20,23 @@ REPLACE = [
'-DOLD_STABLE_VERSION=' + OLD_STABLE_VERSION,
]
UE_REPLACE = REPLACE + ['-DFORTH=uEForth']
ESP_REPLACE = REPLACE + ['-DFORTH=ESP32forth']
OPTIONS = '-I $src/site'
UE_OPTIONS = OPTIONS + ' -DFORTH=uEForth'
ESP_OPTIONS = OPTIONS + ' -DFORTH=ESP32forth'
DEPLOY_ITEMS = []
DEPLOY_ITEMS += [
Copy('$dst/deploy/.gcloudignore', '$src/site/.gcloudignore'),
Copy('$dst/deploy/ueforth.js', '$dst/web/ueforth.js'),
Importation('$dst/deploy/index.html', '$src/site/index.html'),
Importation('$dst/deploy/linux.html', '$src/site/linux.html'),
Importation('$dst/deploy/windows.html', '$src/site/windows.html'),
Importation('$dst/deploy/web.html', '$src/site/web.html'),
Importation('$dst/deploy/ESP32forth.html', '$src/site/ESP32forth.html'),
Importation('$dst/deploy/pico-ice.html', '$src/site/pico-ice.html'),
Importation('$dst/deploy/internals.html', '$src/site/internals.html'),
Importation('$dst/deploy/classic.html', '$src/site/classic.html'),
Importation('$dst/deploy/index.html', '$src/site/index.html', options=ESP_OPTIONS),
Importation('$dst/deploy/linux.html', '$src/site/linux.html', options=UE_OPTIONS),
Importation('$dst/deploy/windows.html', '$src/site/windows.html', options=UE_OPTIONS),
Importation('$dst/deploy/web.html', '$src/site/web.html', options=UE_OPTIONS),
Importation('$dst/deploy/ESP32forth.html', '$src/site/ESP32forth.html', options=ESP_OPTIONS),
Importation('$dst/deploy/pico-ice.html', '$src/site/pico-ice.html', options=UE_OPTIONS),
Importation('$dst/deploy/internals.html', '$src/site/internals.html', options=UE_OPTIONS),
Importation('$dst/deploy/classic.html', '$src/site/classic.html', options=ESP_OPTIONS),
Copy('$dst/deploy/eforth.go', '$src/site/eforth.go'),
Copy('$dst/deploy/app.yaml', '$src/site/app.yaml'),
]

View File

@ -24,6 +24,7 @@ parser.add_argument('-i', required=True)
parser.add_argument('-o', required=True)
parser.add_argument('-I', action='append')
parser.add_argument('-D', action='append')
parser.add_argument('-F', action='append')
parser.add_argument('--depsout')
parser.add_argument('--no-out', action='store_true')
parser.add_argument('--keep-first-comment', action='store_true')
@ -32,6 +33,7 @@ parser.add_argument('--header')
args = parser.parse_args()
bases = args.I or []
replacements = args.D or []
file_replacements = args.F or []
results = []
imported = set([__file__])
@ -57,9 +59,9 @@ def Import(filename):
sfilename = line.split('"')[1]
done = False
for base in bases:
sfilename = os.path.join(base, sfilename)
if os.path.exists(sfilename):
Import(sfilename)
bfilename = os.path.join(base, sfilename)
if os.path.exists(bfilename):
Import(bfilename)
done = True
break
if not done:
@ -75,6 +77,10 @@ def Process():
for r in replacements:
name, value = r.split('=', 1)
line = line.replace('{{' + name + '}}', value)
for r in file_replacements:
name, filename = r.split('=', 1)
imported.add(os.path.abspath(filename))
line = line.replace('{{' + name + '}}', open(filename).read())
output.append(line)
# Drop comments.
comment1 = False

View File

@ -1,4 +1,17 @@
#! /usr/bin/env python3
# Copyright 2023 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.
import sys

32
tools/revstamp.py Executable file
View File

@ -0,0 +1,32 @@
#! /usr/bin/env python3
# Copyright 2023 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.
import os
import subprocess
import sys
base_path = sys.argv[1]
revision_file = sys.argv[2]
revshort_file = sys.argv[3]
revision = subprocess.check_output('git rev-parse HEAD ' + base_path, shell=True).splitlines()[0]
revshort = revision[:7]
if not os.path.exists(revision_file) or open(revision_file).read() != revision:
with open(revision_file, 'wb') as fh:
fh.write(revision)
if not os.path.exists(revshort_file) or open(revshort_file).read() != revshort:
with open(revshort_file, 'wb') as fh:
fh.write(revshort)