Skip to content

Commit

Permalink
reintroduce create_skipfile.py script for gerrit
Browse files Browse the repository at this point in the history
The script was removed in c1626bb
but for the usecase where the user does not want to analyze
all the source files in the review it is needed.
  • Loading branch information
Gyorgy Orban committed Nov 5, 2020
1 parent d1604bb commit 11ca1e0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ package_tu_collector: build_tu_collector package_dir_structure
cd $(CC_BUILD_DIR) && \
ln -sf ../lib/python3/tu_collector/tu_collector.py bin/tu_collector

package_gerrit_skiplist:
cp -rp $(CC_TOOLS)/skiplist/create_skipfile.py $(CC_BUILD_DIR)/bin

build_report_converter:
$(MAKE) -C $(ROOT)/tools/report-converter build

Expand Down Expand Up @@ -90,7 +93,7 @@ package_statistics_collector: build_statistics_collector package_dir_structure
cd $(CC_BUILD_DIR) && \
ln -sf ../lib/python3/codechecker_statistics_collector/cli.py bin/post-process-stats

package: package_dir_structure set_git_commit_template package_plist_to_html package_tu_collector package_report_converter package_report_hash package_merge_clang_extdef_mappings package_statistics_collector
package: package_dir_structure set_git_commit_template package_plist_to_html package_tu_collector package_report_converter package_report_hash package_merge_clang_extdef_mappings package_statistics_collector package_gerrit_skiplist
BUILD_DIR=$(BUILD_DIR) BUILD_LOGGER_64_BIT_ONLY=$(BUILD_LOGGER_64_BIT_ONLY) $(MAKE) -C $(CC_ANALYZER) package_analyzer
BUILD_DIR=$(BUILD_DIR) $(MAKE) -C $(CC_WEB) package_web

Expand Down
13 changes: 12 additions & 1 deletion docs/jenkins_gerrit_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,16 @@ CodeChecker log -b "build command" -o compile_cmd.json
# Run the tests. If this fails, the result will be verified -1.
make tests

export CC_CHANGED_FILES="$WORKSPACE/files-changed"
export CC_SKIPFILE="$WORKSPACE/skipfile"

# create_skipfile.py script can be found in the bin directory in the CodeChecker package.
python create_skipfile.py $CC_CHANGED_FILES $CC_SKIPFILE

# Check the project.
CodeChecker analyze \
-e sensitive \
--ignore $CC_SKIPFILE \
-j 16 \
compile_cmd.json \
-o cc_reports
Expand All @@ -213,7 +220,6 @@ CodeChecker analyze \
# gerrit_review.json file in this directory that is later going to be loaded
# as an Environment Variable.
CC_REPORT_URL="http://your_jenkins_address/userContent/$JOB_NAME/$BUILD_NUMBER/index.html" \
CC_CHANGED_FILES="$WORKSPACE/files-changed" \
CC_REPO_DIR="$WORKSPACE/repo_dir" \
CodeChecker cmd diff \
-b clangsa_checkers-merge \
Expand All @@ -222,6 +228,11 @@ CodeChecker cmd diff \
--new \
-o html gerrit \
-e $JENKINS_HOME/userContent/$JOB_NAME/$BUILD_NUMBER

# Craft the review message and write it into a file,
# that is later going to be loaded as an Environment Variable.
echo DATA_TO_POST=\\ > review
CodeChecker parse --ignore $CC_SKIPFILE cc_reports -e gerrit >> review
```

### Inject environment variable <a name="inject-environment-variable"></a>
Expand Down
54 changes: 54 additions & 0 deletions tools/skiplist/create_skipfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
Converts Gerrit Review changed files list to CodeChecker skipfile.
"""

import argparse
import json
import re


def create_skipfile(files_changed, skipfile):
# File is likely to contain some garbage values at start,
# only the corresponding json should be parsed.
json_pattern = re.compile(r"^\{.*\}")
for line in files_changed.readlines():
if re.match(json_pattern, line):
for filename in json.loads(line):
if "/COMMIT_MSG" in filename:
continue
skipfile.write("+*/%s\n" % filename)

skipfile.write("-*\n")


def main():
parser = argparse.ArgumentParser(
description="Converts Gerrit Review changed files "
"json to CodeChecker skipfile."
)
parser.add_argument(
"files_changed",
type=argparse.FileType("r"),
help="Path of changed files json from Gerrit.",
)
parser.add_argument(
"skipfile",
nargs="?",
default="skipfile",
type=argparse.FileType("w"),
help="Path of the skipfile output. Default is ./skipfile.",
)
args = parser.parse_args()

create_skipfile(args.files_changed, args.skipfile)


if __name__ == "__main__":
main()

0 comments on commit 11ca1e0

Please sign in to comment.