Skip to content

Commit

Permalink
assets: move away from gx
Browse files Browse the repository at this point in the history
1. Use a submodule for dir-index-html. This isn't a go dependency and treating
   it like one is more trouble than it's worth. We don't actually need to
   checkout the submodule unless we need to regenerate the assets.
2. Avoid a runtime dependency on dir-index-html (may shave a few bytes off the
   final binary?).
3. Remove unused code.
4. Avoid bundling unused files.
5. Switch to a maintained version of go-bindata.
6. Use go mod to manage go-bindata.
  • Loading branch information
Stebalien committed Jun 6, 2019
1 parent f72ae26 commit b60053e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 167 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "assets/dir-index-html"]
path = assets/dir-index-html
url = [email protected]:ipfs/dir-index-html
3 changes: 1 addition & 2 deletions assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ Instead, edit the source files and use `go generate` from within the
assets directory:

```
go get -u github.com/jteeuwen/go-bindata/...
go generate
go generate .
```
18 changes: 2 additions & 16 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//go:generate go-bindata -pkg=assets -prefix=$GOPATH/src/gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV init-doc $GOPATH/src/gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV/dir-index-html
//go:generate git submodule update --init ./dir-index-html
//go:generate go run github.com/go-bindata/go-bindata/go-bindata -pkg=assets init-doc dir-index-html/dir-index.html dir-index-html/knownIcons.txt
//go:generate gofmt -w bindata.go

package assets

import (
"fmt"
"os"
"path/filepath"

"github.com/ipfs/go-ipfs/core"
Expand All @@ -15,9 +14,6 @@ import (
files "github.com/ipfs/go-ipfs-files"
options "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"

// this import keeps gx from thinking the dep isn't used
_ "github.com/ipfs/dir-index-html"
)

// initDocPaths lists the paths for the docs we want to seed during --init
Expand All @@ -36,16 +32,6 @@ func SeedInitDocs(nd *core.IpfsNode) (cid.Cid, error) {
return addAssetList(nd, initDocPaths)
}

var initDirPath = filepath.Join(os.Getenv("GOPATH"), "gx", "ipfs", "QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV", "dir-index-html")
var initDirIndex = []string{
filepath.Join(initDirPath, "knownIcons.txt"),
filepath.Join(initDirPath, "dir-index.html"),
}

func SeedInitDirIndex(nd *core.IpfsNode) (cid.Cid, error) {
return addAssetList(nd, initDirIndex)
}

func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
api, err := coreapi.NewCoreAPI(nd)
if err != nil {
Expand Down
8 changes: 0 additions & 8 deletions assets/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ func TestEmbeddedDocs(t *testing.T) {
testNFiles(initDocPaths, 5, t, "documents")
}

func TestDirIndex(t *testing.T) {
t.Skip("skipping for now, code being tested is currently unused")
// TODO: import assets during init.
// this will require figuring out how to set the right paths up for
// referencing the code from its gx path
testNFiles(initDirIndex, 2, t, "assets")
}

func testNFiles(fs []string, wantCnt int, t *testing.T, ftype string) {
if len(fs) < wantCnt {
t.Fatalf("expected %d %s. got %d", wantCnt, ftype, len(fs))
Expand Down
170 changes: 32 additions & 138 deletions assets/bindata.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions assets/bindata_dep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//+build never,!never
package assets

import (
// Make sure go mod tracks these deps but avoid including them in the
// actual build.
_ "github.com/go-bindata/go-bindata"
)
1 change: 1 addition & 0 deletions assets/dir-index-html
Submodule dir-index-html added at a2330d
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ require (
github.com/elgris/jsondiff v0.0.0-20160530203242-765b5c24c302
github.com/fatih/color v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.4.7
github.com/go-bindata/go-bindata v3.1.1+incompatible
github.com/go-critic/go-critic v0.0.0-20181204210945-ee9bf5809ead // indirect
github.com/gogo/protobuf v1.2.1
github.com/golangci/golangci-lint v1.16.1-0.20190425135923-692dacb773b7
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/golang-lru v0.5.1
github.com/hsanjuan/go-libp2p-http v0.1.0
github.com/ipfs/dir-index-html v1.0.3
github.com/ipfs/go-bitswap v0.1.1
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-blockservice v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-bindata/go-bindata v3.1.1+incompatible h1:tR4f0e4VTO7LK6B2YWyAoVEzG9ByG1wrXB4TL9+jiYg=
github.com/go-bindata/go-bindata v3.1.1+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-critic/go-critic v0.0.0-20181204210945-c3db6069acc5/go.mod h1:Jc75BZJv2dNy7opKH6bF29VveDQHfGZ6Asn/3phBesg=
Expand Down Expand Up @@ -189,8 +191,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ipfs/bbloom v0.0.1 h1:s7KkiBPfxCeDVo47KySjK0ACPc5GJRUxFpdyWEuDjhw=
github.com/ipfs/bbloom v0.0.1/go.mod h1:oqo8CVWsJFMOZqTglBG4wydCE4IQA/G2/SEofB0rjUI=
github.com/ipfs/dir-index-html v1.0.3 h1:cKdOjJBKJgewgcv97zOlqsNOle52N91d3nAkbQadnuY=
github.com/ipfs/dir-index-html v1.0.3/go.mod h1:TG9zbaH/+4MnkGel0xF4SLNhk+YZvBNo6jjBkO/LaWc=
github.com/ipfs/go-bitswap v0.0.3/go.mod h1:jadAZYsP/tcRMl47ZhFxhaNuDQoXawT8iHMg+iFoQbg=
github.com/ipfs/go-bitswap v0.0.9/go.mod h1:kAPf5qgn2W2DrgAcscZ3HrM9qh4pH+X8Fkk3UPrwvis=
github.com/ipfs/go-bitswap v0.1.0 h1:28YsHYw9ut6wootnImPXH0WpnU5Dbo3qm6cvQ6e6wYY=
Expand Down

0 comments on commit b60053e

Please sign in to comment.