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

"no calls to rice.FindBox() found" when using const for directory #18

Closed
cryptix opened this issue Jul 24, 2014 · 9 comments
Closed

"no calls to rice.FindBox() found" when using const for directory #18

cryptix opened this issue Jul 24, 2014 · 9 comments

Comments

@cryptix
Copy link

cryptix commented Jul 24, 2014

Hi,
when using const for directories to embed, like this:

package main

import (
    "fmt"

    "github.com/GeertJohan/go.rice"
)

const weirdTmp = "/tmp/weird"

func main() {
    constDir := rice.MustFindBox(weirdTmp)
    fmt.Println("constDir:", constDir)
}

This happens:

[cryptix@planc /tmp/tmp] rice -v embed-go
2014/07/24 11:10:04 using pwd as import path
2014/07/24 11:10:04 using import path: .
2014/07/24 11:10:04 scanning file "/tmp/tmp/repro.go"
no calls to rice.FindBox() found
2014/07/24 11:10:04 
2014/07/24 11:10:04 rice finished successfully

While this works as expected:

package main

import (
    "fmt"

    "github.com/GeertJohan/go.rice"
)

func main() {
    constDir := rice.MustFindBox("/tmp/weird")
    fmt.Println(dir:", constDir)
}
@GeertJohan
Copy link
Owner

Indeed. This is because right now the rice tool uses a regular expression over the code to locate calls to FindBox and MustFindBox. As mentioned in the readme under TODO: this should be changed to go/ast or maybe go.tools/oracle. I think go.tools/oracle is the best option, but it is not finished yet afaik.

@GeertJohan
Copy link
Owner

I'll keep this issue open until the problem is resolved.

@cryptix
Copy link
Author

cryptix commented Jul 29, 2014

I went a bit crazy over this one because I always wanted to try out go/ast so I took this chance.
This playground shows my progress so far.

It finds Call Expressions to rice.MustFindBox and rice.FindBox and tries to find values for the first argument. It so far works for basic literals (either in-line or declared as global const or var) but I haven't tried further for concat's other constructs.

How do you feel about this? I'd like to get more usage tests and I'm not sure if the name of the bux is enough. If you like it, it would be great if you could point me to where the rice tool does it's magic and I'd clean this up and prepare a first PR.

ps: Here is a copy of the playground as a gist, just in case.

@cryptix
Copy link
Author

cryptix commented Jul 29, 2014

Oh, i forgot to give the proper credits: I took some inspiration from golint's code (mainly the walker construction because I thought i need to call ast.Walk more often) and goast-viewer was really helpful as well.

@GeertJohan
Copy link
Owner

Hi cryptix,
Sorry for replying so late here, I'm afraid I totally forgot to reply..

Do you still have plans to work this out for rice? I'd be very interested if consts would work.
I think allowing var's is more work and should create a warning (PR #30)

@GeertJohan
Copy link
Owner

I'm thinking of dropping source analysis in rice 2.0 Please see #47

@GeertJohan
Copy link
Owner

I dont think this can be fixed in this version of rice.

@cryptix
Copy link
Author

cryptix commented Feb 12, 2015

wow.. How time flies sometimes is incredible.

Feel free to close, my purposeful was more of a proof of concept anyway.

@GeertJohan
Copy link
Owner

Yes, very fast. Take a look at #47 if you like, maybe you have some good idea's for it :)

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

No branches or pull requests

2 participants