|
21 | 21 | EnableThunderscopeOption, |
22 | 22 | EnableVisualizerOption, |
23 | 23 | StopAIOnStartOption, |
| 24 | + SearchQueryArgument, |
| 25 | + TestSuiteOption, |
24 | 26 | DebugBinary, |
25 | 27 | JobsOption, |
26 | 28 | ) |
|
37 | 39 | app = Typer() |
38 | 40 |
|
39 | 41 |
|
40 | | -@app.command( |
41 | | - context_settings={"allow_extra_args": True, "ignore_unknown_options": True}, |
42 | | - no_args_is_help=True, |
43 | | -) |
44 | | -def main( |
45 | | - ctx: Context, |
| 42 | +def fuzzy_find_target( |
46 | 43 | action: ActionArgument, |
47 | | - search_query: str, |
48 | | - print_command: PrintCommandOption = False, |
49 | | - no_optimized_build: NoOptimizedBuildOption = False, |
50 | | - debug_build: DebugBuildOption = False, |
51 | | - select_debug_binaries: SelectDebugBinariesOption = None, |
52 | | - flash_robots: FlashRobotsOption = None, |
53 | | - ssh_password: SSHPasswordOption = None, |
54 | | - interactive_search: InteractiveModeOption = False, |
55 | | - tracy: TracyOption = False, |
56 | | - enable_thunderscope: EnableThunderscopeOption = False, |
57 | | - enable_visualizer: EnableVisualizerOption = False, |
58 | | - stop_ai_on_start: StopAIOnStartOption = False, |
59 | | - jobs_option: JobsOption = None, |
60 | | -) -> None: |
61 | | - if bool(flash_robots) ^ bool(ssh_password): |
62 | | - print( |
63 | | - "If you want to flash robots, both the robot IDs and password must be provided" |
64 | | - ) |
65 | | - sys.exit(1) |
66 | | - |
| 44 | + search_query: SearchQueryArgument, |
| 45 | + interactive_search: InteractiveModeOption, |
| 46 | +) -> str: |
67 | 47 | test_query = ["bazel", "query", "tests(//...)"] |
68 | 48 | binary_query = ["bazel", "query", "kind(.*_binary,//...)"] |
69 | 49 | library_query = ["bazel", "query", "kind(.*_library,//...)"] |
@@ -109,7 +89,53 @@ def main( |
109 | 89 | target = str(iterfzf.iterfzf(iter(targets)), encoding="utf-8") |
110 | 90 | print("User selected {}".format(target)) |
111 | 91 |
|
112 | | - command = ["bazel", action.value, target] |
| 92 | + return target |
| 93 | + |
| 94 | + |
| 95 | +@app.command( |
| 96 | + context_settings={"allow_extra_args": True, "ignore_unknown_options": True}, |
| 97 | + no_args_is_help=True, |
| 98 | +) |
| 99 | +def main( |
| 100 | + ctx: Context, |
| 101 | + action: ActionArgument, |
| 102 | + search_query: SearchQueryArgument = None, |
| 103 | + print_command: PrintCommandOption = False, |
| 104 | + no_optimized_build: NoOptimizedBuildOption = False, |
| 105 | + debug_build: DebugBuildOption = False, |
| 106 | + select_debug_binaries: SelectDebugBinariesOption = None, |
| 107 | + flash_robots: FlashRobotsOption = None, |
| 108 | + ssh_password: SSHPasswordOption = None, |
| 109 | + interactive_search: InteractiveModeOption = False, |
| 110 | + tracy: TracyOption = False, |
| 111 | + enable_thunderscope: EnableThunderscopeOption = False, |
| 112 | + enable_visualizer: EnableVisualizerOption = False, |
| 113 | + stop_ai_on_start: StopAIOnStartOption = False, |
| 114 | + test_suite: TestSuiteOption = False, |
| 115 | + jobs_option: JobsOption = "", |
| 116 | +) -> None: |
| 117 | + if bool(flash_robots) ^ bool(ssh_password): |
| 118 | + print( |
| 119 | + "If you want to flash robots, both the robot IDs and password must be provided" |
| 120 | + ) |
| 121 | + sys.exit(1) |
| 122 | + |
| 123 | + if search_query is None and (not test_suite or not action == ActionArgument.test): |
| 124 | + print( |
| 125 | + "You must specify a search query unless you are running the test suite, use ./tbots.py test --suite instead" |
| 126 | + ) |
| 127 | + sys.exit(1) |
| 128 | + |
| 129 | + if test_suite and action == ActionArgument.test: |
| 130 | + target = """-- //... \\ |
| 131 | + -//software/field_tests/... \\ |
| 132 | + -//toolchains/cc/... \\ |
| 133 | + -//software:unix_full_system_tar_gen""" |
| 134 | + print("Running software and simulated gameplay test suite") |
| 135 | + else: |
| 136 | + target = fuzzy_find_target(action, search_query, interactive_search) |
| 137 | + |
| 138 | + command = ["bazel", action.value] |
113 | 139 | unknown_args = ctx.args |
114 | 140 |
|
115 | 141 | # Trigger a debug build |
@@ -151,6 +177,8 @@ def main( |
151 | 177 | if action == ActionArgument.run: |
152 | 178 | command += ["--"] |
153 | 179 |
|
| 180 | + command.append(target) |
| 181 | + |
154 | 182 | bazel_arguments = unknown_args |
155 | 183 | if stop_ai_on_start: |
156 | 184 | bazel_arguments += ["--stop_ai_on_start"] |
|
0 commit comments