How to install local Go git repos for testing?

agolangf · · 439 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve got a lib, <a href="https://github.com/mcandre/go-ios7crypt" rel="nofollow">https://github.com/mcandre/go-ios7crypt</a>, with an accompanying command line tool, <a href="https://github.com/mcandre/go-ios7crypt/tree/master/cmd/ios7crypt" rel="nofollow">https://github.com/mcandre/go-ios7crypt/tree/master/cmd/ios7crypt</a>, that I like to hack on.</p> <p>I often want to tweak the code, rebuild the library, rebuild the command line binary, install, and try out the command line binary. I&#39;ve been pushing commits to GitHub and <code>go get -u github.com/mcandre/go-ios7crypt &amp;&amp; go install github.com/mcandre/go-ios7crypt/cmd/ios7crypt</code> for every little change, and it&#39;s not fun.</p> <p>Are there more better<code>go</code>... commands I can use to rebuild and reinstall my stuff directly from my local git repo checkout, rather than pushing my stuff to GitHub first?</p> <hr/>**评论:**<br/><br/>djherbis: <pre><p>If you are modifying your code under: $GOPATH/src/github/mcandre/go-ios7crypt</p> <p>Then go install github.com/mcandre/go-ios7crypt/cmd/ios7crypt is using your local lib. You shouldn&#39;t have to go get every time, if the changes are already being made locally.</p></pre>mcandre: <pre><p>For reasons, I prefer not to keep all my projects in $GOPATH. Could I soft link or something?</p></pre>TheMerovius: <pre><p>Your reasons are probably bad reasons.</p> <p>Nevertheless, yes, you can create symlinks from wherever you are keeping your code into the appropriate $GOPATH directory. You&#39;ll still want to develop from there, because otherwise go treats this as an out-of-tree build (as it looks at <code>.</code>) which might have undesirable side-effects.</p> <p>Really, if you don&#39;t want to fight with the tooling, you shouldn&#39;t fight with the tooling and just use $GOPATH the way as it was intended.</p></pre>mcandre: <pre><blockquote> <p>if you don&#39;t want to fight with the tooling</p> </blockquote> <p>Too late. Go&#39;s tooling has gotten much better than it once was (remember when we had to use multiple Makefiles to compile Go code, before <code>go build</code> was a thing?) However, Go should reexamine how it checks whether a directory is &#34;in&#34; $GOPATH. Simply expanding GOPATH into an absolute path and testing whether cwd is a direct child of GOPATH excludes symlinks, i.e., the tooling is fighting tried-and-true Unix file system standards.</p> <p>I wouldn&#39;t even be <em>discussing</em> soft links and other hacks in the context of other programming languages, because other package managers like NPM don&#39;t require such nonsense. <em>Go</em> is the problem here.</p></pre>mixedCase_: <pre><p>Soft linking isn&#39;t a hack. It&#39;s a unix tool like any other.</p> <p>I can access all my projects at $HOME/code but many of them exist in a different place, including all the Go code I touch which lie in a $HOME/.go folder.</p> <p>NPM has its own downsides, and if you want NPM&#39;s way of dealing with things you vendor absolutely everything and stop complaining about go getting stuff.</p></pre>mcandre: <pre><p>Hmm, maybe my symlinks are misconfigured in Windows. Do I need to use a junction? Anyone have success symlinking local git repo directories into GOPATH in Windows?</p></pre>ohaiyou_meepo_desu: <pre><blockquote> <p>Your reasons are probably bad reasons.</p> </blockquote> <p>I don&#39;t like how Go treats me like I&#39;m retarded in that sense. Go is a cruel, but very enjoyable mistress.</p></pre>djherbis: <pre><p>I always just use GOPATH, but maybe <a href="https://getgb.io/" rel="nofollow">gb</a> would help?</p></pre>mcandre: <pre><blockquote> <p>gb projects can be retrieved using go get, but cannot be built by the go tool as they do not follow the convention required by go get.</p> </blockquote> <p><a href="https://getgb.io/docs/project/" rel="nofollow">https://getgb.io/docs/project/</a></p> <p>Worrisome.</p></pre>djherbis: <pre><p>Go is opinionated about how things are done. They may not always be what&#39;s &#34;best&#34; by your standard, but if you do them the Go way, they will work easily within the Go setup.</p> <p>You can&#39;t really get the best of both worlds with this, you either have to use GOPATH, and have go get work they way you want. Or use a package manager (like gb) and do things their way.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

439 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传