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

Use vfsgen to statically embed template data. #84

Merged
merged 2 commits into from
Sep 21, 2015
Merged

Use vfsgen to statically embed template data. #84

merged 2 commits into from
Sep 21, 2015

Conversation

dmitshur
Copy link
Contributor

  • Remove deprecated Makefile build process.
  • Replace use of go-bindata with vfsgen for embedding template data. As a side effect, this removes the need to gofmt the generated output.
  • Move go generate directives into ./traceapp/tmpl package, since that's the only package they affect.

Rationale

Reasons for switching to vfsgen include:

  • Consistency across all Sourcegraph code bases.
    • Other projects need vfsgen for its additional functionality, and it's good to use the same tool for this task.
  • Ability to easily enable gzipped compression efficiently in the future.
  • No need for a follow-up go fmt ./... after regeneration.
  • Usage of http.FileSystem directly matches the needs of this project (bonus of being done in one package instead of across two separately maintained packages).

@dmitshur
Copy link
Contributor Author

I've tried to keep the filenames unchanged to make it easier to review.

traceapp/tmpl/data_src.go is still the // +build dev live disk reload version, but it's a much smaller file now because it simply uses http.Dir. It defines an Assets var, and that's what's used in dev mode, as well as by vfsgen during go generate to generate data.go file.

traceapp/tmpl/data.go is still the // +build !dev go generated static embedded version, but it's now generated with vfsgen.

@dmitshur
Copy link
Contributor Author

Travis CI is failing, but not sure if that's related to my changes or external. The last master build was successful, but it was 12 days ago. Can someone with access restart CI to check if master is still passing?

@dmitshur
Copy link
Contributor Author

It turns out Travis is passing on master even now, so this appears to be a legitimate failure due to my changes in this PR. I'll try to see what the cause could be.

@slimsag
Copy link
Member

slimsag commented Sep 21, 2015

@shurcooL I suspect perhaps the filepaths have changed somehow, but can't say for certain

@slimsag
Copy link
Member

slimsag commented Sep 21, 2015

On second thought, this appears unrelated to your change. Running master locally (go test -v ./...) produces the same test failures for me.

@dmitshur
Copy link
Contributor Author

The Makefile that was in the root folder previous to being removed in this PR was causing Travis not to run tests at all, that's why it succeeded.

See the bottom of https://travis-ci.org/sourcegraph/appdash/jobs/79379987 output:

The command "make" exited with 0.

Done. Your build exited with 0.

slimsag added a commit that referenced this pull request Sep 21, 2015
These tests were failing (but not reported by Travis due to the Makefile,
soon to be removed by #84) due to the fact that the keys
changed previously and are now prefixed with Server/Client for easy
differentiation in the web UI.
@slimsag
Copy link
Member

slimsag commented Sep 21, 2015

@shurcooL I've merged #85 in, please rebase so we can see whether or not that fixed the issue :)

Remove deprecated Makefile build process.

Replace use of go-bindata with vfsgen for embedding template data. As a
side effect, this removes the need to gofmt the generated output.

Move go generate directives into ./traceapp/tmpl package, since that's
the only package they affect.
@dmitshur
Copy link
Contributor Author

Done, and it's green now.

return fmt.Errorf("template %v: %s", set, err)
}
tmplBytes, err := ioutil.ReadAll(tmplFile)
tmplFile.Close()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an observation, if this were my codebase, I would use a helper similar to ioutil.ReadFile but for virtual filesystems:

vfsutil.ReadFile

tmplBytes, err := vfsutil.ReadFile(tmpl.Assets, "/" + tmp)
...

Then the number of lines would not increase here. But I figured it's not worth pulling in an extra package just to replace a standard library package and 4 extra lines of standard code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that would make sense if we did it in more than a few places -- but IMO it's a bit easier to read these standard lines rather than not strictly knowing what vfsutil.ReadFile (despite obvious name) does.

@slimsag
Copy link
Member

slimsag commented Sep 21, 2015

LGTM

slimsag added a commit that referenced this pull request Sep 21, 2015
Use vfsgen to statically embed template data.
@slimsag slimsag merged commit ca4a741 into sourcegraph:master Sep 21, 2015
@dmitshur dmitshur deleted the use-vfsgen-for-tmpl branch September 21, 2015 22:32
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.

2 participants