• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2#
3# Copyright 2020-2022 The Khronos Group Inc.
4#
5# SPDX-License-Identifier: Apache-2.0
6"""Script to create symbolic links for aliases in reference pages
7   Usage: makemanaliases.py -refdir refpage-output-directory"""
8
9import argparse
10import os
11import sys
12
13if __name__ == '__main__':
14    parser = argparse.ArgumentParser()
15
16    parser.add_argument('-genpath', action='store',
17                        default=None,
18                        help='Path to directory containing generated apimap.py module')
19    parser.add_argument('-refdir', action='store',
20                        required=True,
21                        help='Path to directory containing reference pages to symlink')
22
23    args = parser.parse_args()
24
25    # Look for apimap.py in the specified directory
26    if args.genpath is not None:
27        sys.path.insert(0, args.genpath)
28    import apimap as api
29
30    # Change to refpage directory
31    try:
32        os.chdir(args.refdir)
33    except:
34        print('Cannot chdir to', args.refdir, file=sys.stderr)
35        sys.exit(1)
36
37    # For each alias in the API alias map, create a symlink if it
38    # does not exist - and warn if it does exist.
39
40    for key in api.alias:
41        if key.endswith(('_EXTENSION_NAME', '_SPEC_VERSION')):
42            # No reference pages are generated for these meta-tokens, so
43            # attempts to alias them will fail. Silently skip them.
44            continue
45
46        alias = key + '.html'
47        src = api.alias[key] + '.html'
48
49        if not os.access(src, os.R_OK):
50            # This should not happen, but is possible if the api module is
51            # not generated for the same set of APIs as were the refpages.
52            print('No source file', src, file=sys.stderr)
53            continue
54
55        if os.access(alias, os.R_OK):
56            # If the link already exists, that is not necessarily a
57            # problem, so do not fail, but it should be checked out.
58            # The usual case for this is not cleaning the target directory
59            # prior to generating refpages.
60            print('Unexpected alias file "' + alias + '" exists, skipping',
61                  file=sys.stderr)
62        else:
63            # Create link from alias refpage to page for what it is aliasing
64            os.symlink(src, alias)
65