blob: 86c7c1811a6c28794d75bed9e8bfac637abb1e92 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001#! /usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
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 Bishop15ae2502019-06-18 21:44:24 -040031import sys, os, argparse
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032
33
Brad Bishop15ae2502019-06-18 21:44:24 -040034this_binary = sys.argv[0].split("/")[-1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
36# To be outputted if functionality that hasn't been stubbed yet is invoked.
37stub_msg = """
Brad Bishop15ae2502019-06-18 21:44:24 -040038This stand-in version of %s is not yet fully capable of emulating
39the real version from the GNU texinfo suite. If you see this message, file a
40bug report with details on the recipe that failed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041""" % 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 Bishop15ae2502019-06-18 21:44:24 -040046version_str = """%s (fake texinfo, emulating GNU texinfo) 5.2
47
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048Super amazing version which is totally not fake in any way whatsoever.
49Copyright (C) 2014 Intel Corp. Distributed under the terms of the MIT
50license.
51""" % this_binary
52
53simple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \
54 txixml2texi install-info ginstall-info \
Brad Bishop15ae2502019-06-18 21:44:24 -040055 update-info-dir".split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056
57# These utilities use a slightly different set of options and flags.
Brad Bishop15ae2502019-06-18 21:44:24 -040058complex_binaries = "makeinfo texi2any".split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059
60valid_binaries = simple_binaries + complex_binaries
61
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062assert this_binary in valid_binaries, \
Brad Bishop15ae2502019-06-18 21:44:24 -040063 this_binary + " is not one of " + ', '.join(valid_binaries)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064
65# For debugging
66log_interceptions = False
67if log_interceptions:
Brad Bishop15ae2502019-06-18 21:44:24 -040068 with open("/tmp/intercepted_" + this_binary, "a") as f:
69 f.write(' '.join([this_binary] + sys.argv[1:]) + '\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
71# Look through the options and flags, and if necessary, touch any output
72# files.
Brad Bishop15ae2502019-06-18 21:44:24 -040073p = argparse.ArgumentParser()
74if this_binary in complex_binaries:
75 p.add_argument('-E', '--macro-expand', metavar='FILE')
76p.add_argument('-o', '--output', metavar='DEST')
77p.add_argument('--version', action='store_true')
78
79args, unknown = p.parse_known_args()
80
81if args.version:
82 print(version_str)
83 sys.exit(0)
84
85# Check for functionality that isn't implemented yet.
86assert 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.
90if args.output:
91 with open(args.output, 'w'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092 pass
Brad Bishop15ae2502019-06-18 21:44:24 -040093 sys.exit(0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094
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.
98assert this_binary in simple_binaries, \
99 "Don't know how to get default output file name from input file!" + \
100 stub_msg