Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: third_party/lit/lit/ShCommands.py

Issue 1663053003: [fusl] Add llvm's lit tool to third_party (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: move down a dir Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/lit/lit/ProgressBar.py ('k') | third_party/lit/lit/ShUtil.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/lit/lit/ShCommands.py
diff --git a/third_party/lit/lit/ShCommands.py b/third_party/lit/lit/ShCommands.py
new file mode 100644
index 0000000000000000000000000000000000000000..9ca9e8c91c0d404174c8aae1c468defe1691d352
--- /dev/null
+++ b/third_party/lit/lit/ShCommands.py
@@ -0,0 +1,85 @@
+class Command:
+ def __init__(self, args, redirects):
+ self.args = list(args)
+ self.redirects = list(redirects)
+
+ def __repr__(self):
+ return 'Command(%r, %r)' % (self.args, self.redirects)
+
+ def __eq__(self, other):
+ if not isinstance(other, Command):
+ return False
+
+ return ((self.args, self.redirects) ==
+ (other.args, other.redirects))
+
+ def toShell(self, file):
+ for arg in self.args:
+ if "'" not in arg:
+ quoted = "'%s'" % arg
+ elif '"' not in arg and '$' not in arg:
+ quoted = '"%s"' % arg
+ else:
+ raise NotImplementedError('Unable to quote %r' % arg)
+ file.write(quoted)
+
+ # For debugging / validation.
+ import ShUtil
+ dequoted = list(ShUtil.ShLexer(quoted).lex())
+ if dequoted != [arg]:
+ raise NotImplementedError('Unable to quote %r' % arg)
+
+ for r in self.redirects:
+ if len(r[0]) == 1:
+ file.write("%s '%s'" % (r[0][0], r[1]))
+ else:
+ file.write("%s%s '%s'" % (r[0][1], r[0][0], r[1]))
+
+class Pipeline:
+ def __init__(self, commands, negate=False, pipe_err=False):
+ self.commands = commands
+ self.negate = negate
+ self.pipe_err = pipe_err
+
+ def __repr__(self):
+ return 'Pipeline(%r, %r, %r)' % (self.commands, self.negate,
+ self.pipe_err)
+
+ def __eq__(self, other):
+ if not isinstance(other, Pipeline):
+ return False
+
+ return ((self.commands, self.negate, self.pipe_err) ==
+ (other.commands, other.negate, self.pipe_err))
+
+ def toShell(self, file, pipefail=False):
+ if pipefail != self.pipe_err:
+ raise ValueError('Inconsistent "pipefail" attribute!')
+ if self.negate:
+ file.write('! ')
+ for cmd in self.commands:
+ cmd.toShell(file)
+ if cmd is not self.commands[-1]:
+ file.write('|\n ')
+
+class Seq:
+ def __init__(self, lhs, op, rhs):
+ assert op in (';', '&', '||', '&&')
+ self.op = op
+ self.lhs = lhs
+ self.rhs = rhs
+
+ def __repr__(self):
+ return 'Seq(%r, %r, %r)' % (self.lhs, self.op, self.rhs)
+
+ def __eq__(self, other):
+ if not isinstance(other, Seq):
+ return False
+
+ return ((self.lhs, self.op, self.rhs) ==
+ (other.lhs, other.op, other.rhs))
+
+ def toShell(self, file, pipefail=False):
+ self.lhs.toShell(file, pipefail)
+ file.write(' %s\n' % self.op)
+ self.rhs.toShell(file, pipefail)
« no previous file with comments | « third_party/lit/lit/ProgressBar.py ('k') | third_party/lit/lit/ShUtil.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698