Index: pydir/buildatts.py |
diff --git a/pydir/buildatts.py b/pydir/buildatts.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..c210dbffb0e72ac2e46f1c9034b6e690bc8a171d |
--- /dev/null |
+++ b/pydir/buildatts.py |
@@ -0,0 +1,60 @@ |
+#!/usr/bin/env python2 |
+ |
+import argparse |
+import os |
+import sys |
+ |
+from utils import shellcmd |
+ |
+def getBuildAttributes(Filename): |
Jim Stichnoth
2014/10/15 03:16:37
Hmm, I don't know what our name capitalization sty
Karl
2014/10/15 20:12:31
Done.
|
+ Filename += ".build_atts" |
+ if not os.path.isfile(Filename): |
+ return [] |
+ f = open(Filename, 'r') |
Jim Stichnoth
2014/10/15 03:16:37
with open(Filename, 'r') as f:
return f.read().s
Karl
2014/10/15 20:12:32
Done.
|
+ kinds = f.read().split() |
+ f.close() |
+ return kinds |
+ |
+def hasBuildAttributes(Filename, Attributes): |
Jim Stichnoth
2014/10/15 03:16:37
These functions ought to have docstrings.
Karl
2014/10/15 20:12:32
Done.
|
+ BuildAtts = getBuildAttributes(Filename) |
+ for Att in Attributes: |
Jim Stichnoth
2014/10/15 03:16:36
return set(Attributes) <= set(BuildAtts)
Karl
2014/10/15 20:12:32
Done.
|
+ if Att not in BuildAtts: |
+ return False |
+ return True |
+ |
+def main(): |
+ """Run check on corresponding ice executable .kind file to see if |
Jim Stichnoth
2014/10/15 03:16:37
What is a .kind file?
llvm2ice executable?
Karl
2014/10/15 20:12:31
Simplified python script to just be checking if a
|
+ 'minimal' is specified. If so, quits and completes with success. |
+ Otherwise, runs shell command on remainder of line. |
+ """ |
+ argparser = argparse.ArgumentParser( |
+ description=' ' + main.__doc__, |
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
+ argparser.add_argument( |
+ '--llvm2ice', required=False, default='./llvm2ice', metavar='LLVM2ICE', |
+ help="Subzero translator 'llvm2ice'") |
+ argparser.add_argument('--att', required=False, default=[], |
+ action='append', |
+ help='Look for executable build attributes') |
+ argparser.add_argument('--echo-cmd', required=False, |
+ action='store_true', |
+ help='Trace command that run in separate shell') |
Jim Stichnoth
2014/10/15 03:16:37
commands
Karl
2014/10/15 20:12:32
Done.
|
+ argparser.add_argument('cmd', nargs=argparse.REMAINDER, |
+ help='Remaining arguments are run in a separate shell') |
+ |
+ args = argparser.parse_args() |
+ |
+ # Quit early if no command to run. |
+ if args.cmd is None: |
Jim Stichnoth
2014/10/15 03:16:37
if not args.cmd:
(would this work?)
Karl
2014/10/15 20:12:32
Done.
|
+ return |
Jim Stichnoth
2014/10/15 03:16:37
Should an explicit zero or nonzero value be return
Karl
2014/10/15 20:12:32
Done.
|
+ |
+ # Quit early if the executable doesn't support expected build attributes. |
+ if not hasBuildAttributes(args.llvm2ice, args.att): |
+ return |
+ |
+ stdout_result = shellcmd(args.cmd, echo=args.echo_cmd) |
+ if not args.echo_cmd: |
+ sys.stdout.write(stdout_result) |
+ |
+if __name__ == '__main__': |
+ main() |