summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Lexy Munroe) <eevee.git@veekun.com>2016-08-24 17:10:04 -0700
committerEevee (Lexy Munroe) <eevee.git@veekun.com>2016-08-24 17:10:04 -0700
commit89c054a265caecb0681032a154077ed89fecf760 (patch)
tree6743095e35d013b81d0d874c7237fe5906278e39
parent30c2048b14a5d3d0b5bda25f4c9119b9f1fc1fde (diff)
Clean up scan_includes a bit
- Use the with statement, so it works with pypy (dies with "too many open files" otherwise) - Nuke dem tabs - Get rid of the global, yikes
-rw-r--r--pokemontools/scan_includes.py60
1 files changed, 34 insertions, 26 deletions
diff --git a/pokemontools/scan_includes.py b/pokemontools/scan_includes.py
index 53ff091..fea7002 100644
--- a/pokemontools/scan_includes.py
+++ b/pokemontools/scan_includes.py
@@ -4,40 +4,48 @@
"""
Recursively scan an asm file for dependencies.
"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
import sys
import argparse
import os.path
-includes = set()
def scan_file(filename):
- for line in open(filename):
- if 'INC' not in line:
- continue
- line = line.split(';')[0]
- if 'INCLUDE' in line:
- include = line.split('"')[1]
- if os.path.exists("src/"):
- includes.add("src/" + include)
- scan_file("src/" + include)
- else:
- includes.add(include)
- scan_file(include)
- elif 'INCBIN' in line:
- include = line.split('"')[1]
- if 'baserom.gbc' not in line and os.path.exists("src/"):
- includes.add("src/" + include)
- else:
- includes.add(include)
+ with open(filename) as f:
+ for line in f:
+ if 'INC' not in line:
+ continue
+ line = line.split(';')[0]
+ if 'INCLUDE' in line:
+ include = line.split('"')[1]
+ if os.path.exists("src/"):
+ yield "src/" + include
+ for inc in scan_file("src/" + include):
+ yield inc
+ else:
+ yield include
+ for inc in scan_file(include):
+ yield inc
+ elif 'INCBIN' in line:
+ include = line.split('"')[1]
+ if 'baserom.gbc' not in line and os.path.exists("src/"):
+ yield "src/" + include
+ else:
+ yield include
+
def main():
- ap = argparse.ArgumentParser()
- ap.add_argument('filenames', nargs='*')
- args = ap.parse_args()
- for filename in set(args.filenames):
- scan_file(filename)
- sys.stdout.write(' '.join(includes))
+ ap = argparse.ArgumentParser()
+ ap.add_argument('filenames', nargs='*')
+ args = ap.parse_args()
+ includes = set()
+ for filename in set(args.filenames):
+ includes.update(scan_file(filename))
+ sys.stdout.write(' '.join(sorted(includes)))
+
if __name__ == '__main__':
- main()
+ main()