go.rice icon indicating copy to clipboard operation
go.rice copied to clipboard

rice 2.0: move away from source parsing and use a Ricefile?

Open GeertJohan opened this issue 10 years ago • 7 comments

"Rice 2.0? But 1.0 hasn't even been released yet!?" Correct. Please see #48 about that.

Dropping .go file source parsing I've been thinking about this for a while now. The parsing of go source is a nice feature, but doesn't always work as expected:

const boxName = `someBox`
rice.FindBox(boxName) // will work in 'live' mode, but rice tool won't find this box so it isn't embedded/appended.

This can be solved by moving the configuration of boxes to a Ricefile; a config file in some human-readable format such as yaml. This also allows us to define more configuration parameters per box such as:

  • strategy: embed vs append (embed one box, append the other).
  • path different than box name

Ricefile should be located in main package for the binary, but can include boxes used in sub-packages. Ricefile import other Ricefiles based on import path? This could make defining resources in packages a feasible reality.

This issue is a work in progress..

GeertJohan avatar Feb 03 '15 14:02 GeertJohan

The current rice tool cannot use build tags, another reason to move away from source analysis and towards a configuration file for boxes.

GeertJohan avatar Feb 10 '15 10:02 GeertJohan

Appears the current rice tool fails when multiple packages live in the same directory too.

burdges avatar Mar 26 '15 20:03 burdges

multiple packages in the same directory? That should never happen right? (maybe exceptionally when one package has -buildflag and the other has +buildflag). @burdges

GeertJohan avatar Mar 26 '15 21:03 GeertJohan

Appears not. At least, it does not happen where I once thought I'd seen it happen, thanks!

burdges avatar Mar 26 '15 22:03 burdges

There's another reason to do this - FindBox calls in global scope will work until the user uses embed-go, at which point it will fail, since variables are initialized before the init() functions are called. This has already confused people, as in issue #67.

cortesi avatar Oct 20 '15 22:10 cortesi

I just needed to implement the ability for rice to append boxes without access to source files. Only just noticed this issue after I've finished, sorry about that. I've implemented slightly differently ..

If you're in a directory that has only the box contents but no source, you can run this:

rice appendbox --exec <executable> -b <box1> [ -b <box2> ]

See https://github.com/boyvinall/go.rice/commit/appendbox

boyvinall avatar Nov 23 '16 17:11 boyvinall

@boyvinall I also came across this issue after having problems with source parsing. I implemented it similarly on the command line here - https://github.com/JonathanTech/go.rice/pull/1 . I added it as a separate command instead.

rice append-simple -b <box1> [-b <box2>] --exec <executable>

JonathanTech avatar Jun 20 '17 14:06 JonathanTech