Last active
December 11, 2015 15:57
-
-
Save primiano/ee8d525df2332090cc61 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import os | |
import re | |
import sys | |
def main(): | |
for root, _, files in os.walk(sys.argv[1]): | |
for file_name in files: | |
if file_name.endswith('.ninja'): | |
sortFile(os.path.join(root, file_name)) | |
def sortFile(path): | |
lines = open(path).readlines() | |
targets = {} | |
out = '' | |
for line in lines: | |
if not line.startswith('build '): | |
out += line | |
continue | |
(cmd, deps) = line.split(':', 1) | |
cmd_deps = '' | |
for dep in sorted(deps.split()): | |
cmd_deps += ' ' + dep + '\n' | |
targets[cmd] = cmd_deps | |
for (cmd, deps) in sorted(targets.iteritems()): | |
out += cmd + ':\n' + deps + '\n' | |
with open(path + '.new', 'w') as ofile: | |
ofile.write(out) | |
os.rename(path + '.new', path) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment