Fixed an issue where go:embed directives would generate illegal directories #3445
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.
Description
This PR fixes an issue where valid go:embed directives containing patterns instead of relative paths would result in illegal directories being created. The issue lies in
v2/internal/staticanalysis/staticanalysis.go
, where wails iterates through go:embed comments independently of the compiler. This list of embedded paths are read byCreateEmbedDirectories
inv2/pkg/commands/build/build.go
to create embedded directories if they don't exist.I modified staticanalysis.go's
GetEmbedDetailsForFile
to check for the pattern matching characters used by filepath, excluding the escape character which may flag valid windows paths by accident. These paths are ignored. I also added a check inCreateEmbedDirectories
to make sure the directory being created has no extension.I also added an iterator to
GetEmbedDetailsForFile
for the case that multiple paths are declared in a single comment.The tests in
staticanalysis_test.go
now check for these additional edge cases of go:embed comments.Fixes #3436
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using
wails doctor
.I added additional embed comments for these edge cases to the example project staticanalysis_test.go uses.
Test Configuration
Checklist:
website/src/pages/changelog.mdx
with details of this PR