Make all the scripts Python3

This commit is contained in:
Kevin Lange 2017-01-08 19:38:48 +09:00
parent ca8d3af8c7
commit e98a4a3785
7 changed files with 38 additions and 117 deletions

View File

@ -177,7 +177,7 @@ kernel/symbols.o: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} util/generate_symbols.py
@-rm -f kernel/symbols.o
@${BEG} "NM" "Generating symbol list..."
@${KCC} -T kernel/link.ld ${CFLAGS} -nostdlib -o toaruos-kernel ${KERNEL_ASMOBJS} ${KERNEL_OBJS} -lgcc ${ERRORS}
@${KNM} toaruos-kernel -g | python2 util/generate_symbols.py > kernel/symbols.S
@${KNM} toaruos-kernel -g | util/generate_symbols.py > kernel/symbols.S
@${END} "NM" "Generated symbol list."
@${BEG} "AS" "kernel/symbols.S"
@${KAS} ${ASFLAGS} kernel/symbols.S -o $@ ${ERRORS}

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# coding: utf-8
import os
import sys
@ -85,11 +85,11 @@ class Classifier(object):
"""Calculate include and library dependencies."""
lines = []
depends = []
with open(self.filename) as f:
with open(self.filename,'r') as f:
lines = f.readlines()
for l in lines:
if l.startswith('#include'):
depends.extend([k for k in self.dependency_hints.keys() if l.startswith('#include ' + k)])
depends.extend([k for k in list(self.dependency_hints.keys()) if l.startswith('#include ' + k)])
depends = self._calculate([], depends)
depends = self._sort(depends)
includes = []
@ -116,7 +116,7 @@ def todep(name):
if __name__ == "__main__":
if len(sys.argv) < 3:
print "usage: util/auto-dep.py command filename"
print("usage: util/auto-dep.py command filename")
exit(1)
command = sys.argv[1]
filename = sys.argv[2]
@ -124,11 +124,11 @@ if __name__ == "__main__":
c = Classifier(filename)
if command == "--cflags":
print " ".join([x for x in c.includes])
print(" ".join([x for x in c.includes]))
elif command == "--libs":
print " ".join([x for x in c.libs])
print(" ".join([x for x in c.libs]))
elif command == "--deps":
results = [todep(x) for x in c.libs]
normal = [x[1] for x in results if not x[0]]
order_only = [x[1] for x in results if x[0]]
print " ".join(normal) + " | " + " ".join(order_only)
print(" ".join(normal) + " | " + " ".join(order_only))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
for i in range(256):
print str(i) + "\t\x1b[48;5;" + str(i) + "m \x1b[0m"
print(str(i) + "\t\x1b[48;5;" + str(i) + "m \x1b[0m")

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python2
# coding: utf-8
#!/usr/bin/env python3
"""
Generate a symbol table from nm output.
"""
@ -8,33 +7,33 @@ import sys
# Write extern + type
def extern(name):
print ".extern %s" % (name)
print ".type %s, @function" % (name)
print ""
print(".extern %s" % (name))
print(".type %s, @function" % (name))
print("")
# Write an entry
def entry(name):
print ".long %s" % (name)
print ".asciz \"%s\"" % (name)
print ""
print(".long %s" % (name))
print(".asciz \"%s\"" % (name))
print("")
ignore = [ "abs", "kernel_symbols_start", "kernel_symbols_end" ]
lines = [ x.strip().split(" ")[2] for x in sys.stdin.readlines() if x not in ignore ]
# Generate the assembly
print ".section .symbols"
print ""
print(".section .symbols")
print("")
for name in lines:
extern(name)
print ".global kernel_symbols_start"
print "kernel_symbols_start:"
print ""
print(".global kernel_symbols_start")
print("kernel_symbols_start:")
print("")
for name in lines:
entry(name)
print ".global kernel_symbols_end"
print "kernel_symbols_end:"
print(".global kernel_symbols_end")
print("kernel_symbols_end:")

