File: library-modules-verifier.py

package info (click to toggle)
webkit2gtk 2.51.90-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 484,192 kB
  • sloc: cpp: 3,930,945; javascript: 197,713; ansic: 167,619; python: 53,160; asm: 21,857; ruby: 18,114; perl: 17,149; xml: 4,631; sh: 2,462; yacc: 2,394; java: 2,032; lex: 1,358; pascal: 372; makefile: 215
file content (101 lines) | stat: -rwxr-xr-x 2,819 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3

import argparse
from dataclasses import dataclass
import json
import os
import pathlib
import sys
from typing import TypedDict

from GenerateModuleVerifierInputsTask import GenerateModuleVerifierInputsTask
from VerifyModuleTask import VerifyModuleTask


@dataclass
class CommandArguments:
    tapi_filelist: pathlib.Path
    relative_to: pathlib.Path


class FileListHeader(TypedDict):
    path: pathlib.Path
    type: str


class FileList(TypedDict):
    headers: list[FileListHeader]
    version: str


def parse_command_arguments() -> CommandArguments:
    parser = argparse.ArgumentParser(
        prog="library-modules-verifier",
        description="Tests library clang modules in a clean environment.",
    )

    parser.add_argument(
        "tapi_filelist",
        type=pathlib.Path,
        help="A path to a tapi-installapi(1) compatible JSON file list containing the library headers (for example, `path/to/WTF.json`).",
    )

    parser.add_argument(
        "--relative-to",
        required=True,
        type=pathlib.Path,
        help="The destination location of the library (for example, `WebKitBuild/Debug/usr/local/include`)",
    )

    args = parser.parse_args()
    return CommandArguments(args.tapi_filelist, args.relative_to)


if __name__ == "__main__":
    if os.environ.get("ENABLE_WK_LIBRARY_MODULE_VERIFIER") != "YES":
        print(
            "warning: Library module verifier is not enabled. Set `ENABLE_WK_LIBRARY_MODULE_VERIFIER` to `YES` to enable the verifier."
        )
        sys.exit()

    arguments = parse_command_arguments()

    with open(arguments.tapi_filelist, "r") as tapi_filelist:
        filelist_data: FileList = json.load(tapi_filelist)

    headers = [
        os.path.relpath(header["path"], arguments.relative_to)
        for header in filelist_data["headers"]
    ]

    print("Generating inputs for module verifier...")

    input_tasks = GenerateModuleVerifierInputsTask.create_tasks(os.environ)
    if not input_tasks:
        print("warning: No inputs were generated for the verifier.")
        sys.exit()

    for input_task in input_tasks:
        input_task.perform_action(headers)

    print("Generated inputs for module verifier!")

    for input_task in input_tasks:
        verify_task = VerifyModuleTask(
            input_task.target_set, input_task.inputs, os.environ
        )
        command = verify_task.create_command()

        print(
            f"Verifying clang module ({verify_task.language.value}, {verify_task.standard.value}, {verify_task.target}) ..."
        )
        print(" ".join(command))

        result = verify_task.perform_action()
        print(result.stderr)

        if result.returncode:
            sys.exit("error: Failed to verify module.")

    print("Verified module!")
    sys.exit()