Skip to content
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

Ignore special folder contents #32

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions unity/metanecessity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type MetaNecessity func(targetPath typedpath.SlashPath) bool

const AssetsDirBaseName typedpath.BaseName = "Assets"

func NewMetaNecessityInUnityProject(pkgPaths []typedpath.SlashPath) MetaNecessity {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
40 changes: 34 additions & 6 deletions unity/metanecessity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
},
}

Expand Down
Loading