Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | # template.py (and other filenames) |
| 4 | # By Max Eliaser (max.eliaser@intel.com) |
| 5 | |
| 6 | # Copyright (c) 2014 Intel Corp. |
| 7 | |
| 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | # of this software and associated documentation files (the "Software"), to deal |
| 10 | # in the Software without restriction, including without limitation the rights |
| 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | # copies of the Software, and to permit persons to whom the Software is |
| 13 | # furnished to do so, subject to the following conditions: |
| 14 | |
| 15 | # The above copyright notice and this permission notice shall be included in |
| 16 | # all copies or substantial portions of the Software. |
| 17 | |
| 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | # THE SOFTWARE. |
| 25 | |
| 26 | # This program acts like a dummy version of the texinfo utilities, creating |
| 27 | # the right output files but leaving them blank. It will parse out the name |
| 28 | # of the executable from argv[0] and emulate the corresponding program, so |
| 29 | # multiple copies of this script will exist under different names. |
| 30 | |
| 31 | import sys, os |
| 32 | |
| 33 | olong = "--output=" |
| 34 | Elong = "--macro-expand=" |
| 35 | |
| 36 | |
| 37 | this_binary = sys.argv[0].split ("/")[-1] |
| 38 | |
| 39 | # To be outputted if functionality that hasn't been stubbed yet is invoked. |
| 40 | stub_msg = """ |
| 41 | This stand-in version of %s is not yet fully capable of emulating the real |
| 42 | version from the GNU texinfo suite. If you see this message, file a bug report |
| 43 | with details on the recipe that failed. |
| 44 | """ % this_binary |
| 45 | |
| 46 | # Autotools setups query the version, so this is actually necessary. Some of |
| 47 | # them (lookin' at you, glibc) actually look for the substring "GNU texinfo," |
| 48 | # so we put that substring in there without actually telling a lie. |
| 49 | version_str = """ %s (fake texinfo, emulating GNU texinfo) 5.2 |
| 50 | |
| 51 | Super amazing version which is totally not fake in any way whatsoever. |
| 52 | Copyright (C) 2014 Intel Corp. Distributed under the terms of the MIT |
| 53 | license. |
| 54 | """ % this_binary |
| 55 | |
| 56 | simple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \ |
| 57 | txixml2texi install-info ginstall-info \ |
| 58 | update-info-dir".split () |
| 59 | |
| 60 | # These utilities use a slightly different set of options and flags. |
| 61 | complex_binaries = "makeinfo texi2any".split () |
| 62 | |
| 63 | valid_binaries = simple_binaries + complex_binaries |
| 64 | |
| 65 | # For generating blank output files. |
| 66 | def touch_file (path): |
| 67 | f = open (path, "w") |
| 68 | f.close () |
| 69 | |
| 70 | assert this_binary in valid_binaries, \ |
| 71 | this_binary + " is not one of " + ', '.join (valid_binaries) |
| 72 | |
| 73 | if "--version" in sys.argv: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 74 | print(version_str) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | sys.exit (0) |
| 76 | |
| 77 | # For debugging |
| 78 | log_interceptions = False |
| 79 | if log_interceptions: |
| 80 | f = open ("/tmp/intercepted_" + this_binary, "a") |
| 81 | f.write (' '.join ([this_binary] + sys.argv[1:]) + '\n') |
| 82 | f.close () |
| 83 | |
| 84 | # Look through the options and flags, and if necessary, touch any output |
| 85 | # files. |
| 86 | arg_idx = 1 |
| 87 | while arg_idx < len (sys.argv): |
| 88 | arg = sys.argv [arg_idx] |
| 89 | |
| 90 | if arg == "--": |
| 91 | break |
| 92 | |
| 93 | # Something like -I . can result in a need for this (specifically the .) |
| 94 | elif len (arg) < 2: |
| 95 | pass |
| 96 | |
| 97 | # Check if -o or --output is specified. These can be used at most once. |
| 98 | elif arg[0] == '-' and arg[1] != '-' and arg[len (arg) - 1] == 'o': |
| 99 | touch_file (sys.argv[arg_idx + 1]) |
| 100 | sys.exit (0) |
| 101 | elif arg.startswith (olong): |
| 102 | touch_file (arg.split ("=")[1]) |
| 103 | sys.exit (0) |
| 104 | |
| 105 | # Check for functionality that isn't implemented yet. |
| 106 | else: |
| 107 | assert arg[0] != '-' or arg[1] == '-' or 'E' not in arg or \ |
| 108 | this_binary in simple_binaries, \ |
| 109 | "-E option not yet supported" + stub_msg |
| 110 | |
| 111 | assert not arg.startswith (Elong), \ |
| 112 | Elong[:-1] + " option not yet supported" + stub_msg |
| 113 | |
| 114 | arg_idx += 1 |
| 115 | |
| 116 | # The -o/--output option overrides the default. For makeinfo and texi2any, |
| 117 | # that default is to look for a @setfilename command in the input file. |
| 118 | # Otherwise, printing nothing to stdout and then exiting should suffice. |
| 119 | assert this_binary in simple_binaries, \ |
| 120 | "Don't know how to get default output file name from input file!" + \ |
| 121 | stub_msg |
| 122 | |