Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
68 changes: 36 additions & 32 deletions scripts/build_codeql_language.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
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():
parser = argparse.ArgumentParser()
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()
1 change: 1 addition & 0 deletions scripts/get_codeql_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

LINUX = "ubuntu-latest"
MACOS = "macos-latest"
WINDOWS = "windows-latest"


@dataclass(frozen=True)
Expand Down
Loading