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

@ -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)