Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Replace data_generate.go with a proposed use of vfsgen binary. #91

Merged
merged 2 commits into from Jan 11, 2016
Merged

Replace data_generate.go with a proposed use of vfsgen binary. #91

merged 2 commits into from Jan 11, 2016

Conversation

dmitshur
Copy link
Contributor

This change makes use of a new vfsgendev command-line tool in order to embed the static assets instead of the old data_generate.go file.

  • The tool is opinionated and designed specifically for use cases like ours here.
  • New behavior is identical to the old behavior.

For more information, see shurcooL/vfsgen#16

@dmitshur
Copy link
Contributor Author

dmitshur commented Dec 8, 2015

Now that I've created binstale, I feel more comfortable requiring the use of a vfsgen binary, because I can now ensure it's the latest non-stale version before running go generate.

Previously, I could only do that for Go package source (via gostatus command).

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 vfsgen binary implementation.

@dmitshur
Copy link
Contributor Author

Can you review the proposed API?

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"))
Copy link
Member

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.

Copy link
Contributor Author

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).

@slimsag
Copy link
Member

slimsag commented Dec 25, 2015

A few questions, @shurcooL, but overall this looks like a good simplification. I really like the direction this is going in!

@slimsag
Copy link
Member

slimsag commented Dec 30, 2015

@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:

  • Make the default for -output-tags be -output-tags=!dev.
  • Make the default for -tags be -tags=dev.

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 vfsgen binary a developer-first oriented tool, i.e. assume that you'll always want a dev and non-dev VFS. In my experience, I always want this -- and in the cases that I do not use this feature it is because it is hard to set up and I don't need it that badly.

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?

@slimsag
Copy link
Member

slimsag commented Dec 30, 2015

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.

@dmitshur
Copy link
Contributor Author

This would make the vfsgen binary a developer-first oriented tool, i.e. assume that you'll always want a dev and non-dev VFS. In my experience, I always want this -- and in the cases that I do not use this feature it is because it is hard to set up and I don't need it that badly.

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?

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 vfsgen binary even more opinionated, simple to use, and developer-oriented. We'll call it vfsgendev to indicate that it's not a general purpose and convention-agnostic tool. Instead, it will focus on solving the most common use case well and being as friendly/easy to use as possible.

For general purpose/custom needs, vfsgen the Go library can still be used. Let's see how vfsgendev works out and go from there.

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

vfsgendev will not have any other flags. I think -source is all it'll need.

dmitshur added a commit to shurcooL/vfsgen that referenced this pull request Dec 31, 2015
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.
@dmitshur
Copy link
Contributor Author

PTAL, this is the final API, and it's fully functional.

You will need the vfsgendev binary in your GOPATH to run go generate. It'll be generally available after shurcooL/vfsgen#16 is merged.

@dmitshur
Copy link
Contributor Author

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).

@slimsag
Copy link
Member

slimsag commented Dec 31, 2015

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.

@slimsag
Copy link
Member

slimsag commented Dec 31, 2015

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.
@dmitshur
Copy link
Contributor Author

Squash into just two commits, as history is a bit polluted. Can you do this @shurcooL ?

Sure. Done.

@dmitshur
Copy link
Contributor Author

dmitshur commented Jan 1, 2016

Merge shurcooL/vfsgen#16

Also done!

@slimsag
Copy link
Member

slimsag commented Jan 11, 2016

Sorry for the delay! I thought I had merged this when you wrote your comment above.

LGTM

slimsag added a commit that referenced this pull request Jan 11, 2016
Replace data_generate.go with a proposed use of vfsgen binary.
@slimsag slimsag merged commit 84f0569 into sourcegraph:master Jan 11, 2016
@dmitshur dmitshur deleted the try-using-vfsgen-binary branch January 11, 2016 04:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants