• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2014 the V8 project authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""This program either generates the parser files for Torque, generating
7the source and header files directly in V8's src directory."""
8
9import subprocess
10import sys
11import re
12from subprocess import Popen, PIPE
13
14if len(sys.argv) < 2 or len(sys.argv) > 3:
15  print "invalid number of arguments"
16  sys.exit(-1)
17
18use_stdout = True
19if len(sys.argv) == 3 and sys.argv[1] == '-i':
20  use_stdout = False
21
22filename = sys.argv[len(sys.argv) - 1]
23
24with open(filename, 'r') as content_file:
25  content = content_file.read()
26p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
27output, err = p.communicate(content)
28rc = p.returncode
29if (rc <> 0):
30  sys.exit(rc);
31if use_stdout:
32  print output
33else:
34  output_file = open(filename, 'w')
35  output_file.write(output);
36  output_file.close()
37