Read during review. The mechanical part is enforced by the Architecture/ package (see
docs/architecture-rules.md); the rest is judgement.
- One pipeline, top-level phase functions.
Plugin.swiftloads the config and callsPackageGeneratorV2.generate, which runs the phases in order: discovery (TargetResolution.swift), import filtering (ImportAnalysis.swift), rendering (TargetRendering.swift,ProductGeneration.swift, written byCodeGeneration.swift) and the optional extras (AdvancedFeatures.swift,DependencyGraph.swift). A phase is a free function at file scope, not a method on a new type. - Pure core, thin shell. Code that turns a configuration and a list of
ParsedPackageinto text does not importPackagePlugin: it takes values and returns values, and reports warnings through a closure the caller passes. Only the shell (config loading, path discovery, runningpackage-generator-cli, writing files,Diagnostics) touchesPackagePlugin, the file system or a process. - The tests compile the real files. A
.plugintarget cannot be imported, soTests/PackageGeneratorTests/SharedandBenchmarks/Benchmarks/GeneratorBenchmarks/Sharedhold symbolic links to the pure files inPlugins/PackageGenerator, never copies. A file that gains aPackagePluginimport can no longer be linked there. - Swift 6 language mode. All code compiles under strict concurrency (
swiftLanguageModes: [.v6]).
- Output is deterministic. The same config and imports give byte-for-byte the same
Package.swift: products and targets are sorted, dependencies are sorted beforeadditionalDependenciesare appended. - Config strings are verbatim.
parametersandadditionalDependenciesare written intoPackage.swiftas given, trimmed but never parsed or rewritten. - Apple SDK filtering happens at render time.
filterImportsdrops only self-imports and explicit exclusions.renderSingleTargetlooks an import up in the external products first, then the local targets, and only then inappleDefaultSDKs, so a package product named like an SDK (Charts) is never dropped. - External products use the package identity.
.product(name:package:)takesdependency.package.id, the URL-derived identity SwiftPM resolves, neverdisplayName. - URL-based PackagePlugin APIs.
context.package.directoryURL,context.pluginWorkDirectoryURL,tool.url; never the deprecatedPathAPIs. - Old configs keep working. A new config key is optional with a default that reproduces today's output; legacy
keys (
targetsParameters, booleanverbose) are migrated in memory, never on disk. Document new keys inREADME.mdand, when they replace an old one, inMIGRATION.md.
- Diagnostics, not print. The plugin reports through
Diagnostics.emit;printoutput is lost in Xcode. Verbose-only messages checkconfig.verbosePlugin.
- Swift Testing only.
@Suite,@Test,#expect,#require; no XCTest, no disabled tests. - Test the rendered text. Assert on the generated
Package.swiftlines, which is what users see.