From 79d6c635ac5b5566b02828e378e30731dca9a2cd Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Wed, 17 Apr 2024 10:23:07 +0900 Subject: [PATCH 1/3] Ignore special folder contents --- unity/metanecessity.go | 26 ++++++++++++++++++++++-- unity/metanecessity_test.go | 40 +++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/unity/metanecessity.go b/unity/metanecessity.go index 321fad1..039245e 100644 --- a/unity/metanecessity.go +++ b/unity/metanecessity.go @@ -8,6 +8,7 @@ import ( ) type MetaNecessity func(targetPath typedpath.SlashPath) bool + const AssetsDirBaseName typedpath.BaseName = "Assets" func NewMetaNecessityInUnityProject(pkgPaths []typedpath.SlashPath) MetaNecessity { @@ -33,10 +34,14 @@ func NewMetaNecessityInUnityProject(pkgPaths []typedpath.SlashPath) MetaNecessit return false } - for _, component := range elements { + for i, component := range elements { if IsHiddenBasename(component) { return false } + notLast := i < len(elements)-1 + if notLast && IsSpecialFolder(component) { + return false + } } return true @@ -50,10 +55,14 @@ func NewMetaNecessityInUnityProjectSubDir() MetaNecessity { return false } - for _, component := range elements { + for i, component := range elements { if IsHiddenBasename(component) { return false } + notLast := i < len(elements)-1 + if notLast && IsSpecialFolder(component) { + return false + } } return true @@ -76,6 +85,19 @@ func IsHiddenBasename(baseName typedpath.BaseName) bool { strings.HasSuffix(string(baseName), ".tmp") } +// IsSpecialFolder return whether the specified basename is treated as "special" by Unity. +// Unity requires .meta files for only the special folder itself, and not requires .meta files for contents of the special folder. +// https://docs.unity3d.com/ja/2023.1/Manual/SpecialFolders.html +// https://forum.unity.com/threads/loadable-plugin-directory-import-behaviour-change-androidlib-bundle-framework-and-plugin.1381113/ +func IsSpecialFolder(baseName typedpath.BaseName) bool { + return strings.HasSuffix(string(baseName), ".xcframework") || + strings.HasSuffix(string(baseName), ".framework") || + strings.HasSuffix(string(baseName), ".androidlib") || + strings.HasSuffix(string(baseName), ".androidpack") || + strings.HasSuffix(string(baseName), ".bundle") || + strings.HasSuffix(string(baseName), ".plugin") +} + const MetaSuffix string = ".meta" func IsMeta(path typedpath.SlashPath) bool { diff --git a/unity/metanecessity_test.go b/unity/metanecessity_test.go index 94f5a96..ad2a719 100644 --- a/unity/metanecessity_test.go +++ b/unity/metanecessity_test.go @@ -17,6 +17,12 @@ func TestNewMetaNecessityInUnityProject(t *testing.T) { {"Packages/com.my.pkg/README.md", true}, // https://docs.unity3d.com/2020.2/Documentation/Manual/cus-layout.html {"LocalPackages/com.my.local.pkg/README.md", true}, + // https://docs.unity3d.com/ja/2023.1/Manual/SpecialFolders.html + {"Assets/Plugins/Foo.xcframework", true}, + {"Assets/Plugins/Foo.androidlib", true}, + {"Assets/Plugins/Foo.androidpack", true}, + {"Assets/Plugins/Foo.bundle", true}, + {"Assets/Plugins/Foo.framework", true}, {"", false}, {".git", false}, @@ -37,6 +43,14 @@ func TestNewMetaNecessityInUnityProject(t *testing.T) { {"LocalPackages", false}, {"LocalPackages/com.my.local.pkg", false}, {"LocalPackages/com.my.local.pkg/Documentation~", false}, + + // https://docs.unity3d.com/ja/2023.1/Manual/SpecialFolders.html + {"Assets/Plugins/Foo.bundle/Contents/Info.plist", false}, + {"Assets/Plugins/Foo.framework/Versions/A/Foo", false}, + {"Assets/Plugins/Foo.xcframework/Info.plist", false}, + {"Assets/Plugins/Foo.xcframework/ios-armv7_arm64/Foo.xcframework/Info.plist", false}, + {"Assets/Plugins/Foo.androidlib/AndroidManifest.xml", false}, + {"Assets/Plugins/Foo.androidpack/src/main/assets/Bar.bundle", false}, } for _, c := range cases { @@ -80,11 +94,26 @@ func TestNewMetaNecessityInUnityProjectSubDir(t *testing.T) { {"Tests/Editor/EditorExampleTest.cs", true}, {"lib/native.a", true}, + // https://docs.unity3d.com/ja/2023.1/Manual/SpecialFolders.html + {"Runtime/Foo.bundle", true}, + {"Runtime/Foo.framework", true}, + {"Runtime/Foo.xcframework", true}, + {"Runtime/Foo.androidlib", true}, + {"Runtime/Foo.androidpack", true}, + {"", false}, {".git", false}, {"Runtime.meta", false}, {"Documentation~", false}, {"Documentation~/com.my.pkg.md", false}, + + // https://docs.unity3d.com/ja/2023.1/Manual/SpecialFolders.html + {"Runtime/Foo.bundle/Contents/Info.plist", false}, + {"Runtime/Foo.framework/Versions/A/Foo", false}, + {"Runtime/Foo.xcframework/Info.plist", false}, + {"Runtime/Foo.xcframework/ios-armv7_arm64/Foo.xcframework/Info.plist", false}, + {"Runtime/Foo.androidlib/AndroidManifest.xml", false}, + {"Runtime/Foo.androidpack/src/main/assets/Bar.bundle", false}, } for _, c := range cases { @@ -101,19 +130,18 @@ func TestNewMetaNecessityInUnityProjectSubDir(t *testing.T) { } } - func TestTrimMeta(t *testing.T) { - cases := []struct{ + cases := []struct { SlashPath typedpath.SlashPath - Expected typedpath.SlashPath - } { + Expected typedpath.SlashPath + }{ { SlashPath: "path/to/foo.meta", - Expected: "path/to/foo", + Expected: "path/to/foo", }, { SlashPath: "path/to/test.meta", - Expected: "path/to/test", + Expected: "path/to/test", }, } From 6c30cf0fc961ea7e6e073fc123e503a2146a9c84 Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Wed, 17 Apr 2024 10:40:20 +0900 Subject: [PATCH 2/3] Treat special folders --- testdata/InvalidProject | 2 +- testdata/ValidProject | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testdata/InvalidProject b/testdata/InvalidProject index a2e4a88..910c1ac 160000 --- a/testdata/InvalidProject +++ b/testdata/InvalidProject @@ -1 +1 @@ -Subproject commit a2e4a88a59ff6eb6292439ed3c8fcb99b1eb3c51 +Subproject commit 910c1ac24e731b8651a308144e4808fcd9d65a2f diff --git a/testdata/ValidProject b/testdata/ValidProject index d5d4feb..0986450 160000 --- a/testdata/ValidProject +++ b/testdata/ValidProject @@ -1 +1 @@ -Subproject commit d5d4feb502cc27a9c9ea346a3f6943f458c75ea6 +Subproject commit 0986450f7bea2bdf7a25b3a641c15835c576151e From 4abb447e8d07cc4736ea5ae45d107b5e13050c64 Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Wed, 17 Apr 2024 10:47:13 +0900 Subject: [PATCH 3/3] Treat missing meta for special folders --- main_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main_test.go b/main_test.go index d47b809..9de7619 100644 --- a/main_test.go +++ b/main_test.go @@ -62,6 +62,7 @@ func TestInvalid(t *testing.T) { actualStdout := stdout.Captured.String() expectedStdout := `missing Assets/AssetsMissing.meta +missing Assets/Plugins/SpecialFolder.framework.meta missing Assets/SubDir/SubDirFile.meta missing LocalPackages/com.example.local.pkg/LocalPkgMissing.meta missing Packages/com.example.pkg/PkgMissing.meta