• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Module for representing the workspace directory which CIFuzz uses."""
15
16import os
17
18
19class Workspace:
20  """Class representing the workspace directory."""
21
22  def __init__(self, config):
23    self.workspace = config.workspace
24
25  def initialize_dir(self, directory):  # pylint: disable=no-self-use
26    """Creates directory if it doesn't already exist, otherwise does nothing."""
27    os.makedirs(directory, exist_ok=True)
28
29  @property
30  def repo_storage(self):
31    """The parent directory for repo storage."""
32    return os.path.join(self.workspace, 'storage')
33
34  @property
35  def out(self):
36    """The out directory used for storing the fuzzer build built by
37    build_fuzzers."""
38    # Don't use 'out' because it needs to be used by artifacts.
39    return os.path.join(self.workspace, 'build-out')
40
41  @property
42  def work(self):
43    """The directory used as the work directory for the fuzzer build/run."""
44    return os.path.join(self.workspace, 'work')
45
46  @property
47  def artifacts(self):
48    """The directory used to store artifacts for download by CI-system users."""
49    # This is hardcoded by a lot of clients, so we need to use this.
50    return os.path.join(self.workspace, 'out', 'artifacts')
51
52  @property
53  def clusterfuzz_build(self):
54    """The directory where builds from ClusterFuzz are stored."""
55    return os.path.join(self.workspace, 'cifuzz-prev-build')
56
57  @property
58  def clusterfuzz_coverage(self):
59    """The directory where builds from ClusterFuzz are stored."""
60    return os.path.join(self.workspace, 'cifuzz-prev-coverage')
61
62  @property
63  def coverage_report(self):
64    """The directory where coverage reports generated by cifuzz are put."""
65    return os.path.join(self.workspace, 'cifuzz-coverage')
66
67  @property
68  def corpora(self):
69    """The directory where corpora from ClusterFuzz are stored."""
70    return os.path.join(self.workspace, 'cifuzz-corpus')
71
72  @property
73  def pruned_corpora(self):
74    """The directory where pruned corpora are stored."""
75    return os.path.join(self.workspace, 'cifuzz-pruned-corpus')
76