2017-08-19 77 views
1

我想为使用go构建的OSS项目做出贡献,但我很难编译它。看起来好像我失去了一些明显的东西。无法构建开源项目

我认为这个问题与我的电脑上安装的go而不是项目本身有关,因此我将它发布到StackOverflow上,而不是项目的“问题”部分。

以下是我正在做的事情。

  1. 我使用homebrew安装go

    $ brew install go 
    Updating Homebrew... 
    ==> Auto-updated Homebrew! 
    Updated 1 tap (homebrew/core). 
    ==> Updated Formulae 
    libebml 
    
    ==> Downloading https://homebrew.bintray.com/bottles/go-1.8.3.sierra.bottle.tar.gz 
    Already downloaded: /Users/gmile/Library/Caches/Homebrew/go-1.8.3.sierra.bottle.tar.gz 
    ==> Pouring go-1.8.3.sierra.bottle.tar.gz 
    ==> Caveats 
    A valid GOPATH is required to use the `go get` command. 
    If $GOPATH is not specified, $HOME/go will be used by default: 
        https://golang.org/doc/code.html#GOPATH 
    
    You may wish to add the GOROOT-based install location to your PATH: 
        export PATH=$PATH:/usr/local/opt/go/libexec/bin 
    ==> Summary 
        /usr/local/Cellar/go/1.8.3: 7,035 files, 282.0MB 
    $ 
    
  2. 然后我克隆回购:

    $ hub clone lucapette/fakedata 
    
  3. 我跑make setup(每条指令),起初没成功完成:

    $ make setup 
    go get -u github.com/alecthomas/gometalinter 
    gometalinter --install 
    make: gometalinter: No such file or directory 
    make: *** [setup] Error 1 
    $ 
    

    我想这是因为gometalinter是无处我$PATH,因此增加了它(我使用fish-shell):

    $ set fish_user_paths /Users/gmile/go/bin 
    
  4. 运行make setup现在似乎已经成功。这是输出:

    $ make setup 
    go get -u github.com/alecthomas/gometalinter 
    gometalinter --install 
    Installing: 
        aligncheck 
        deadcode 
        dupl 
        errcheck 
        gas 
        goconst 
        gocyclo 
        goimports 
        golint 
        gosimple 
        gotype 
        ineffassign 
        interfacer 
        lll 
        megacheck 
        misspell 
        safesql 
        staticcheck 
        structcheck 
        unconvert 
        unparam 
        unused 
        varcheck 
    $ 
    
  5. 运行make build失败

    $ make build 
    go build 
    main.go:11:2: cannot find package"github.com/lucapette/fakedata/pkg/fakedata" in any of: 
         /usr/local/Cellar/go/1.8.3/libexec/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOROOT) 
         /Users/gmile/go/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOPATH) 
    main.go:12:2: cannot find package "github.com/spf13/pflag" in any of: 
         /usr/local/Cellar/go/1.8.3/libexec/src/github.com/spf13/pflag (from $GOROOT) 
         /Users/gmile/go/src/github.com/spf13/pflag (from $GOPATH) 
    make: *** [build] Error 1 
    $ 
    

因此,无论Contributing方针是不完整的,或者说我缺少明显的东西有关安装和管理去包。

回答

5

你当克隆源必须在golang PATH路径一样: /home/gujarat/golang/src/github.com/lucapette/fakedata

,你可以看到我的路径golang路径是:/home/gujarat/golang/。 您也可以输入以下内容在您的终端中打印您的golang路径:$GOPATH

git clone应该与上面的路径一致:src/github.com/lucapette/

cd $GOPATH/src/github.com/ 
mkdir lucaptte 
cd lucapette 
git clone https://github.com/lucapette/fakedata.git 

当您运行make命令,它触发go build这个命令会看$GOPATH和你$GOROOT文件夹。

+0

谢谢!这有帮助。 – gmile

0

你的源代码应该在你的gopath - 这里是Users/gmile/src。使用go get取得你想要工作的pkg,它应该可以工作。