<commit_before>// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

def call(body) {
    // evaluate the body block, and collect configuration into the object
    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    // Mandatory configuration
    def dockerfile = config["dockerfile"]
    assert dockerfile : "dockerfile should be specified"
    def gitUrl = config["git"]
    assert gitUrl : "git should be specified"

    // Optional configuration
    def projectName = config["name"] ?: env.JOB_BASE_NAME
    def sanitizers = config["sanitizers"] ?: ["address", "memory"]
    def checkoutDir = config["checkoutDir"] ?: projectName
    def needsOssFuzz = config["needsOssFuzz"] ?: false

    def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(java.time.LocalDateTime.now())

    node {
      echo "Building project $projectName with Dockerfile=$dockerfile"

      for (int i = 0; i < sanitizers.size(); i++) {
        def sanitizer = sanitizers[i]
        def dockerTag = "$projectName-$sanitizer"

        dir(sanitizer) {
          echo "*** Building with $sanitizer sanitizer"

          // See JENKINS-33511
          sh 'pwd > pwd.current'
          def workspace = readFile('pwd.current').trim()
          def out = "$workspace/out"

          if (needsOssFuzz) {
            dir('libfuzzer-bot') {
                git url: 'https://github.com/google/libfuzzer-bot/'
            }

            dir(checkoutDir) {
                git url: gitUrl
            }
          } else {
            git url: gitUrl
          }

          sh "docker build -t libfuzzer/$dockerTag -f $dockerfile ."

          sh "rm -rf $out"
          def zipFile= "$dockerTag-${date}.zip"

          sh "mkdir -p $out"
          sh "docker run -v $workspace:/workspace -v $out:/out -e sanitizer_flags=\"-fsanitize=$sanitizer\" -t libfuzzer/$dockerTag"
          sh "zip -j $zipFile $out/*"
          sh "gsutil cp $zipFile gs://clusterfuzz-builds/$projectName/"
        }
      }
    }

  echo 'Done'
}

return this;
<commit_msg>[infra] updating oss-fuzz location<commit_after>// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

def call(body) {
    // evaluate the body block, and collect configuration into the object
    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    // Mandatory configuration
    def dockerfile = config["dockerfile"]
    assert dockerfile : "dockerfile should be specified"
    def gitUrl = config["git"]
    assert gitUrl : "git should be specified"

    // Optional configuration
    def projectName = config["name"] ?: env.JOB_BASE_NAME
    def sanitizers = config["sanitizers"] ?: ["address", "memory"]
    def checkoutDir = config["checkoutDir"] ?: projectName
    def needsOssFuzz = config["needsOssFuzz"] ?: false

    def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(java.time.LocalDateTime.now())

    node {
      echo "Building project $projectName with Dockerfile=$dockerfile"

      for (int i = 0; i < sanitizers.size(); i++) {
        def sanitizer = sanitizers[i]
        def dockerTag = "$projectName-$sanitizer"

        dir(sanitizer) {
          stage name: "$sanitizer sanitizer"

          // See JENKINS-33511
          sh 'pwd > pwd.current'
          def workspace = readFile('pwd.current').trim()
          def out = "$workspace/out"

          if (needsOssFuzz) {
            dir('oss-fuzz') {
                git url: 'https://github.com/google/oss-fuzz.git'
            }

            dir(checkoutDir) {
                git url: gitUrl
            }
          } else {
            git url: gitUrl
          }

          sh "docker build -t libfuzzer/$dockerTag -f $dockerfile ."

          sh "rm -rf $out"
          def zipFile= "$dockerTag-${date}.zip"

          sh "mkdir -p $out"
          sh "docker run -v $workspace:/workspace -v $out:/out -e sanitizer_flags=\"-fsanitize=$sanitizer\" -t libfuzzer/$dockerTag"
          sh "zip -j $zipFile $out/*"
          sh "gsutil cp $zipFile gs://clusterfuzz-builds/$projectName/"
        }
      }
    }

  echo 'Done'
}

return this;

{'fraction_non_alphanumeric': 0.1413862842434271, 'fraction_numerical': 0.005148005148005148, 'mean_word_length': 2.139065204847086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3286821', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1507, 'n_words': 478}