tom_analyzer_shared
Caching infrastructure that builds and reuses binary analyzer summaries so Tom's code generators skip rescanning stable dependencies on every run.
Overview
`tom_analyzer_shared` gives Tom's code generators a shared summary cache. For a project with a resolved `pubspec.lock`, it resolves dependencies, decides which are cacheable, and builds binary analyzer summaries for the SDK and each stable package in dependency order. Summaries are stored under the workspace and handed back so callers can feed them to the analyzer and skip re-analysing unchanged packages from source. Extracted from the reflection generator, it is now the common cache reused by reflection, d4rt bridges, and other generators.
What it enables
Enables Reflection code generation, d4rt bridge generation, Cached dependency analysis.
Relationships
Standalone — no declared relationships.
tom_analyzer_shared
Shared analyzer-summary caching infrastructure reused by Tom code generators. It was extracted from `tom_reflection_generator` so multiple tools (reflection, d4rt bridges, ...) can share the same summary cache at `<workspace>/.tom/analyzer-cache/` and avoid rescanning stable dependencies on every run.
What it does
For a project with a resolved `pubspec.lock`, this library can:
1. Enumerate all dependencies with their exact versions and source types (`hosted`, `sdk`, `path`, `git`). 2. Decide which of them are *cacheable* (hosted pub.dev packages and SDK packages — their versions are stable). 3. Build a binary summary (`.sum`) for the Dart SDK (including Flutter `dart:ui` via `sky_engine/_embedder.yaml` when Flutter is on the path) and for each cacheable package, in topological order so that a package's summary can reference its dependencies' summaries. 4. Store all summaries under `<workspace>/.tom/analyzer-cache/` using the naming scheme `{package}@{version}.sum` and `sdk@{dart-version}.sum`. 5. Return the list of summary paths so callers can pass them to `AnalysisContextCollectionImpl(..., librarySummaryPaths: summaryPaths, sdkSummaryPath: sdkSummaryPath)` and skip re-analysing those packages from sources.
Public API
Import everything via the top-level library:
import 'package:tom_analyzer_shared/tom_analyzer_shared.dart';
Main types and functions:
- `PackageDependency`, `DependencySet` — resolved dependency metadata.
- `DependencyResolver` — parses `pubspec.lock`, resolves hosted and SDK
package locations. - `SummaryCacheManager` — reads and writes `.sum` files in the shared cache directory. - `SummaryGenerator` — generates the SDK summary and per-package summaries (topological order, progress callback, error aggregation). - `runSummaryCacheStage()` — convenience entry-point used by CLI tools. Resolves dependencies, generates what's missing, and returns a `SummaryCacheResult(summaryPaths, sdkSummaryPath)`.
Typical usage
final result = await runSummaryCacheStage(
projectRoot,
verbose: true,
);
final collection = AnalysisContextCollectionImpl(
includedPaths: [projectRoot],
sdkSummaryPath: result?.sdkSummaryPath,
librarySummaryPaths: result?.summaryPaths ?? const [],
);
Both `tom_reflection_generator` and `tom_d4rt_generator` use this stage to share a single cache directory across runs.
License
BSD 3-Clause License Copyright (c) 2024-2026, Peter Nicolai Alexis Kyaw Find me on LinkedIn under Alexis Kyaw All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.