Last active
December 1, 2023 07:03
-
-
Save uroboro/240cb3122b00e0faa70e449250ff614f to your computer and use it in GitHub Desktop.
https://github.com/theos/theos/blob/kabiroberai%2Fswift-driver/bin/generate-output-file-map.swift but python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➤ python json_output.py -d xxx -t T1000 -o - file1.swift file2.swift | |
{"file1.swift": {"object": "xxx/file1.swift.T1000.o", "dependencies": "xxx/file1.swift.T1000.Td"}, "file2.swift": {"object": "xxx/file2.swift.T1000.o", "dependencies": "xxx/file2.swift.T1000.Td"}, "": {"swift-dependencies": "xxx/master.swiftdeps"}}⏎ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from argparse import ArgumentParser | |
from argparse import Namespace | |
from sys import stdout | |
from typing import Dict | |
from typing import List | |
def generate_json(directory: str, tag: str, files: List[str]) -> Dict[str, Dict[str, str]]: | |
mapping = { | |
file_name: {"object": f"{directory}/{file_name}.{tag}.o", "dependencies": f"{directory}/{file_name}.{tag}.Td"} | |
for file_name in files | |
} | |
mapping[""] = {"swift-dependencies": f"{directory}/master.swiftdeps"} | |
return mapping | |
def print_json_to_file(mapping: Dict[str, Dict[str, str]], output: str) -> None: | |
if output == "-": | |
json.dump(mapping, fp=stdout) | |
else: | |
with open(output, "w") as file: | |
json.dump(mapping, fp=file) | |
def main(arguments: Namespace) -> None: | |
mapping = generate_json(directory=arguments.directory, tag=arguments.tag, files=arguments.file) | |
print_json_to_file(mapping, output=arguments.output) | |
if __name__ == "__main__": | |
arg_parser = ArgumentParser(description="Logos cli") | |
arg_parser.add_argument("-d", "--directory", required=True, help="Source directory") | |
arg_parser.add_argument("-t", "--tag", required=True, help="File tag") | |
arg_parser.add_argument("-o", "--output", default="-", help="Output file") | |
arg_parser.add_argument("file", nargs="+", help="Input files") | |
main(arg_parser.parse_args()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➤ python json_output.py -h | |
usage: json_output.py [-h] -d DIRECTORY -t TAG [-o OUTPUT] file [file ...] | |
Logos cli | |
positional arguments: | |
file Input files | |
optional arguments: | |
-h, --help show this help message and exit | |
-d DIRECTORY, --directory DIRECTORY | |
Source directory | |
-t TAG, --tag TAG File tag | |
-o OUTPUT, --output OUTPUT | |
Output file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment