diff options
| author | Jamie Madill <jmadill@chromium.org> | 2016-05-10 07:36:20 -0700 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-05-16 09:03:27 -0600 |
| commit | 689d1dc52ebb76ae54d0f8697903d53bc6a3f763 (patch) | |
| tree | ace917cae51729d2742eb29de8dacd47f35581ca | |
| parent | 857a6accbf9cbf81edce6d7791d9c20e60e8dc6e (diff) | |
| download | usermoji-689d1dc52ebb76ae54d0f8697903d53bc6a3f763.tar.xz | |
layers: Add output file option to vk-generate scripts.
With some build systems, it's not easy to pipe stdout into a file.
This solution allows the scripts to use the last argument as an
output file option. This is a problem in partiuclar for GN.
| -rwxr-xr-x | vk-generate.py | 24 | ||||
| -rwxr-xr-x | vk-layer-generate.py | 18 |
2 files changed, 33 insertions, 9 deletions
diff --git a/vk-generate.py b/vk-generate.py index a1a7165f..c740494c 100755 --- a/vk-generate.py +++ b/vk-generate.py @@ -35,9 +35,14 @@ class Subcommand(object): self.argv = argv self.headers = vulkan.headers self.protos = vulkan.protos + self.outfile = None def run(self): - print(self.generate()) + if self.outfile: + with open(self.outfile, "w") as outfile: + outfile.write(self.generate()) + else: + print(self.generate()) def generate(self): copyright = self.generate_copyright() @@ -91,11 +96,19 @@ class Subcommand(object): class DispatchTableOpsSubcommand(Subcommand): def run(self): - if len(self.argv) != 1: + if len(self.argv) < 1: print("DispatchTableOpsSubcommand: <prefix> unspecified") return self.prefix = self.argv[0] + + if len(self.argv) > 2: + print("DispatchTableOpsSubcommand: <prefix> [outfile]") + return + + if len(self.argv) == 2: + self.outfile = self.argv[1] + super(DispatchTableOpsSubcommand, self).run() def generate_header(self): @@ -167,8 +180,8 @@ class WinDefFileSubcommand(Subcommand): ] } - if len(self.argv) != 2 or self.argv[1] not in library_exports: - print("WinDefFileSubcommand: <library-name> {%s}" % + if len(self.argv) < 2 or len(self.argv) > 3 or self.argv[1] not in library_exports: + print("WinDefFileSubcommand: <library-name> {%s} [outfile]" % "|".join(library_exports.keys())) return @@ -178,6 +191,9 @@ class WinDefFileSubcommand(Subcommand): else: self.exports = library_exports[self.argv[1]] + if len(self.argv) == 3: + self.outfile = self.argv[2] + super(WinDefFileSubcommand, self).run() def generate_copyright(self): diff --git a/vk-layer-generate.py b/vk-layer-generate.py index e57f8ec3..a76c29a0 100755 --- a/vk-layer-generate.py +++ b/vk-layer-generate.py @@ -164,8 +164,8 @@ def get_object_uses(obj_list, params): return (obj_uses, local_decls) class Subcommand(object): - def __init__(self, argv): - self.argv = argv + def __init__(self, outfile): + self.outfile = outfile self.headers = vulkan.headers self.protos = vulkan.protos self.no_addr = False @@ -174,7 +174,11 @@ class Subcommand(object): self.wsi = sys.argv[1] def run(self): - print(self.generate()) + if self.outfile: + with open(self.outfile, "w") as outfile: + outfile.write(self.generate()) + else: + print(self.generate()) def generate(self): copyright = self.generate_copyright() @@ -1664,7 +1668,7 @@ def main(): } if len(sys.argv) < 4 or sys.argv[1] not in wsi or sys.argv[2] not in subcommands or not os.path.exists(sys.argv[3]): - print("Usage: %s <wsi> <subcommand> <input_header> [options]" % sys.argv[0]) + print("Usage: %s <wsi> <subcommand> <input_header> [outdir]" % sys.argv[0]) print print("Available subcommands are: %s" % " ".join(subcommands)) exit(1) @@ -1678,7 +1682,11 @@ def main(): vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() vk_helper.types_dict = hfp.get_types_dict() - subcmd = subcommands[sys.argv[2]](sys.argv[3:]) + outfile = None + if len(sys.argv) >= 5: + outfile = sys.argv[4] + + subcmd = subcommands[sys.argv[2]](outfile) subcmd.run() if __name__ == "__main__": |
