Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Build Artifacts knows what game engines and .NET build
Țugui Dragoș0cee00d26c2d
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swiftindex d370a6ce..90a9d5de 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift@@ -43,7 +43,8 @@ public enum ProjectArtifacts {struct Definition: Sendable {let name: String- /// A leading `*` matches any name with that ending, as in `*.xcodeproj`.+ /// A leading `*` matches any name with that ending, as in `*.xcodeproj`, and a path names a file inside a+ /// folder beside the artifact, as in `ProjectSettings/ProjectVersion.txt`.let markers: [String]let tool: Stringlet isGeneric: Bool@@ -53,11 +54,22 @@ public enum ProjectArtifacts {/// What the folder holds that only its tool writes, for a kind no project file stands beside.var proof: Proof?- /// Whether the folder at `url`, beside the entries called `names`, is this kind.func matches(_ url: URL, besides names: Set<String>) -> Bool {- guard markers.isEmpty || ProjectArtifacts.marker(for: self, in: names) != nil else { return false }+ let folder = url.deletingLastPathComponent()+ guard markers.isEmpty || hasMarker(besides: names, in: folder) else { return false }return proof?.holds(at: url) ?? true}++ private func hasMarker(besides names: Set<String>, in folder: URL) -> Bool {+ markers.contains { marker in+ if marker.hasPrefix("*") {+ let suffix = marker.dropFirst()+ return names.contains { $0.hasSuffix(suffix) && $0.count > suffix.count }+ }+ guard let first = PathComponents.of(marker).first, names.contains(first) else { return false }+ return first == marker || Proof.holds(marker).holds(at: folder)+ }+ }}enum Proof: Sendable {@@ -91,6 +103,8 @@ public enum ProjectArtifacts {private static let viteConfigFiles = ["ts", "mts", "cts", "js", "mjs", "cjs"].map { "vite.config." + $0 }private static let vitestConfigFiles = ["ts", "mts", "cts", "js", "mjs", "cjs"].map { "vitest.config." + $0 }private static let gatsbyConfigFiles = ["gatsby-config.js", "gatsby-config.ts", "gatsby-config.mjs"]+ private static let unityProjectFile = "ProjectSettings/ProjectVersion.txt"+ private static let dotNetProjectFiles = ["*.csproj", "*.fsproj", "*.vbproj", "*.sln"]private static let pytestFiles = ["pytest.toml", ".pytest.toml", "pytest.ini", ".pytest.ini", "pyproject.toml", "tox.ini", "setup.cfg","conftest.py",@@ -243,6 +257,51 @@ public enum ProjectArtifacts {name: "dist", markers: ["pyproject.toml"], tool: "Python", isGeneric: true,source: "https://packaging.python.org/en/latest/tutorials/packaging-projects/"),+ Definition(+ name: "Library", markers: [unityProjectFile], tool: "Unity", isGeneric: true,+ source: "https://docs.unity.com/en-us/unity-version-control/ignore-files"+ ),+ Definition(+ name: "Temp", markers: [unityProjectFile], tool: "Unity", isGeneric: true,+ source: "https://docs.unity.com/en-us/unity-version-control/ignore-files"+ ),+ Definition(+ name: "Logs", markers: [unityProjectFile], tool: "Unity", isGeneric: true,+ source: "https://docs.unity.com/en-us/unity-version-control/ignore-files"+ ),+ Definition(+ name: "obj", markers: [unityProjectFile], tool: "Unity", isGeneric: true,+ source: "https://docs.unity.com/en-us/unity-version-control/ignore-files"+ ),+ Definition(+ name: "Binaries", markers: ["*.uproject"], tool: "Unreal Engine", isGeneric: true,+ source: "https://dev.epicgames.com/documentation/en-us/unreal-engine/unreal-engine-directory-structure"+ ),+ Definition(+ name: "Intermediate", markers: ["*.uproject"], tool: "Unreal Engine", isGeneric: true,+ source: "https://dev.epicgames.com/documentation/en-us/unreal-engine/unreal-engine-directory-structure"+ ),+ Definition(+ name: "DerivedDataCache", markers: ["*.uproject"], tool: "Unreal Engine", isGeneric: false,+ source: "https://dev.epicgames.com/documentation/en-us/unreal-engine/unreal-engine-directory-structure"+ ),+ Definition(+ name: ".godot", markers: ["project.godot"], tool: "Godot", isGeneric: false,+ source: "https://docs.godotengine.org/en/stable/tutorials/best_practices/version_control_systems.html"+ ),+ Definition(+ name: ".import", markers: ["project.godot"], tool: "Godot", isGeneric: false,+ source: "https://docs.godotengine.org/en/3.6/tutorials/best_practices/version_control_systems.html"+ ),+ // After the game engines, whose projects carry a .NET project file too.+ Definition(+ name: "bin", markers: dotNetProjectFiles, tool: ".NET", isGeneric: true,+ source: "https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props"+ ),+ Definition(+ name: "obj", markers: dotNetProjectFiles, tool: ".NET", isGeneric: true,+ source: "https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties"+ ),]/// Duplicates uses it to recognize a project folder and leave it alone.@@ -250,7 +309,9 @@ public enum ProjectArtifacts {exactMarkers.contains(name) || markerSuffixes.contains { name.hasSuffix($0) && name.count > $0.count }}- private static let exactMarkers = Set(definitions.flatMap(\.markers).filter { !$0.hasPrefix("*") })+ private static let exactMarkers = Set(+ definitions.flatMap(\.markers).filter { !$0.hasPrefix("*") }.compactMap { PathComponents.of($0).first }+ )private static let markerSuffixes = Set(definitions.flatMap(\.markers).filter { $0.hasPrefix("*") }.map { String($0.dropFirst()) })static let maximumDepth = 8@@ -395,18 +456,6 @@ public enum ProjectArtifacts {return definitions.contains { $0.name == name && !$0.isGeneric }}- static func marker(for definition: Definition, in names: Set<String>) -> String? {- for marker in definition.markers {- if marker.hasPrefix("*") {- let suffix = String(marker.dropFirst())- if let match = names.first(where: { $0.hasSuffix(suffix) && $0.count > suffix.count }) { return match }- } else if names.contains(marker) {- return marker- }- }- return nil- }-/// Files Git updates whenever the repository changes: three reads can answer for a whole repository.private static let gitMarks = [".git/index", ".git/HEAD", ".git/logs/HEAD"]diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swiftindex 2c9628aa..52c5b18f 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift@@ -137,6 +137,34 @@ struct ProjectArtifactsTests {])}+ @Test func findsWhatGameEnginesAndDotNetBuild() async throws {+ let unity = "ProjectSettings/ProjectVersion.txt"+ try await expectFound([+ Kind(artifact: "Library", marker: unity, tool: "Unity", isGeneric: true),+ Kind(artifact: "Temp", marker: unity, tool: "Unity", isGeneric: true),+ Kind(artifact: "Logs", marker: unity, tool: "Unity", isGeneric: true),+ Kind(artifact: "obj", marker: unity, tool: "Unity", isGeneric: true),+ Kind(artifact: "Binaries", marker: "Game.uproject", tool: "Unreal Engine", isGeneric: true),+ Kind(artifact: "Intermediate", marker: "Game.uproject", tool: "Unreal Engine", isGeneric: true),+ Kind(artifact: "DerivedDataCache", marker: "Game.uproject", tool: "Unreal Engine", isGeneric: false),+ Kind(artifact: ".godot", marker: "project.godot", tool: "Godot", isGeneric: false),+ Kind(artifact: ".import", marker: "project.godot", tool: "Godot", isGeneric: false),+ Kind(artifact: "bin", marker: "App.csproj", tool: ".NET", isGeneric: true),+ Kind(artifact: "obj", marker: "Library.fsproj", tool: ".NET", isGeneric: true),+ ])+ }++ @Test func aUnityProjectsObjIsUnitysThoughDotNetsProjectFileSitsBesideIt() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("game/ProjectSettings/ProjectVersion.txt", bytes: 16)+ try directory.file("game/Assembly-CSharp.csproj", bytes: 16)+ try directory.file("game/obj/Debug/Assembly-CSharp.dll", bytes: 400_000)++ let found = await ProjectArtifacts.scan(roots: [directory.url]).artifacts++ #expect(found.map(\.tool) == ["Unity"])+ }+@Test func findsPythonsCompiledFilesOnlyWhereThatIsAllThereIs() async throws {let directory = try TemporaryDirectory()try directory.file("tool/app.py", bytes: 16)