|  | 
|  | 1 | +from pathlib import PurePath | 
|  | 2 | + | 
|  | 3 | +from configuration.builders.infra.runtime import ( | 
|  | 4 | +    BuildSequence, | 
|  | 5 | +    DockerConfig, | 
|  | 6 | +    InContainer, | 
|  | 7 | +) | 
|  | 8 | +from configuration.builders.sequences.helpers import ( | 
|  | 9 | +    save_infer_logs, | 
|  | 10 | +) | 
|  | 11 | +from configuration.steps.base import StepOptions | 
|  | 12 | +from configuration.steps.commands.compile import CompileCMakeCommand | 
|  | 13 | +from configuration.steps.commands.configure import ConfigureMariaDBCMake | 
|  | 14 | +from configuration.steps.commands.download import GitInitFromCommit, GitFetch | 
|  | 15 | +from configuration.steps.commands.util import InferScript, PrintEnvironmentDetails | 
|  | 16 | +from configuration.steps.generators.cmake.compilers import ClangCompiler | 
|  | 17 | +from configuration.steps.generators.cmake.generator import CMakeGenerator | 
|  | 18 | +from configuration.steps.generators.cmake.options import ( | 
|  | 19 | +    CMAKE, | 
|  | 20 | +    WITH, | 
|  | 21 | +    BuildType, | 
|  | 22 | +    CMakeOption, | 
|  | 23 | +) | 
|  | 24 | +from configuration.steps.remote import ShellStep | 
|  | 25 | + | 
|  | 26 | + | 
|  | 27 | +def infer( | 
|  | 28 | +    config: DockerConfig, | 
|  | 29 | +    jobs: int, | 
|  | 30 | +): | 
|  | 31 | +    sequence = BuildSequence() | 
|  | 32 | + | 
|  | 33 | +    sequence.add_step(ShellStep(command=PrintEnvironmentDetails())) | 
|  | 34 | +    # infer --version | 
|  | 35 | + | 
|  | 36 | +    sequence.add_step( | 
|  | 37 | +        InContainer( | 
|  | 38 | +            docker_environment=config, | 
|  | 39 | +            step=ShellStep( | 
|  | 40 | +                command=BashCommand( | 
|  | 41 | +                    command="git clean -df", workdir=PurePath("/mnt", "src") | 
|  | 42 | +                ), | 
|  | 43 | +                options=StepOptions( | 
|  | 44 | +                    haltOnFailure=False, | 
|  | 45 | +                    descriptionDone="git cleaned", | 
|  | 46 | +                ), | 
|  | 47 | +            ), | 
|  | 48 | +        ) | 
|  | 49 | +    ) | 
|  | 50 | + | 
|  | 51 | +    sequence.add_step( | 
|  | 52 | +        InContainer( | 
|  | 53 | +            ShellStep( | 
|  | 54 | +                command=GitInitFromCommit( | 
|  | 55 | +                    repo_url="%(prop:repository)s", | 
|  | 56 | +                    commit="%(prop:revision)s", | 
|  | 57 | +                    jobs=jobs, | 
|  | 58 | +                    depth=0, | 
|  | 59 | +                    workdir=PurePath("/mnt", "src"), | 
|  | 60 | +                ) | 
|  | 61 | +            ), | 
|  | 62 | +            docker_environment=config, | 
|  | 63 | +        ), | 
|  | 64 | +    ) | 
|  | 65 | + | 
|  | 66 | +    sequence.add_step( | 
|  | 67 | +        InContainer( | 
|  | 68 | +            docker_environment=config, | 
|  | 69 | +            step=ShellStep( | 
|  | 70 | +                command=BashCommand( | 
|  | 71 | +                    command="git diff --name-only FETCH_HEAD..%(prop:master_branch)s | tee $OLD_PWD/index.txt", workdir=PurePath("/mnt", "src") | 
|  | 72 | +                ), | 
|  | 73 | +                options=StepOptions( | 
|  | 74 | +                    haltOnFailure=False, | 
|  | 75 | +                    descriptionDone="names of changed files", | 
|  | 76 | +                ), | 
|  | 77 | +            ), | 
|  | 78 | +        ) | 
|  | 79 | +    ) | 
|  | 80 | + | 
|  | 81 | +    flags = [ | 
|  | 82 | +        # UBSAN is the only prevention of UNINIT_VAR(X) x= x | 
|  | 83 | +        # that generated lots of uninit read/write errors. | 
|  | 84 | +        CMakeOption(WITH.UBSAN, True), | 
|  | 85 | +        CMakeOption(CMAKE.EXPORT_COMPILE_COMMANDS, True), | 
|  | 86 | +    ] | 
|  | 87 | + | 
|  | 88 | +    sequence.add_step( | 
|  | 89 | +        InContainer( | 
|  | 90 | +            docker_environment=config, | 
|  | 91 | +            step=ShellStep( | 
|  | 92 | +                command=ConfigureMariaDBCMake( | 
|  | 93 | +                    name="configure", | 
|  | 94 | +                    cmake_generator=CMakeGenerator( | 
|  | 95 | +                        use_ccache=True, | 
|  | 96 | +                        flags=flags, | 
|  | 97 | +                        source_path="/mnt/src", | 
|  | 98 | +                        builddir="bld", | 
|  | 99 | +                        compiler=ClangCompiler(), | 
|  | 100 | +                    ), | 
|  | 101 | +                ), | 
|  | 102 | +                options=StepOptions(descriptionDone="Configure"), | 
|  | 103 | +            ), | 
|  | 104 | +        ) | 
|  | 105 | +    ) | 
|  | 106 | + | 
|  | 107 | +    # Some server code is generated, so these need to be generated to test | 
|  | 108 | +    sequence.add_step( | 
|  | 109 | +        InContainer( | 
|  | 110 | +            docker_environment=config, | 
|  | 111 | +            step=ShellStep( | 
|  | 112 | +                command=CompileCMakeCommand( | 
|  | 113 | +                    builddir="bld", | 
|  | 114 | +                    jobs=jobs, | 
|  | 115 | +                    verbose=True, | 
|  | 116 | +                    targets=[ | 
|  | 117 | +                        "GenError", | 
|  | 118 | +                        "GenServerSource", | 
|  | 119 | +                        "GenUnicodeDataSource", | 
|  | 120 | +                        "GenFixPrivs", | 
|  | 121 | +                    ], | 
|  | 122 | +                ), | 
|  | 123 | +                options=StepOptions(descriptionDone="compile"), | 
|  | 124 | +            ), | 
|  | 125 | +        ) | 
|  | 126 | +    ) | 
|  | 127 | + | 
|  | 128 | +    env_vars = [ | 
|  | 129 | +        ( | 
|  | 130 | +            "JOBS", | 
|  | 131 | +            str(jobs) | 
|  | 132 | +        ) | 
|  | 133 | +    ] | 
|  | 134 | +    sequence.add_step( | 
|  | 135 | +        InContainer( | 
|  | 136 | +            docker_environment=config, | 
|  | 137 | +            step=ShellStep( | 
|  | 138 | +                command=InferScript(), | 
|  | 139 | +                command=BashScript("infer.sh", args=["%(prop:ldnum)s"]), | 
|  | 140 | +                options=StepOptions( | 
|  | 141 | +                    descriptionDone="infer analysis complete", | 
|  | 142 | +                ), | 
|  | 143 | +                env_vars=env_vars, | 
|  | 144 | +            ), | 
|  | 145 | +        ) | 
|  | 146 | +    ) | 
|  | 147 | + | 
|  | 148 | +    sequence.add_step( | 
|  | 149 | +        save_infer_logs( | 
|  | 150 | +            step_wrapping_fn=lambda step: InContainer( | 
|  | 151 | +                docker_environment=config, step=step | 
|  | 152 | +            ), | 
|  | 153 | +        ) | 
|  | 154 | +    ) | 
|  | 155 | +    return sequence | 
0 commit comments