libc: generate syscall stubs in one big file...
...all the better to switch to a genrule rather than checking in
generated source.
This also removes all the code in the script to deal with git,
rather than fix it. We won't need that where we're going.
Test: boots
Change-Id: I468ce019d4232a7ef27e5cb5cfd89f4c2fe4ecbd
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 31a8bd0..9b6dc81 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -20,39 +20,10 @@
all_arches = [ "arm", "arm64", "mips", "mips64", "x86", "x86_64" ]
+bionic_libc = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
-# temp directory where we store all intermediate files
-bionic_temp = tempfile.mkdtemp(prefix="bionic_gensyscalls");
-# Make sure the directory is deleted when the script exits.
-atexit.register(shutil.rmtree, bionic_temp)
-
-bionic_libc_root = os.path.join(os.path.dirname(os.path.abspath(__file__)),
- "..")
-
-warning = "Generated by gensyscalls.py. Do not edit."
-
-DRY_RUN = False
-
-def make_dir(path):
- path = os.path.abspath(path)
- if not os.path.exists(path):
- parent = os.path.dirname(path)
- if parent:
- make_dir(parent)
- os.mkdir(path)
-
-
-def create_file(relpath):
- full_path = os.path.join(bionic_temp, relpath)
- dir = os.path.dirname(full_path)
- make_dir(dir)
- return open(full_path, "w")
-
-
-syscall_stub_header = "/* " + warning + " */\n" + \
+syscall_stub_header = \
"""
-#include <private/bionic_asm.h>
-
ENTRY(%(func)s)
"""
@@ -97,7 +68,7 @@
#
-# Arm64 assembler templates for each syscall stub
+# Arm64 assembler template for each syscall stub
#
arm64_call = syscall_stub_header + """\
@@ -114,7 +85,7 @@
#
-# MIPS assembler templates for each syscall stub
+# MIPS assembler template for each syscall stub
#
mips_call = syscall_stub_header + """\
@@ -136,7 +107,7 @@
#
-# MIPS64 assembler templates for each syscall stub
+# MIPS64 assembler template for each syscall stub
#
mips64_call = syscall_stub_header + """\
@@ -199,7 +170,7 @@
#
-# x86_64 assembler templates for each syscall stub
+# x86_64 assembler template for each syscall stub
#
x86_64_call = """\
@@ -525,8 +496,6 @@
class State:
def __init__(self):
- self.old_stubs = []
- self.new_stubs = []
self.syscalls = []
@@ -564,84 +533,20 @@
syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
- # Write each syscall stub.
- def gen_syscall_stubs(self):
- for syscall in self.syscalls:
- for arch in all_arches:
- if syscall.has_key("asm-%s" % arch):
- filename = "arch-%s/syscalls/%s.S" % (arch, syscall["func"])
- logging.info(">>> generating " + filename)
- fp = create_file(filename)
- fp.write(syscall["asm-%s" % arch])
- fp.close()
- self.new_stubs.append(filename)
-
-
def regenerate(self):
- logging.info("scanning for existing architecture-specific stub files...")
-
for arch in all_arches:
- arch_dir = "arch-" + arch
- logging.info("scanning " + os.path.join(bionic_libc_root, arch_dir))
- rel_path = os.path.join(arch_dir, "syscalls")
- for file in os.listdir(os.path.join(bionic_libc_root, rel_path)):
- if file.endswith(".S"):
- self.old_stubs.append(os.path.join(rel_path, file))
-
- logging.info("found %d stub files" % len(self.old_stubs))
-
- if not os.path.exists(bionic_temp):
- logging.info("creating %s..." % bionic_temp)
- make_dir(bionic_temp)
-
- logging.info("re-generating stubs...")
-
- self.gen_syscall_stubs()
-
- logging.info("comparing files...")
- adds = []
- edits = []
-
- for stub in self.new_stubs:
- tmp_file = os.path.join(bionic_temp, stub)
- libc_file = os.path.join(bionic_libc_root, stub)
- if not os.path.exists(libc_file):
- # new file, git add it
- logging.info("new file: " + stub)
- adds.append(libc_file)
- shutil.copyfile(tmp_file, libc_file)
-
- elif not filecmp.cmp(tmp_file, libc_file):
- logging.info("changed file: " + stub)
- edits.append(stub)
-
- deletes = []
- for stub in self.old_stubs:
- if not stub in self.new_stubs:
- logging.info("deleted file: " + stub)
- deletes.append(os.path.join(bionic_libc_root, stub))
-
- if not DRY_RUN:
- if adds:
- commands.getoutput("git add " + " ".join(adds))
- if deletes:
- commands.getoutput("git rm " + " ".join(deletes))
- if edits:
- for file in edits:
- shutil.copyfile(os.path.join(bionic_temp, file),
- os.path.join(bionic_libc_root, file))
- commands.getoutput("git add " + " ".join((os.path.join(bionic_libc_root, file)) for file in edits))
-
- commands.getoutput("git add %s" % (os.path.join(bionic_libc_root, "SYSCALLS.TXT")))
-
- if (not adds) and (not deletes) and (not edits):
- logging.info("no changes detected!")
- else:
- logging.info("ready to go!!")
+ filename = '%s/arch-%s/syscalls.S' % (bionic_libc, arch)
+ fp = open(filename, 'w')
+ fp.write("/* Generated by gensyscalls.py. Do not edit. */\n")
+ fp.write("#include <private/bionic_asm.h>\n")
+ for syscall in self.syscalls:
+ if syscall.has_key("asm-%s" % arch):
+ fp.write(syscall["asm-%s" % arch])
+ fp.close()
logging.basicConfig(level=logging.INFO)
if __name__ == "__main__":
state = State()
- state.process_file(os.path.join(bionic_libc_root, "SYSCALLS.TXT"))
+ state.process_file(os.path.join(bionic_libc, "SYSCALLS.TXT"))
state.regenerate()