| 36 | |
| 37 | |
| 38 | def _check_banned_symbols(src_dir: Path, symbols: Iterable[str]) -> None: |
| 39 | logging.info(f"Checking for banned symbols") |
| 40 | |
| 41 | assert any( |
| 42 | map(lambda x: platform.system() == x, ("Linux", "Darwin", "Windows"))) |
| 43 | |
| 44 | on_windows = platform.system() == "Windows" |
| 45 | |
| 46 | def form_command(search_string: str) -> Tuple[str]: |
| 47 | if on_windows: |
| 48 | # Switch exit codes so that 0 is found and 1 is not-found to match linux code-path. |
| 49 | return ( |
| 50 | "powershell", "-Command", |
| 51 | f"if (Get-ChildItem -Recurse \"{str(src_dir.absolute())}\" | Select-String \"{search_string}\")", |
| 52 | "{ exit 0 }", "else", "{ exit 1 }") |
| 53 | else: |
| 54 | return ('grep', search_string, '-R', str(src_dir.absolute())) |
| 55 | |
| 56 | exceptions = [] |
| 57 | for search_string in symbols: |
| 58 | command = form_command(search_string) |
| 59 | command_log = " ".join(command) |
| 60 | logging.debug(f"Executing {command_log}") |
| 61 | keyword_found = subprocess.run(command).returncode |
| 62 | if keyword_found == 0: |
| 63 | exceptions.append( |
| 64 | RuntimeError( |
| 65 | f"Search string {search_string} found in path {str(src_dir.absolute())}" |
| 66 | )) |
| 67 | |
| 68 | if len(exceptions): |
| 69 | raise Exception(exceptions) |
| 70 | |
| 71 | |
| 72 | def compress(tgt_pkg_name: Path, src_dir: Path) -> None: |