diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d66b67103..39b97529f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -112,10 +112,27 @@ jobs: distribution: 'oracle' java-version: '23' + - name: Install C# compiler + if: ${{ matrix.language == 'c#' }} + run: sudo apt-get update && sudo apt-get install -y mono-mcs + - name: Remove ignored paths if: ${{ github.event_name == 'pull_request' }} run: rm -f ${{ matrix.paths-ignore }} + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Run Poetry Image + uses: abatilo/actions-poetry@v3 + with: + poetry-version: "1.8.5" + + - name: Install Dependencies + run: poetry install + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 @@ -138,7 +155,7 @@ jobs: - name: Manual build if: ${{ matrix.build-mode == 'manual' }} - run: python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }} + run: poetry run python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }} - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/scripts/build_codeql_language.py b/scripts/build_codeql_language.py index f960b316c..6b1fb4559 100644 --- a/scripts/build_codeql_language.py +++ b/scripts/build_codeql_language.py @@ -1,7 +1,27 @@ import argparse +import shlex import subprocess +from dataclasses import dataclass from pathlib import Path -from typing import Callable, Dict, List +from typing import Dict, List + +from glotter.source import Source + +TEST_INFO_DIR: Dict[str, str] = { + "c": "c", + "cpp": "c-plus-plus", + "c#": "c-sharp", + "java": "java", + "kotlin": "kotlin", + "swift": "swift", +} + + +@dataclass +class TestInfoStruct: + path: Path + language: str + test_info_str: str def main(): @@ -9,46 +29,30 @@ def main(): parser.add_argument("language", help="language to build") parser.add_argument("files_changed", nargs="*", help="files that have changed") parsed_args = parser.parse_args() - command_func = COMMANDS[parsed_args.language] + testinfo_struct = get_test_info_struct(parsed_args.language) for changed_file in parsed_args.files_changed: path = Path(changed_file) print(f"Building {path}") - command = command_func(path) + command = get_build_command(testinfo_struct, path) subprocess.run(command, cwd=path.parent, check=True) -def build_c(path: Path) -> List[str]: - return ["gcc", "-o", path.stem, path.name, "-lm"] - - -def build_cpp(path: Path) -> List[str]: - return ["g++", "-o", path.stem, path.name] - +def get_test_info_struct(language: str) -> TestInfoStruct: + path = Path("archive") / language[0] / TEST_INFO_DIR[language] / "testinfo.yml" + testinfo_str = path.read_text(encoding="utf-8") + return TestInfoStruct(path=path, language=language, test_info_str=testinfo_str) -def build_c_sharp(path: Path) -> List[str]: - return ["mcs", "-reference:System.Numerics", path.name] +def get_build_command(testinfo_struct: TestInfoStruct, path: Path) -> List[str]: + source = Source( + name=path.name, + language=testinfo_struct.language, + path=str(path), + test_info_string=testinfo_struct.test_info_str, + ) + build: str = source.test_info.container_info.build + return shlex.split(build) -def build_java(path: Path) -> List[str]: - return ["javac", path.name] - - -def build_kotlin(path: Path) -> List[str]: - return ["kotlinc", path.name, "-include-runtime", "-d", f"{path.stem}.jar"] - - -def build_swift(path: Path) -> List[str]: - return ["swiftc", "-o", path.stem, path.name] - - -COMMANDS: Dict[str, Callable[[Path], List[str]]] = { - "c": build_c, - "cpp": build_cpp, - "c#": build_c_sharp, - "java": build_java, - "kotlin": build_kotlin, - "swift": build_swift, -} if __name__ == "__main__": main() diff --git a/scripts/get_codeql_languages.py b/scripts/get_codeql_languages.py index 97dbc9c2e..4ee5f17d1 100644 --- a/scripts/get_codeql_languages.py +++ b/scripts/get_codeql_languages.py @@ -8,6 +8,7 @@ LINUX = "ubuntu-latest" MACOS = "macos-latest" +WINDOWS = "windows-latest" @dataclass(frozen=True)