Improved.
This commit is contained in:
@ -14,6 +14,7 @@ parser.add_argument('--set-version')
|
||||
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')
|
||||
args = parser.parse_args()
|
||||
bases = args.I or []
|
||||
|
||||
@ -33,6 +34,7 @@ def Import(filename):
|
||||
sfilename = os.path.join(os.path.dirname(filename), sfilename)
|
||||
Import(sfilename)
|
||||
elif (filename.endswith('.h') or
|
||||
filename.endswith('.ino') or
|
||||
filename.endswith('.cc') or
|
||||
filename.endswith('.c')) and line.startswith('#include "'):
|
||||
sfilename = line.split('"')[1]
|
||||
@ -50,17 +52,41 @@ def Import(filename):
|
||||
|
||||
def Process():
|
||||
Import(args.input)
|
||||
# Conversion version tags.
|
||||
output = []
|
||||
for line in results:
|
||||
if args.set_version:
|
||||
line = line.replace('{{VERSION}}', args.set_version)
|
||||
if args.set_revision:
|
||||
line = line.replace('{{REVISION}}', args.set_revision)
|
||||
output.append(line)
|
||||
# Drop comments.
|
||||
comment1 = False
|
||||
comment2 = False
|
||||
counter = 0
|
||||
old_output = output
|
||||
output = []
|
||||
for line in old_output:
|
||||
if line == '<!--':
|
||||
comment1 = True
|
||||
elif comment1 and line == '-->':
|
||||
comment1 = False
|
||||
elif 'Copyright' in line:
|
||||
if counter != 0 or not args.keep_first_comment:
|
||||
comment2 = True
|
||||
counter += 1
|
||||
elif comment2 and line == '':
|
||||
comment2 = False
|
||||
elif not comment1 and not comment2:
|
||||
output.append(line)
|
||||
# Emit deps.
|
||||
if args.depsout:
|
||||
with open(args.depsout, 'w') as fh:
|
||||
fh.write(args.output + ': ' +
|
||||
' '.join([os.path.relpath(i) for i in imported]) + '\n')
|
||||
# Emit expanded file.
|
||||
if not args.no_out:
|
||||
with open(args.output, 'w') as fh:
|
||||
fh.write('\n'.join(results) + '\n')
|
||||
fh.write('\n'.join(output) + '\n')
|
||||
|
||||
Process()
|
||||
|
||||
Reference in New Issue
Block a user