aboutsummaryrefslogtreecommitdiff
path: root/infra/base-images/base-builder
diff options
context:
space:
mode:
authorJonathan Metzman <metzman@chromium.org>2021-01-20 12:34:29 -0800
committerJonathan Metzman <metzman@chromium.org>2021-01-20 13:25:56 -0800
commit2b26c5446f7a55d52259aad4bef342d28bdd087a (patch)
tree212a7ad7ac7a029dfa4bfdd3294ab39a4b2bbedb /infra/base-images/base-builder
parentb998058ef3c6a27fe179b0ab3db8cb08ad766d85 (diff)
downloadoss-fuzz-2b26c5446f7a55d52259aad4bef342d28bdd087a.tar.gz
Lint everything (and test everything too?
Diffstat (limited to 'infra/base-images/base-builder')
-rw-r--r--infra/base-images/base-builder/bisect_clang.py29
-rw-r--r--infra/base-images/base-builder/bisect_clang_test.py15
-rwxr-xr-xinfra/base-images/base-builder/write_labels.py7
3 files changed, 29 insertions, 22 deletions
diff --git a/infra/base-images/base-builder/bisect_clang.py b/infra/base-images/base-builder/bisect_clang.py
index 2e7db61ca..8c530b627 100644
--- a/infra/base-images/base-builder/bisect_clang.py
+++ b/infra/base-images/base-builder/bisect_clang.py
@@ -112,7 +112,7 @@ class GitRepo:
class BisectError(Exception):
- pass
+ """Error that was encountered during bisection."""
def get_clang_build_env():
@@ -140,8 +140,8 @@ def clone_with_retries(repo, local_path, num_retries=10):
for _ in range(num_retries):
if os.path.isdir(local_path):
shutil.rmtree(local_path)
- retcode, _, _ = execute(
- ['git', 'clone', repo, local_path], expect_zero=False)
+ retcode, _, _ = execute(['git', 'clone', repo, local_path],
+ expect_zero=False)
if retcode == 0:
return
raise Exception('Could not checkout %s.' % repo)
@@ -162,17 +162,16 @@ def prepare_build(llvm_project_path):
llvm_build_dir = os.path.join(os.getenv('WORK'), 'llvm-build')
if not os.path.exists(llvm_build_dir):
os.mkdir(llvm_build_dir)
- execute(
- [
- 'cmake', '-G', 'Ninja', '-DLIBCXX_ENABLE_SHARED=OFF',
- '-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON',
- '-DLIBCXXABI_ENABLE_SHARED=OFF', '-DCMAKE_BUILD_TYPE=Release',
- '-DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi;compiler-rt;clang',
- '-DLLVM_TARGETS_TO_BUILD=' + get_clang_target_arch(),
- os.path.join(llvm_project_path, 'llvm')
- ],
- env=get_clang_build_env(),
- cwd=llvm_build_dir)
+ execute([
+ 'cmake', '-G', 'Ninja', '-DLIBCXX_ENABLE_SHARED=OFF',
+ '-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON', '-DLIBCXXABI_ENABLE_SHARED=OFF',
+ '-DCMAKE_BUILD_TYPE=Release',
+ '-DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi;compiler-rt;clang',
+ '-DLLVM_TARGETS_TO_BUILD=' + get_clang_target_arch(),
+ os.path.join(llvm_project_path, 'llvm')
+ ],
+ env=get_clang_build_env(),
+ cwd=llvm_build_dir)
return llvm_build_dir
@@ -201,12 +200,14 @@ def find_culprit_commit(test_command, good_commit, bad_commit):
def main():
+ # pylint: disable=line-too-long
"""Finds the culprit LLVM commit that introduced a clang regression.
Can be tested using this command in a libsodium shell:
python3 bisect_clang.py "cd /src/libsodium; make clean; cd -; compile && /out/secret_key_auth_fuzzer -runs=100" \
f7e52fbdb5a7af8ea0808e98458b497125a5eca1 \
8288453f6aac05080b751b680455349e09d49825
"""
+ # pylint: enable=line-too-long
# TODO(metzman): Sanity check CFLAGS for things like
# -fsanitize=fuzzer-no-link.
# TODO(metzman): Allow test_command to be optional and for just build.sh to be
diff --git a/infra/base-images/base-builder/bisect_clang_test.py b/infra/base-images/base-builder/bisect_clang_test.py
index 7a11021d1..edf13e759 100644
--- a/infra/base-images/base-builder/bisect_clang_test.py
+++ b/infra/base-images/base-builder/bisect_clang_test.py
@@ -37,10 +37,11 @@ def patch_environ(testcase_obj):
patcher.start()
-class BisectClangTestMixin:
+class BisectClangTestMixin: # pylint: disable=too-few-public-methods
"""Useful mixin for bisect_clang unittests."""
- def setUp(self):
+ def setUp(self): # pylint: disable=invalid-name
+ """Initialization method for unittests."""
patch_environ(self)
os.environ['SRC'] = '/src'
os.environ['WORK'] = '/work'
@@ -68,8 +69,9 @@ class GetClangBuildEnvTest(BisectClangTestMixin, unittest.TestCase):
def read_test_data(filename):
- with open(os.path.join(FILE_DIRECTORY, 'test_data', filename)) as f:
- return f.read()
+ """Returns data from |filename| in the test_data directory."""
+ with open(os.path.join(FILE_DIRECTORY, 'test_data', filename)) as file_handle:
+ return file_handle.read()
class SearchBisectOutputTest(BisectClangTestMixin, unittest.TestCase):
@@ -126,6 +128,7 @@ def create_mock_popen(
def mock_prepare_build(llvm_project_path): # pylint: disable=unused-argument
+ """Mocked prepare_build function."""
return '/work/llvm-build'
@@ -224,8 +227,8 @@ class GitRepoTest(BisectClangTestMixin, unittest.TestCase):
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
self.git.bisect_start(self.good_commit, self.bad_commit,
self.test_command)
- self.assertEqual(
- get_git_command('bisect', 'start'), mock_popen.commands[0])
+ self.assertEqual(get_git_command('bisect', 'start'),
+ mock_popen.commands[0])
mock_test_start_commit.assert_has_calls([
mock.call('bad_commit', 'bad', 'testcommand'),
mock.call('good_commit', 'good', 'testcommand')
diff --git a/infra/base-images/base-builder/write_labels.py b/infra/base-images/base-builder/write_labels.py
index 338ac716f..b1a748427 100755
--- a/infra/base-images/base-builder/write_labels.py
+++ b/infra/base-images/base-builder/write_labels.py
@@ -1,10 +1,13 @@
#!/usr/bin/python3
+"""Script for writing from project.yaml to .labels file."""
import os
import json
import sys
+
def main():
+ """Writes labels."""
if len(sys.argv) != 3:
print('Usage: write_labels.py labels_json out_dir', file=sys.stderr)
sys.exit(1)
@@ -13,8 +16,8 @@ def main():
out = sys.argv[2]
for target_name, labels in labels_by_target.items():
- with open(os.path.join(out, target_name + '.labels'), 'w') as f:
- f.write('\n'.join(labels))
+ with open(os.path.join(out, target_name + '.labels'), 'w') as file_handle:
+ file_handle.write('\n'.join(labels))
if __name__ == '__main__':