Skip to content

Commit

Permalink
Remove requirement for code checked out into old GOPATH structure (#3409
Browse files Browse the repository at this point in the history
)
  • Loading branch information
travisperson authored Oct 8, 2019
1 parent a5eae72 commit 9126ad8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 56 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
name: Configure environment variables
command: |
echo 'export PATH="/usr/local/go/bin:${HOME}/.cargo/bin:${PATH}:${HOME}/go/bin:${HOME}/.bin"' >> $BASH_ENV
echo 'export GOPATH="${HOME}/go"' >> $BASH_ENV
echo 'export GO111MODULE=on' >> $BASH_ENV
echo 'export FILECOIN_PARAMETER_CACHE="${HOME}/filecoin-proof-parameters/"' >> $BASH_ENV
echo 'export FILECOIN_USE_PRECOMPILED_RUST_PROOFS=yes' >> $BASH_ENV
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ cd ${GOPATH}/src/github.com/filecoin-project/go-filecoin
FILECOIN_USE_PRECOMPILED_RUST_PROOFS=true go run ./build deps
```

Note: The first time you run `deps` can be **slow** as a ~1.6GB parameter file is either downloaded or generated locally in `/tmp/filecoin-proof-parameters`.
Note: The first time you run `deps` can be **slow** as a ~1.6GB parameter file is either downloaded or generated locally in `/var/tmp/filecoin-proof-parameters`.
Have patience; future runs will be faster.

#### Build, Run Tests, and Install
Expand All @@ -122,9 +122,6 @@ Have patience; future runs will be faster.
# First, build the binary
go run ./build build

# Install go-filecoin to ${GOPATH}/bin (necessary for tests)
go run ./build install

# Then, run the unit tests.
go run ./build test

Expand Down
16 changes: 5 additions & 11 deletions fixtures/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ type detailsStruct struct {
}

func init() {
gopath, err := th.GetGoPath()
if err != nil {
panic(err)
}
root := th.ProjectRoot()

detailspath := filepath.Join(gopath, "/src/github.com/filecoin-project/go-filecoin/fixtures/test/gen.json")
detailspath := filepath.Join(root, "fixtures/test/gen.json")
detailsFile, err := os.Open(detailspath)
if err != nil {
// fmt.Printf("Fixture data not found. Skipping fixture initialization: %s\n", err)
Expand Down Expand Up @@ -92,15 +89,12 @@ func init() {

// KeyFilePaths returns the paths to the wallets of the testaddresses
func KeyFilePaths() []string {
gopath, err := th.GetGoPath()
if err != nil {
panic(err)
}
folder := "/src/github.com/filecoin-project/go-filecoin/fixtures/test/"
root := th.ProjectRoot()
folder := filepath.Join(root, "fixtures/test")

res := make([]string, len(testKeys))
for i, k := range testKeys {
res[i] = filepath.Join(gopath, folder, k)
res[i] = filepath.Join(folder, k)
}

return res
Expand Down
12 changes: 6 additions & 6 deletions testhelpers/test_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -757,19 +758,18 @@ func RunInit(td *TestDaemon, opts ...string) ([]byte, error) {
return process.CombinedOutput()
}

// GenesisFilePath returns the path of the WalletFile
// GenesisFilePath returns the path to the test genesis
func GenesisFilePath() string {
return ProjectRoot("/fixtures/test/genesis.car")
}

// ProjectRoot return the project root joined with any path fragments
func ProjectRoot(paths ...string) string {
gopath, err := GetGoPath()
if err != nil {
panic(err)
}
_, currentFile, _, _ := runtime.Caller(0)
dir := filepath.Dir(currentFile)
dir = filepath.Dir(dir)

allPaths := append([]string{gopath, "/src/github.com/filecoin-project/go-filecoin"}, paths...)
allPaths := append([]string{dir}, paths...)

return filepath.Join(allPaths...)
}
Expand Down
26 changes: 2 additions & 24 deletions testhelpers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import (
"fmt"
"net"
"os"
"path/filepath"
"sync"
"time"

"github.com/mitchellh/go-homedir"
)

// GetFreePort gets a free port from the kernel
Expand All @@ -27,21 +24,6 @@ func GetFreePort() (int, error) {
return l.Addr().(*net.TCPAddr).Port, nil
}

// GetGoPath returns the current go path for the user.
func GetGoPath() (string, error) {
gp := os.Getenv("GOPATH")
if gp != "" {
return gp, nil
}

home, err := homedir.Dir()
if err != nil {
return "", err
}

return filepath.Join(home, "go"), nil
}

// MustGetFilecoinBinary returns the path where the filecoin binary will be if it has been built and panics otherwise.
func MustGetFilecoinBinary() string {
path, err := GetFilecoinBinary()
Expand All @@ -54,13 +36,9 @@ func MustGetFilecoinBinary() string {

// GetFilecoinBinary returns the path where the filecoin binary will be if it has been built
func GetFilecoinBinary() (string, error) {
gopath, err := GetGoPath()
if err != nil {
return "", err
}
bin := ProjectRoot("go-filecoin")

bin := filepath.Join(gopath, "/src/github.com/filecoin-project/go-filecoin/go-filecoin")
_, err = os.Stat(bin)
_, err := os.Stat(bin)
if err != nil {
return "", err
}
Expand Down
12 changes: 6 additions & 6 deletions tools/genesis-file-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
"fmt"
"net/http"
"os"
"path/filepath"
)

func main() {
port := flag.Int("port", 0, "port over which to serve genesis file via HTTP")
genesisFilePath := flag.String(
"genesis-file-path",
filepath.Join(os.Getenv("GOPATH"), "src/github.com/filecoin-project/go-filecoin/fixtures/test/genesis.car"),
"port over which to serve genesis file via HTTP\n",
)
genesisFilePath := flag.String("genesis-file-path", "", "full path to the genesis file to be served")
flag.Parse()

if len(*genesisFilePath) == 0 {
fmt.Println("Please specify a genesis to serve")
os.Exit(1)
}

ServeGenesisFileAtPort(*genesisFilePath, *port)
}

Expand Down
7 changes: 3 additions & 4 deletions tools/migration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ func TestOptions(t *testing.T) {
}

func requireGetMigrationBinary(t *testing.T) string {
gopath, err := testhelpers.GetGoPath()
require.NoError(t, err)
root := testhelpers.ProjectRoot()

bin := filepath.Join(gopath, "/src/github.com/filecoin-project/go-filecoin/tools/migration/go-filecoin-migrate")
_, err = os.Stat(bin)
bin := filepath.Join(root, "tools/migration/go-filecoin-migrate")
_, err := os.Stat(bin)
require.NoError(t, err)

return bin
Expand Down

0 comments on commit 9126ad8

Please sign in to comment.