OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (C) 2009 Google Inc. All rights reserved. | 3 # Copyright (C) 2009 Google Inc. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 14 matching lines...) Expand all Loading... |
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 # | 30 # |
31 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 31 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
32 # Use of this source code is governed by a BSD-style license that can be | 32 # Use of this source code is governed by a BSD-style license that can be |
33 # found in the LICENSE file. | 33 # found in the LICENSE file. |
34 | 34 |
35 # usage: rule_bison.py INPUT_FILE OUTPUT_DIR [BISON_EXE] | 35 # usage: rule_bison.py INPUT_FILE OUTPUT_DIR BISON_EXE [DEVELOPER_DIR] |
36 # INPUT_FILE is a path to either XPathGrammar.y. | 36 # INPUT_FILE is a path to either XPathGrammar.y. |
37 # OUTPUT_DIR is where the bison-generated .cpp and .h files should be placed. | 37 # OUTPUT_DIR is where the bison-generated .cpp and .h files should be placed. |
38 | 38 |
39 import errno | 39 import errno |
40 import os | 40 import os |
41 import os.path | 41 import os.path |
42 import subprocess | 42 import subprocess |
43 import sys | 43 import sys |
44 | 44 |
45 assert len(sys.argv) == 3 or len(sys.argv) == 4 | 45 assert len(sys.argv) == 4 or len(sys.argv) == 5 |
46 | 46 |
47 inputFile = sys.argv[1] | 47 inputFile = sys.argv[1] |
48 outputDir = sys.argv[2] | 48 outputDir = sys.argv[2] |
49 bisonExe = 'bison' | 49 bisonExe = sys.argv[3] |
50 if len(sys.argv) > 3: | 50 if len(sys.argv) > 4: |
51 bisonExe = sys.argv[3] | 51 os.environ['DEVELOPER_DIR'] = sys.argv[4] |
52 | 52 |
53 pathToBison = os.path.split(bisonExe)[0] | 53 pathToBison = os.path.split(bisonExe)[0] |
54 if pathToBison: | 54 if pathToBison: |
55 # Make sure this path is in the path so that it can find its auxiliary | 55 # Make sure this path is in the path so that it can find its auxiliary |
56 # binaries (in particular, m4). To avoid other 'm4's being found, insert | 56 # binaries (in particular, m4). To avoid other 'm4's being found, insert |
57 # at head, rather than tail. | 57 # at head, rather than tail. |
58 os.environ['PATH'] = pathToBison + os.pathsep + os.environ['PATH'] | 58 os.environ['PATH'] = pathToBison + os.pathsep + os.environ['PATH'] |
59 | 59 |
60 inputName = os.path.basename(inputFile) | 60 inputName = os.path.basename(inputFile) |
61 assert inputName == 'XPathGrammar.y' | 61 assert inputName == 'XPathGrammar.y' |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 # Rewrite the generated header with #include guards. | 104 # Rewrite the generated header with #include guards. |
105 outputH = os.path.join(outputDir, inputRoot + '.h') | 105 outputH = os.path.join(outputDir, inputRoot + '.h') |
106 | 106 |
107 outputHFile = open(outputH, 'w') | 107 outputHFile = open(outputH, 'w') |
108 print >>outputHFile, '#ifndef %sH' % inputRoot | 108 print >>outputHFile, '#ifndef %sH' % inputRoot |
109 print >>outputHFile, '#define %sH' % inputRoot | 109 print >>outputHFile, '#define %sH' % inputRoot |
110 print >>outputHFile, outputHContents | 110 print >>outputHFile, outputHContents |
111 print >>outputHFile, '#endif' | 111 print >>outputHFile, '#endif' |
112 outputHFile.close() | 112 outputHFile.close() |
OLD | NEW |