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

Fixed an issue where go:embed directives would generate illegal directories #3445

Conversation

TwoNull
Copy link
Contributor

@TwoNull TwoNull commented Apr 28, 2024

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 by CreateEmbedDirectories in v2/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 in CreateEmbedDirectories 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.

  • Bug fix (non-breaking change which fixes an issue)

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.

  • Windows
  • macOS
  • Linux

Test Configuration

Version  | v2.8.1                                  
Revision | b5e72633267e69e83eb0663a9f35e79b364da5e7
Modified | false                                   

# System
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | MacOS                                                                                                                                                                                                                                                                                                                                            |
| Version      | 12.6                                                                                                                                                                                                                                                                                                                                             |
| ID           | 21G115                                                                                                                                                                                                                                                                                                                                           |
| Go Version   | go1.21.5                                                                                                                                                                                                                                                                                                                                         |
| Platform     | darwin                                                                                                                                                                                                                                                                                                                                           |
| Architecture | arm64                                                                                                                                                                                                                                                                                                                                            |
| CPU          | Apple M1                                                                                                                                                                                                                                                                                                                                         |
| GPU          | Chipset Model: Apple M1 Type: GPU Bus: Built-In Total Number of Cores: 8 Vendor: Apple (0x106b) Metal Family: Supported, Metal GPUFamily Apple 7 Displays: Color LCD: Display Type: Built-In Retina LCD Resolution: 2560 x 1600 Retina Main Display: Yes Mirror: Off Online: Yes Automatically Adjust Brightness: No Connection Type: Internal   |
| Memory       | 8GB                                                                                                                                                                                                                                                                                                                                              |
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌──────────────────────────────────────────────────────────────────────┐
| Dependency                | Package Name | Status    | Version       |
| Xcode command line tools  | N/A          | Installed | 2395          |
| Nodejs                    | N/A          | Installed | 18.17.1       |
| npm                       | N/A          | Installed | 9.6.7         |
| *Xcode                    | N/A          | Installed | 14.0 (14A309) |
| *upx                      | N/A          | Available |               |
| *nsis                     | N/A          | Available |               |
└────────────────────── * - Optional Dependency ───────────────────────┘

# Diagnosis
Optional package(s) installation details: 
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@TwoNull TwoNull marked this pull request as ready for review April 28, 2024 21:01
@TwoNull TwoNull changed the title Fixed an issue where go:embed comments would generate illegal directories Fixed an issue where go:embed directives would generate illegal directories Apr 28, 2024
Copy link
Member

@leaanthony leaanthony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for this!

@leaanthony leaanthony merged commit b7713da into wailsapp:master May 2, 2024
8 checks passed
@TwoNull TwoNull deleted the bugfix/3436_wails-build-creating-invalid-folders-based-on-embed branch May 3, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wails build creating invalid folders based on embed file selections. Then failing.
2 participants