File: gen_sarif.sh

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (51 lines) | stat: -rwxr-xr-x 1,685 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Run this script inside its folder to generate the SARIF python object model files
# from the SARIF schema.
# e.g. ./gen_sarif.sh
#
# This script requires the jschema_to_python package to be installed.
# To install it, run:
#   pip install jschema_to_python

set -e -x
ROOT="${PWD}/../../.."
SARIF_DIR="torch/onnx/_internal/diagnostics/infra/sarif"

# SARIF version
SARIF_VERSION="2.1.0"
SARIF_SCHEMA_LINK="https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/schemas/sarif-schema-2.1.0.json"

# Download SARIF schema
tmp_dir="$(mktemp -d)"
sarif_schema_file_path="${tmp_dir}/sarif-schema-${SARIF_VERSION}.json"
curl -L -o "$sarif_schema_file_path" "$SARIF_SCHEMA_LINK"

# TODO: A private branch of jschema_to_python was used to enable
#       the generation to dataclasses and support annotation.
python -m jschema_to_python \
    --schema-path "$sarif_schema_file_path" \
    --module-name torch.onnx._internal.diagnostics.infra.sarif \
    --output-directory "${ROOT}/${SARIF_DIR}" \
    --root-class-name SarifLog \
    --hints-file-path code-gen-hints.json \
    --force \
    --library dataclasses \
    -vv

# Generate SARIF version file
echo "from typing import Final" > "${ROOT}/${SARIF_DIR}/version.py"
echo "SARIF_VERSION: Final = \"${SARIF_VERSION}\"" >> "${ROOT}/${SARIF_DIR}/version.py"
echo "SARIF_SCHEMA_LINK: Final = \"${SARIF_SCHEMA_LINK}\"" >> "${ROOT}/${SARIF_DIR}/version.py"

pushd "$ROOT"
(
    # Hack to have flake8 not complain about generated code.
    set +x
    while IFS= read -r -d '' file; do
        echo "# flake8: noqa" >> "$file"
    done < <(find "$SARIF_DIR" -name '*.py' -print0)
    set -x

    lintrunner "${SARIF_DIR}/"** -a
)
popd