Replace data_generate.go with a proposed use of vfsgen binary. #91
Conversation
Now that I've created Previously, I could only do that for Go package source (via Can you review the proposed API? After taking enough time to reflect, I think I like this now and would like to proceed with finishing the |
Friendly ping, @slimsag. |
} | ||
return p.Dir | ||
} | ||
|
||
// Data is a virtual filesystem that contains template data used by Appdash. | ||
var Data = http.Dir(filepath.Join(defaultBase("sourcegraph.com/sourcegraph/appdash/traceapp/tmpl"), "data")) | ||
var Data = http.Dir(importPathToDir("sourcegraph.com/sourcegraph/appdash/traceapp/tmpl/data")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file change == very good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Although it's not related to the vfsgen binary change, this is just updating this code to the latest version of this pattern. I should've made it a separate PR, that way it could've been merged much sooner (though you're welcome to cherry pick it yourself).
A few questions, @shurcooL, but overall this looks like a good simplification. I really like the direction this is going in! |
@shurcooL everything you said made sense, I agree that my proposal for automatic detection of the var would be a bit magical. I have another proposal:
I wanted to hold off on proposing this to you until I had a chance to confirm that this would be a good idea, but gopherjs/gopherjs#369 has reconfirmed my thoughts that it might be good. This would make the I can now point to one of my personal projects, appdash, and gopherjs all as potential users of the vfsgen binary and wanting to use the above defaults. What do you think on this? |
Also, note that I do think this is a good change. We can move forward with this current approach now if you'd like and continue discussing the default parameters elsewhere. |
I like the idea and agree, it would work for all my current needs/uses of vfsgen too. However, I don't like the idea of mixing up general purpose flags with opinionated and convention-driven ones. I discussed it with @slimsag on Slack and we converged taking the idea of making For general purpose/custom needs, I'll update the PR to have this API then: -//go:generate vfsgen -tags=dev -source="sourcegraph.com/sourcegraph/appdash/traceapp/tmpl".Data -output-tags=!dev
+//go:generate vfsgendev -source="sourcegraph.com/sourcegraph/appdash/traceapp/tmpl".Data
|
Add an opinionated binary for specialized use. It uses the convention of using "dev" build tag for development mode, and assumes that the source VFS is defined in a "dev" only environment; it uses "!dev" build tag in output .go file. Usage is simple: vfsgendev -source="import/path".VariableName See sourcegraph/appdash#91 for additional background, motivation, and discussion. Resolves #2. Closes #14.
PTAL, this is the final API, and it's fully functional. You will need the |
CI is failing on Go 1.3, 1.4, succeeding on tip. Looks completely unrelated to this change (this change affects generate time, not build or run time). |
re: CI failing -- yeah, I don't know what that was about, but it's passing now: https://travis-ci.org/sourcegraph/appdash/builds/99542211 If I see it happen again I'll look into it further. |
Some TODOs before merging:
LVGTM. Thank you for this, @shurcooL. |
Get rid of filepath.Join since it's avoidable. Rename defaultBase to a more descriptive name.
Advantage is that code is more succinct (less boilerplate). Disadvantage is that you now need to install vfsgendev binary to be able to run go generate. Previously, only the vfsgen library was required. Behavior is unchanged.
Sure. Done. |
Also done! |
Sorry for the delay! I thought I had merged this when you wrote your comment above. LGTM |
Replace data_generate.go with a proposed use of vfsgen binary.
This change makes use of a new
vfsgendev
command-line tool in order to embed the static assets instead of the olddata_generate.go
file.For more information, see shurcooL/vfsgen#16