11
util/mod_deps.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# coding: utf-8
"""
Extract dependencies from kernel modules.
@ -10,7 +10,8 @@ import subprocess
def processModule(path):
p = subprocess.Popen(["i686-pc-toaru-nm",path,"-p"], stdout=subprocess.PIPE)
symbols, errors = p.communicate()
symbols, _ = p.communicate()
symbols = symbols.decode('utf-8')
name = [ x[2].replace("module_info_","") for x in [x.strip().split(" ") for x in symbols.split("\n") if len(x.strip().split(" ")) > 2] if x[1] == "D" and x[2].startswith("module_info_") ][0]
dependencies = [ x[2].replace("_mod_dependency_","") for x in [x.strip().split(" ") for x in symbols.split("\n") if len(x.strip().split(" ")) > 2] if x[1] == "d" and x[2].startswith("_mod_dependency_") ]
return path, name, dependencies
@ -27,7 +28,7 @@ for module in os.listdir("hdd/mod"):
# Okay, now let's spit out the dependencies for our module.
if len(sys.argv) < 2:
print >>sys.stderr, "Expected a path to a module (from the root of the build tree), eg. hdd/mod/test.ko"
print("Expected a path to a module (from the root of the build tree), eg. hdd/mod/test.ko", file=sys.stderr)
sys.exit(1)
me = sys.argv[-1]
@ -59,11 +60,11 @@ while set(satisfied) != set(depends):
if len(sys.argv) > 2:
for i in sys.argv[1:-1]:
if i == '--print-deps':
print name, "", " ".join(["\033[31m{mod}\033[m".format(mod=x) if not x in deps else x for x in satisfied])
print(name, "", " ".join(["\033[31m{mod}\033[m".format(mod=x) if not x in deps else x for x in satisfied]))
if i == '--print-files':
for i in satisfied:
print modules[i][0], "(dep-of-dep)" if i not in deps else ""
print(modules[i][0], "(dep-of-dep)" if i not in deps else "")
p = subprocess.Popen(["i686-pc-toaru-ld","-T","kernel/link.ld","-o","/dev/null","toaruos-kernel",]+[modules[x][0] for x in satisfied]+[me])

14
util/package-mods.py Normal file → Executable file
View File

@ -1,5 +1,4 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
import os
import struct
@ -22,17 +21,16 @@ mods_to_pack = [
with open('modpack.kop','wb') as pack:
for mod in mods_to_pack:
with open('hdd/mod/{mod}.ko'.format(mod=mod),'rb') as m:
print "Writing", mod
pack.write("PACK")
pack.write(b"PACK")
size = os.stat(m.name).st_size
extra = 0
while (size + extra) % 4096 != 0:
extra += 1
pack.write(struct.pack("I", size+extra))
pack.write('\0' * (4096-8))
pack.write(b'\0' * (4096-8))
pack.write(m.read(size))
pack.write('\0' * extra)
pack.write("PACK")
pack.write('\0\0\0\0')
pack.write(b'\0' * extra)
pack.write(b"PACK")
pack.write(b'\0\0\0\0')

View File

@ -1,77 +0,0 @@
#!/usr/bin/env python2
import subprocess
import sys
import time
class TestRunner(object):
def __init__(self):
self.passes = 0
self.fails = 0
def run(self):
self.qemu = subprocess.Popen(['make','-s','headless'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
time.sleep(2)
self.qemu.stdin.write("shell\n")
self.qemu.stdin.write("core-tests\n");
line = ""
while self.qemu.poll() == None:
charin = self.qemu.stdout.read(1)
if charin == '\n':
self.parse_line(line)
line = ""
else:
line += charin
print "\033[1mTest completed. \033[1;32m%d passes\033[0m, \033[1;31m%d failures\033[0m." % (self.passes, self.fails)
if self.fails > 0:
sys.exit(1)
def parse_line(self, line):
if line.startswith("core-tests :"):
output, result = self.process_line(line)
print output
if result > 0:
self.qemu.kill()
else:
self.log_line(line)
def process_line(self, line):
data = line.strip().split(" : ")
text = ""
color = ""
result = 0
if data[1] == "FAIL":
color = "1;31"
text = "fail"
self.fails += 1
elif data[1] == "WARN":
color = "1;33"
text = "warn"
elif data[1] == "PASS":
color = "1;32"
text = "pass"
self.passes += 1
elif data[1] == "INFO":
color = "1;34"
text = "info"
elif data[1] == "DONE":
color = "1;36"
text = "Done!"
result = 1
elif data[1] == "FATAL":
color = "1;37;41"
text = "FATAL ERROR ECOUNTERED"
result = 2
return "\033[%sm%s\033[0m %s" % (color, text, data[2]), result
def log_line(self, line):
print >>sys.stderr, line.strip()
if __name__ == "__main__":
TestRunner().run()