|
36 | 36 | from typing import Any, Callable, Mapping, Self, Sequence |
37 | 37 | import urllib.request |
38 | 38 |
|
| 39 | +import manifest_constants |
39 | 40 | import pathlib |
40 | 41 |
|
41 | 42 |
|
42 | | -# Source directory. |
43 | | -SRC_DIR = pathlib.Path("src") |
44 | | -# Object directory. |
45 | | -OBJ_DIR = pathlib.Path("obj") |
46 | | -# Directory for indexer data. |
47 | | -INDEX_DIR = pathlib.Path("idx") |
48 | | -# The index database filename. |
49 | | -INDEX_DB = pathlib.Path("db.sqlite") |
50 | | -# Library directory, where shared libraries are copied - inside obj. |
51 | | -LIB_DIR = OBJ_DIR / "lib" |
52 | | -# Manifest location |
53 | | -MANIFEST_PATH = pathlib.Path("manifest.json") |
54 | | -# Where archive version 1 expects the lib directory to be mounted. |
55 | | -_LIB_MOUNT_PATH_V1 = pathlib.Path("/ossfuzzlib") |
| 43 | +SRC_DIR = manifest_constants.SRC_DIR |
| 44 | +OBJ_DIR = manifest_constants.OBJ_DIR |
| 45 | +INDEX_DIR = manifest_constants.INDEX_DIR |
| 46 | +INDEX_DB = manifest_constants.INDEX_DB |
| 47 | +LIB_DIR = manifest_constants.LIB_DIR |
| 48 | +MANIFEST_PATH = manifest_constants.MANIFEST_PATH |
| 49 | +LIB_MOUNT_PATH_V1 = manifest_constants.LIB_MOUNT_PATH_V1 |
| 50 | + |
| 51 | +INPUT_FILE = manifest_constants.INPUT_FILE |
| 52 | +OUTPUT_FILE = manifest_constants.OUTPUT_FILE |
| 53 | +DYNAMIC_ARGS = manifest_constants.DYNAMIC_ARGS |
| 54 | + |
56 | 55 | # Min archive version we currently support. |
57 | 56 | _MIN_SUPPORTED_ARCHIVE_VERSION = 1 |
58 | 57 | # The current version of the build archive format. |
|
64 | 63 | f"latest_report_info/{os.getenv('PROJECT_NAME')}.json") |
65 | 64 |
|
66 | 65 |
|
67 | | -# Will be replaced with the input file for target execution. |
68 | | -INPUT_FILE = "<input_file>" |
69 | | -# A file the target can write output to. |
70 | | -OUTPUT_FILE = "<output_file>" |
71 | | -# Will be replaced with any dynamic arguments. |
72 | | -DYNAMIC_ARGS = "<dynamic_args>" |
73 | | - |
74 | | - |
75 | | - |
76 | 66 | class RepositoryType(enum.StrEnum): |
77 | 67 | """The type of repository.""" |
78 | 68 |
|
@@ -142,12 +132,13 @@ class BinaryConfig: |
142 | 132 |
|
143 | 133 | Attributes: |
144 | 134 | kind: The kind of binary configuration. |
145 | | - binary_args: The arguments to pass to the binary, for example |
146 | | - "<input_file>". |
| 135 | + binary_name: The name of the executable file. |
147 | 136 | """ |
148 | 137 |
|
149 | 138 | kind: BinaryConfigKind |
150 | 139 |
|
| 140 | + binary_name: str |
| 141 | + |
151 | 142 | @classmethod |
152 | 143 | def from_dict(cls, config_dict: Mapping[str, Any]) -> Self: |
153 | 144 | """Deserializes the correct `BinaryConfig` subclass from a dict.""" |
@@ -186,7 +177,6 @@ class HarnessKind(enum.StrEnum): |
186 | 177 | class CommandLineBinaryConfig(BinaryConfig): |
187 | 178 | """Configuration for a command-line userspace binary.""" |
188 | 179 |
|
189 | | - binary_name: str |
190 | 180 | binary_args: list[str] |
191 | 181 | # Additional environment variables to pass to the binary. They will overwrite |
192 | 182 | # any existing environment variables with the same name. |
@@ -285,7 +275,7 @@ class Manifest: |
285 | 275 | def from_dict(cls, data: dict[str, Any]) -> Self: |
286 | 276 | """Creates a Manifest object from a deserialized dict.""" |
287 | 277 | if data["version"] == 1: |
288 | | - lib_mount_path = _LIB_MOUNT_PATH_V1 |
| 278 | + lib_mount_path = LIB_MOUNT_PATH_V1 |
289 | 279 | else: |
290 | 280 | lib_mount_path = _get_mapped(data, "lib_mount_path", pathlib.Path) |
291 | 281 | if data["version"] < 3: |
@@ -358,7 +348,7 @@ def validate(self) -> None: |
358 | 348 | f"Build archive version too high: {self.version}. Only supporting" |
359 | 349 | f" up to {ARCHIVE_VERSION}." |
360 | 350 | ) |
361 | | - if self.version == 1 and _LIB_MOUNT_PATH_V1 != self.lib_mount_path: |
| 351 | + if self.version == 1 and LIB_MOUNT_PATH_V1 != self.lib_mount_path: |
362 | 352 | raise RuntimeError( |
363 | 353 | "Build archive with version 1 has an alternative lib_mount_path set" |
364 | 354 | f" ({self.lib_mount_path}). This is not a valid archive." |
@@ -409,12 +399,6 @@ def save_build( |
409 | 399 |
|
410 | 400 | self.validate() |
411 | 401 |
|
412 | | - if not hasattr(self.binary_config, "binary_name"): |
413 | | - raise RuntimeError( |
414 | | - "Attempting to save a binary config type without binary_name." |
415 | | - " This is not yet supported. Kind: {self.binary_config.kind}." |
416 | | - ) |
417 | | - |
418 | 402 | with tempfile.NamedTemporaryFile() as tmp: |
419 | 403 | mode = "w:gz" if archive_path.suffix.endswith("gz") else "w" |
420 | 404 | with tarfile.open(tmp.name, mode) as tar: |
@@ -459,7 +443,9 @@ def _save_dir( |
459 | 443 |
|
460 | 444 | dumped_self = self |
461 | 445 | if self.index_db_version is None: |
462 | | - index_db_version = _get_sqlite_db_user_version(index_dir / INDEX_DB) |
| 446 | + index_db_version = _get_sqlite_db_user_version( |
| 447 | + pathlib.Path(index_dir) / INDEX_DB |
| 448 | + ) |
463 | 449 | dumped_self = dataclasses.replace( |
464 | 450 | self, index_db_version=index_db_version |
465 | 451 | ) |
|
0 commit comments