• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# DExTer : Debugging Experience Tester
2# ~~~~~~   ~         ~~         ~   ~~
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7"""Command line options for subtools that use the builder component."""
8
9import os
10
11from dex.tools import Context
12from dex.utils import is_native_windows
13
14
15def _find_build_scripts():
16    """Finds build scripts in the 'scripts' subdirectory.
17
18    Returns:
19        { script_name (str): directory (str) }
20    """
21    try:
22        return _find_build_scripts.cached
23    except AttributeError:
24        scripts_directory = os.path.join(os.path.dirname(__file__), 'scripts')
25        if is_native_windows():
26            scripts_directory = os.path.join(scripts_directory, 'windows')
27        else:
28            scripts_directory = os.path.join(scripts_directory, 'posix')
29        assert os.path.isdir(scripts_directory), scripts_directory
30        results = {}
31
32        for f in os.listdir(scripts_directory):
33            results[os.path.splitext(f)[0]] = os.path.abspath(
34                os.path.join(scripts_directory, f))
35
36        _find_build_scripts.cached = results
37        return results
38
39
40def add_builder_tool_arguments(parser):
41    parser.add_argument('--binary',
42                        metavar="<file>",
43                        help='provide binary file to override --builder')
44
45    parser.add_argument(
46        '--builder',
47        type=str,
48        choices=sorted(_find_build_scripts().keys()),
49        help='test builder to use')
50    parser.add_argument(
51        '--cflags', type=str, default='', help='compiler flags')
52    parser.add_argument('--ldflags', type=str, default='', help='linker flags')
53
54
55def handle_builder_tool_options(context: Context) -> str:
56    return _find_build_scripts()[context.options.builder]
57