-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Track resource inputs for incremental generation #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9ecc39c
fix: Regenerate resources when inputs or configuration change
maximkrouk 057f6a5
ci: Preserve dependency resolution diagnostics
maximkrouk 1f6285a
ci: Include Xcode package graph diagnostics
maximkrouk a922dc3
fix: Exclude plugin build outputs from recursive resource inputs
maximkrouk 1b24f18
fix: Pin merged Swift Snippets compiler compatibility repair
maximkrouk 024e900
fix: Exclude the active SwiftPM scratch tree from plugin inputs
maximkrouk ccab152
fix: Pin merged Casification compatibility and document release const…
maximkrouk 90f24b1
fix: Track symlinked resource destinations without recursive cycles
maximkrouk 906c582
Skip dangling resource symlinks in build inputs
maximkrouk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| indent_style = tab | ||
| tab_width = 2 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | ||
|
|
||
| [*.{py,yml}] | ||
| indent_style = space | ||
| indent_size = 2 | ||
|
|
||
| [*.py] | ||
| indent_size = 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| #!/usr/bin/env python3 | ||
| """Exercise the production plugin's incremental build inputs without remote dependencies. | ||
|
|
||
| The tiny tool records fixture contents instead of invoking resource processors, isolating | ||
| SwiftPM invalidation from generator behavior and dependency resolution. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
| import shutil | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[2] | ||
|
|
||
|
|
||
| class ResourceInputsTests(unittest.TestCase): | ||
| def test_edits_additions_removals_and_package_configuration(self): | ||
| self.check_inputs() | ||
|
|
||
| def test_package_root_target_excludes_build_outputs(self): | ||
| self.check_inputs(target_root=True) | ||
|
|
||
| def test_package_root_target_excludes_custom_scratch_outputs(self): | ||
| self.check_inputs(target_root=True, scratch_path="build-output") | ||
|
|
||
| def test_symlinked_resource_directory_tracks_destination_edits(self): | ||
| self.check_inputs(symlink_resources=True) | ||
|
|
||
| def test_dangling_resource_symlink_is_ignored_until_replaced(self): | ||
| self.check_inputs(dangling_resource=True) | ||
|
|
||
| def check_inputs(self, target_root=False, scratch_path=".build", symlink_resources=False, dangling_resource=False): | ||
| with tempfile.TemporaryDirectory(prefix="package-resource-inputs-") as temporary: | ||
| root = Path(temporary) | ||
| plugin = root / "Plugins/Resources/plugin.swift" | ||
| plugin.parent.mkdir(parents=True) | ||
| shutil.copyfile(ROOT / "Plugins/package-resources-plugin/plugin.swift", plugin) | ||
| (root / "Package.swift").write_text('''// swift-tools-version: 6.1 | ||
| import PackageDescription | ||
| let package = Package( | ||
| name: "ResourceInputFixture", | ||
| platforms: [.macOS(.v15)], | ||
| targets: [ | ||
| .executableTarget(name: "package-resources-cli"), | ||
| .plugin(name: "Resources", capability: .buildTool(), dependencies: ["package-resources-cli"]), | ||
| .target(name: "Fixture", resources: [.copy("Resources")], plugins: ["Resources"]), | ||
| ] | ||
| ) | ||
| ''') | ||
| if target_root: | ||
| manifest = root / "Package.swift" | ||
| manifest.write_text(manifest.read_text().replace( | ||
| '.target(name: "Fixture", resources: [.copy("Resources")],', | ||
| '.target(name: "Fixture", path: ".", ' | ||
| 'exclude: ["Plugins", "Sources/package-resources-cli", "Package.swift"], ' | ||
| 'resources: [.copy("Sources/Fixture/Resources")],', | ||
| )) | ||
| if target_root and scratch_path != ".build": | ||
| # Keep SwiftPM source discovery valid; plugin input traversal must also exclude it. | ||
| manifest.write_text(manifest.read_text().replace( | ||
| '"Package.swift"]', f'"Package.swift", "{scratch_path}"]', | ||
| )) | ||
| tool = root / "Sources/package-resources-cli/main.swift" | ||
| tool.parent.mkdir(parents=True) | ||
| tool.write_text(r'''import Foundation | ||
| let arguments = CommandLine.arguments | ||
| func argument(_ name: String) -> String { arguments[arguments.firstIndex(of: name)! + 1] } | ||
| let input = URL(fileURLWithPath: argument("--input")) | ||
| let rootResources = input.appending(path: "Sources/Fixture/Resources") | ||
| let resources = FileManager.default.fileExists(atPath: rootResources.path) | ||
| ? rootResources : input.appending(path: "Resources") | ||
| let files = FileManager.default.enumerator(at: resources.resolvingSymlinksInPath(), includingPropertiesForKeys: nil, options: [.skipsHiddenFiles])! | ||
| var values: [String] = [] | ||
| for case let file as URL in files where file.pathExtension == "txt" { | ||
| values.append(try String(contentsOf: file, encoding: .utf8)) | ||
| } | ||
| if arguments.contains("--config") { | ||
| values.append(try String(contentsOfFile: argument("--config"), encoding: .utf8)) | ||
| } | ||
| let snapshot = values.sorted().joined(separator: "|") | ||
| try "public let resourceSnapshot = \(String(reflecting: snapshot))\n" | ||
| .write(toFile: argument("--output"), atomically: true, encoding: .utf8) | ||
| ''') | ||
| resources = root / "Sources/Fixture/Resources" | ||
| if symlink_resources: | ||
| shared = root / "SharedResources" | ||
| shared.mkdir() | ||
| resources.parent.mkdir(parents=True) | ||
| resources.symlink_to(shared, target_is_directory=True) | ||
| else: | ||
| resources.mkdir(parents=True) | ||
| (resources.parent / "Fixture.swift").write_text("public enum Fixture {}\n") | ||
| if dangling_resource: | ||
| dangling = resources / "missing.asset" | ||
| dangling.symlink_to(root / "missing-destination") | ||
| original = resources / "original.txt" | ||
| original.write_text("first") | ||
| configuration = root / ".packageresources" | ||
| configuration.write_text("config-first") | ||
|
|
||
| def build_snapshot(): | ||
| result = subprocess.run( | ||
| ["swift", "build", "--scratch-path", str(root / scratch_path), "--target", "Fixture", "--build-system", "native"], | ||
| cwd=root, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | ||
| ) | ||
| self.assertEqual(result.returncode, 0, result.stdout) | ||
| generated = list((root / scratch_path / "plugins/outputs").rglob("Resources.generated.swift")) | ||
| self.assertEqual(len(generated), 1) | ||
| return generated[0].read_text() | ||
|
|
||
| self.assertIn('"config-first|first"', build_snapshot()) | ||
| original.write_text("edited") | ||
| self.assertIn('"config-first|edited"', build_snapshot()) | ||
| added = resources / "added.txt" | ||
| added.write_text("added") | ||
| self.assertIn('"added|config-first|edited"', build_snapshot()) | ||
| original.unlink() | ||
| self.assertIn('"added|config-first"', build_snapshot()) | ||
| configuration.write_text("config-edited") | ||
| self.assertIn('"added|config-edited"', build_snapshot()) | ||
| if dangling_resource: | ||
| dangling.unlink() | ||
| dangling.mkdir() | ||
| (dangling / "recovered.txt").write_text("recovered") | ||
| self.assertIn('"added|config-edited|recovered"', build_snapshot()) | ||
| if symlink_resources: | ||
| replacement = root / "ReplacementResources" | ||
| replacement.mkdir() | ||
| (replacement / "replacement.txt").write_text("replacement") | ||
| resources.unlink() | ||
| resources.symlink_to(replacement, target_is_directory=True) | ||
| self.assertIn('"config-edited|replacement"', build_snapshot()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.