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 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 31 | import sys, os, argparse |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | |
| 33 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 34 | this_binary = sys.argv[0].split("/")[-1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | |
| 36 | # To be outputted if functionality that hasn't been stubbed yet is invoked. |
| 37 | stub_msg = """ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 38 | This stand-in version of %s is not yet fully capable of emulating |
| 39 | the real version from the GNU texinfo suite. If you see this message, file a |
| 40 | bug report with details on the recipe that failed. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | """ % this_binary |
| 42 | |
| 43 | # Autotools setups query the version, so this is actually necessary. Some of |
| 44 | # them (lookin' at you, glibc) actually look for the substring "GNU texinfo," |
| 45 | # so we put that substring in there without actually telling a lie. |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 46 | version_str = """%s (fake texinfo, emulating GNU texinfo) 5.2 |
| 47 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | Super amazing version which is totally not fake in any way whatsoever. |
| 49 | Copyright (C) 2014 Intel Corp. Distributed under the terms of the MIT |
| 50 | license. |
| 51 | """ % this_binary |
| 52 | |
| 53 | simple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \ |
| 54 | txixml2texi install-info ginstall-info \ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 55 | update-info-dir".split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | |
| 57 | # These utilities use a slightly different set of options and flags. |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 58 | complex_binaries = "makeinfo texi2any".split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
| 60 | valid_binaries = simple_binaries + complex_binaries |
| 61 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | assert this_binary in valid_binaries, \ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 63 | this_binary + " is not one of " + ', '.join(valid_binaries) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | |
| 65 | # For debugging |
| 66 | log_interceptions = False |
| 67 | if log_interceptions: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 68 | with open("/tmp/intercepted_" + this_binary, "a") as f: |
| 69 | f.write(' '.join([this_binary] + sys.argv[1:]) + '\n') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
| 71 | # Look through the options and flags, and if necessary, touch any output |
| 72 | # files. |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 73 | p = argparse.ArgumentParser() |
| 74 | if this_binary in complex_binaries: |
| 75 | p.add_argument('-E', '--macro-expand', metavar='FILE') |
| 76 | p.add_argument('-o', '--output', metavar='DEST') |
| 77 | p.add_argument('--version', action='store_true') |
| 78 | |
| 79 | args, unknown = p.parse_known_args() |
| 80 | |
| 81 | if args.version: |
| 82 | print(version_str) |
| 83 | sys.exit(0) |
| 84 | |
| 85 | # Check for functionality that isn't implemented yet. |
| 86 | assert not getattr(args, 'macro_expand', None), \ |
| 87 | "-E/--macro-expand option not yet supported" + stub_msg |
| 88 | |
| 89 | # Check if -o or --output is specified. |
| 90 | if args.output: |
| 91 | with open(args.output, 'w'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | pass |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 93 | sys.exit(0) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | |
| 95 | # The -o/--output option overrides the default. For makeinfo and texi2any, |
| 96 | # that default is to look for a @setfilename command in the input file. |
| 97 | # Otherwise, printing nothing to stdout and then exiting should suffice. |
| 98 | assert this_binary in simple_binaries, \ |
| 99 | "Don't know how to get default output file name from input file!" + \ |
| 100 | stub_msg |