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

-reloaddirs option does not work #2829

Closed
smac89 opened this issue Aug 17, 2023 · 5 comments · Fixed by #2871
Closed

-reloaddirs option does not work #2829

smac89 opened this issue Aug 17, 2023 · 5 comments · Fixed by #2871
Labels
Bug Something isn't working

Comments

@smac89
Copy link
Contributor

smac89 commented Aug 17, 2023

Description

When using the -reloaddirs option to specify a folder outside the working directory, the app is not reloaded when any files in those folders change

To Reproduce

  1. mkdir -p /tmp/myproject/common
  2. cd /tmp/myproject && go work init
  3. wails init -n gui -t preact-ts
  4. go work use gui
  5. cd common && go mod init myproject/common
  6. go work use .
  7. touch foo.go
  8. copy the following to foo.go
    package common
    
    import "fmt"
    
    func doSomething() {
        fmt.Println("Something else")
    }
  9. cd /tmp/myproject/gui
  10. wails dev -reloaddirs=/tmp/myproject/common
  11. In a different process, make changes to /tmp/myproject/common/foo.go

Expected behaviour

Changes made to /tmp/myproject/common/foo.go should have caused the watcher to reload, but instead nothing happens

Screenshots

No response

Attempted Fixes

I've tried specifying the reloaddirs option in many ways, but none of them works. I believe the problem is that the variable which contains dirsThatTriggerAReload, found here:

// doWatcherLoop is the main watch loop that runs while dev is active
func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, watcher *fsnotify.Watcher, exitCodeChannel chan int, quitChannel chan os.Signal, devServerURL *url.URL, legacyUseDevServerInsteadofCustomScheme bool) *process.Process {
// Main Loop
var extensionsThatTriggerARebuild = sliceToMap(strings.Split(f.Extensions, ","))
var dirsThatTriggerAReload []string

is not being added to the watcher, therefore none of the changes specified by -reloaddirs option are being detected

System Details

Wails CLI v2.5.1

# System

OS           | ArcoLinux
Version      | Unknown  
ID           | arcolinux
Go Version   | go1.20.5 
Platform     | linux    
Architecture | amd64    

# Wails

Version         | v2.5.1
Package Manager | pacman

# Dependencies

Dependency | Package Name | Status    | Version    
*docker    | docker       | Installed | 1:24.0.5-1 
gcc        | gcc          | Installed | 13.2.1-3   
libgtk-3   | gtk3         | Installed | 1:3.24.38-1
libwebkit  | webkit2gtk   | Installed | 2.40.5-1   
npm        | npm          | Installed | 9.8.1-1    
pkg-config | pkgconf      | Installed | 1.8.1-1    
* - Optional Dependency

# Diagnosis

Your system is ready for Wails development!
 ♥   If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

No response

@smac89 smac89 added the Bug Something isn't working label Aug 17, 2023
@haukened
Copy link
Contributor

@smac89 i also just noticed there is a strange interplay between .gitignore and those directories.
Can you look at #2867 and confirm for me that isn't your issue as well?

If not, I'm happy to take a look at this!

@smac89
Copy link
Contributor Author

smac89 commented Aug 29, 2023

@haukened I don't think so. The directories I'm having problems with are those that exist outside the project directory (but within the go workspace).

As I observed in my attempts to fix the issue, I believe the problem is that extra directories specified with the -reloaddirs option are not being added to the watch list. I haven't had time to fully test this, but that's my theory for now.

@haukened
Copy link
Contributor

haukened commented Aug 29, 2023

Ok, looking at this i can confirm that its a bug. It looks like the *fsnotify.Watcher is never informed of these directories. These exists logic to cause a reload:

for _, reloadDir := range dirsThatTriggerAReload {
    if strings.HasPrefix(itemName, reloadDir) {
        reload = true
        break
    }
}

but without notifying the watcher that this directory exists, the required watcher.Event is never generated.

Currently, they are not even passed to initialize watcher:
func initialiseWatcher(cwd string) (*fsnotify.Watcher, error) {}.

@haukened
Copy link
Contributor

Fixed by #2871

@smac89
Copy link
Contributor Author

smac89 commented Aug 30, 2023

That's awesome! Thanks for your time investigating this.

leaanthony added a commit that referenced this issue Sep 6, 2023
* remove random print statement

* move watcher into loop and implement reloaddirs

* Fixed -reloaddirs for issue #2829

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants