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.
pull/13021/head
Dylan Baker 11 months ago
parent 934c9074bd
commit fae1363bd3
  1. 19
      mesonbuild/backend/ninjabackend.py
  2. 13
      mesonbuild/scripts/depscan.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]:

@ -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()

Loading…
Cancel
Save