summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-12-11 10:01:10 -0800
committerDylan Baker <dylan@pnwbakers.com>2024-03-29 13:06:54 -0700
commitfae1363bd3d4b6aec4b2de41f58385e277d91eca (patch)
treedb8da7aa366cc4ef83a30b81809d7a46c092b698 /mesonbuild
parent934c9074bdd81c31a67d87a290247007332cdbcf (diff)
downloadmeson-fae1363bd3d4b6aec4b2de41f58385e277d91eca.tar.gz
scripts/depscan: combine pickle and JSON data into a single file
We don't need to write and pass two separate files to the depscanner, I've used the pickle because the pickle serializer/deserializer should be faster than JSON, thought I haven't tested.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py19
-rw-r--r--mesonbuild/scripts/depscan.py13
2 files changed, 13 insertions, 19 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index d729d1989..77e1b04db 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -144,10 +144,12 @@ class TargetDependencyScannerInfo:
:param private_dir: The private scratch directory for the target.
:param source2object: A mapping of source file names to the objects that
will be created from them.
+ :param sources: A list of all the sources in this target
"""
private_dir: str
source2object: T.Dict[str, str]
+ sources: T.List[str]
@unique
@@ -1095,25 +1097,20 @@ class NinjaBackend(backends.Backend):
pickle_base = target.name + '.dat'
pickle_file = os.path.join(self.get_target_private_dir(target), pickle_base).replace('\\', '/')
pickle_abs = os.path.join(self.get_target_private_dir_abs(target), pickle_base).replace('\\', '/')
- json_abs = os.path.join(self.get_target_private_dir_abs(target), f'{target.name}-deps.json').replace('\\', '/')
rule_name = 'depscan'
scan_sources = self.select_sources_to_scan(compiled_sources)
- # Dump the sources as a json list. This avoids potential problems where
- # the number of sources passed to depscan exceeds the limit imposed by
- # the OS.
- with open(json_abs, 'w', encoding='utf-8') as f:
- json.dump(scan_sources, f)
- elem = NinjaBuildElement(self.all_outputs, depscan_file, rule_name, json_abs)
- elem.add_item('picklefile', pickle_file)
+ scaninfo = TargetDependencyScannerInfo(
+ self.get_target_private_dir(target), source2object, scan_sources)
+ with open(pickle_abs, 'wb') as p:
+ pickle.dump(scaninfo, p)
+
+ elem = NinjaBuildElement(self.all_outputs, depscan_file, rule_name, pickle_file)
# Add any generated outputs to the order deps of the scan target, so
# that those sources are present
for g in generated_source_files:
elem.orderdeps.add(g.relative_name())
elem.orderdeps.update(object_deps)
- scaninfo = TargetDependencyScannerInfo(self.get_target_private_dir(target), source2object)
- with open(pickle_abs, 'wb') as p:
- pickle.dump(scaninfo, p)
self.add_build(elem)
def select_sources_to_scan(self, compiled_sources: T.List[str]) -> T.List[str]:
diff --git a/mesonbuild/scripts/depscan.py b/mesonbuild/scripts/depscan.py
index 3a61370a9..c0ac09b52 100644
--- a/mesonbuild/scripts/depscan.py
+++ b/mesonbuild/scripts/depscan.py
@@ -5,7 +5,6 @@
from __future__ import annotations
import collections
-import json
import os
import pathlib
import pickle
@@ -32,11 +31,11 @@ FORTRAN_SUBMOD_RE = re.compile(FORTRAN_SUBMOD_PAT, re.IGNORECASE)
FORTRAN_USE_RE = re.compile(FORTRAN_USE_PAT, re.IGNORECASE)
class DependencyScanner:
- def __init__(self, pickle_file: str, outfile: str, sources: T.List[str]):
+ def __init__(self, pickle_file: str, outfile: str):
with open(pickle_file, 'rb') as pf:
self.target_data: TargetDependencyScannerInfo = pickle.load(pf)
self.outfile = outfile
- self.sources = sources
+ self.sources = self.target_data.sources
self.provided_by: T.Dict[str, str] = {}
self.exports: T.Dict[str, str] = {}
self.needs: collections.defaultdict[str, T.List[str]] = collections.defaultdict(list)
@@ -183,9 +182,7 @@ class DependencyScanner:
return 0
def run(args: T.List[str]) -> int:
- assert len(args) == 3, 'got wrong number of arguments!'
- pickle_file, outfile, jsonfile = args
- with open(jsonfile, encoding='utf-8') as f:
- sources = json.load(f)
- scanner = DependencyScanner(pickle_file, outfile, sources)
+ assert len(args) == 2, 'got wrong number of arguments!'
+ outfile, pickle_file = args
+ scanner = DependencyScanner(pickle_file, outfile)
return scanner.scan()