mirror of https://github.com/pret/pokecrystal.git
rewrite scan_includes to skip duplicates
seems to be faster this way
This commit is contained in:
parent
aaf26de8ed
commit
b5702e24d9
|
@ -2,30 +2,29 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Recursively scan an asm file for rgbasm INCLUDEs and INCBINs.
|
Recursively scan an asm file for rgbasm INCLUDEs and INCBINs.
|
||||||
This is used to generate dependencies for each rgbasm object file.
|
Used to generate dependencies for each rgbasm object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def scan_for_includes(filename):
|
def recursive_scan(filename, includes = []):
|
||||||
filenames = []
|
if (filename[-4:] == '.asm' or filename[-3] == '.tx') and os.path.exists(filename):
|
||||||
if os.path.exists(filename):
|
lines = open(filename).readlines()
|
||||||
for line in open(filename, 'r').readlines():
|
for line in lines:
|
||||||
if 'INCLUDE' in line or 'INCBIN' in line:
|
for directive in ('INCLUDE', 'INCBIN'):
|
||||||
line = line.split(';')[0]
|
if directive in line:
|
||||||
if 'INCLUDE' in line or 'INCBIN' in line:
|
line = line[:line.find(';')]
|
||||||
filenames += [line.split('"')[1]]
|
if directive in line:
|
||||||
return filenames
|
include = line.split('"')[1]
|
||||||
|
if include not in includes:
|
||||||
|
includes += [include]
|
||||||
|
includes = recursive_scan(include, includes)
|
||||||
|
break
|
||||||
|
return includes
|
||||||
|
|
||||||
def recursive_scan_for_includes(filename):
|
if __name__ == '__main__':
|
||||||
filenames = []
|
filenames = sys.argv[1:]
|
||||||
if '.asm' in filename or '.tx' in filename:
|
for filename in filenames:
|
||||||
for include in scan_for_includes(filename):
|
sys.stdout.write(' '.join(recursive_scan(filename)))
|
||||||
filenames += [include] + recursive_scan_for_includes(include)
|
|
||||||
return filenames
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
|
||||||
for arg in sys.argv[1:]:
|
|
||||||
sys.stdout.write(' '.join(recursive_scan_for_includes(arg)))
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue