<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Tools on Roberto Selbach</title><link>https://rselbach.com/tags/tools/</link><description>Recent content in Tools on Roberto Selbach</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Thu, 29 Mar 2012 19:25:00 +0000</lastBuildDate><atom:link href="https://rselbach.com/tags/tools/index.xml" rel="self" type="application/rss+xml"/><item><title>Go 1 and the go command</title><link>https://rselbach.com/go-1-and-the-go-command/</link><pubDate>Thu, 29 Mar 2012 19:25:00 +0000</pubDate><guid>https://rselbach.com/go-1-and-the-go-command/</guid><description>&lt;p&gt;Go 1 was released yesterday, so I took a small command-line programme out of its old build script and built it using only the new &lt;code&gt;go&lt;/code&gt; command. The script did not put up much of a fight, which is usually a sign it had been waiting to retire.&lt;/p&gt;
&lt;p&gt;From the package directory, the common operations are direct:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ go build
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ go test
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ go install
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;go build&lt;/code&gt; compiles the package and its dependencies. &lt;code&gt;go test&lt;/code&gt; builds and runs tests associated with it. &lt;code&gt;go install&lt;/code&gt; places the resulting command or package object where the Go workspace expects it. Supplying an import path performs the same operation without first entering the directory.&lt;/p&gt;
&lt;p&gt;The surprise was how much information the tool obtains from ordinary source. Import declarations already form the dependency graph. File names and build constraints identify operating-system or architecture variants. Package declarations establish the compilation unit. A separate build description for pure Go would repeat facts the compiler must know anyway.&lt;/p&gt;
&lt;p&gt;This is not merely a shorter compiler command. The tool chooses and invokes the appropriate compiler, assembler, and linker, tracks dependencies, and gives packages a common vocabulary. That standard shape makes instructions from another project more useful: &lt;code&gt;go test&lt;/code&gt; means the same kind of operation there as it does here.&lt;/p&gt;
&lt;p&gt;I prefer package paths over lists of files. Building individual files can accidentally omit another file in the same package or bypass the conditions the package author expected. The package is the unit Go code is designed around, so it should also be the ordinary unit of building and testing.&lt;/p&gt;
&lt;p&gt;There are caveats. cgo packages still bring a C toolchain and external libraries into the picture. Code generation and non-Go assets do not disappear because a pleasant command exists. The &lt;code&gt;go&lt;/code&gt; command is deliberately opinionated, so a project that fights the package layout will not win by adding more shell around it.&lt;/p&gt;
&lt;p&gt;The compatibility promise gives this tooling more weight. Go 1 source should remain source-compatible with later Go 1 releases, subject to the documented boundaries, while implementations improve underneath. That makes the command a stable front door rather than this week&amp;rsquo;s preferred route through the compiler tools.&lt;/p&gt;
&lt;p&gt;My programme now builds with three unsurprising commands and no custom dependency list. Build engineering has not ended, but it has lost one excellent hiding place.&lt;/p&gt;</description></item><item><title>One tool for Go packages</title><link>https://rselbach.com/one-tool-for-go-packages/</link><pubDate>Wed, 07 Mar 2012 17:50:00 +0000</pubDate><guid>https://rselbach.com/one-tool-for-go-packages/</guid><description>&lt;p&gt;I moved a test package this morning and expected to edit a build script. The &lt;code&gt;go&lt;/code&gt; tool in a Go 1 development snapshot found the source by package path and did the ordinary work itself.&lt;/p&gt;
&lt;p&gt;The basic loop is almost suspiciously short:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ go build example/words
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ go test example/words
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ go install example/words
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The surprise is not that one command has subcommands. It is that the tool understands Go packages instead of requiring me to list source files and their order. Imports describe dependencies, package directories group files, and the tool can decide what must be compiled.&lt;/p&gt;
&lt;p&gt;This only works because the package layout is a convention shared by source and tool. A directory&amp;rsquo;s buildable Go files form a package, import paths identify dependencies, and build constraints can select platform-specific files. The command is small because the model underneath it is constrained.&lt;/p&gt;
&lt;p&gt;I prefer this to maintaining a make rule for every package. Native libraries and generated files may still need external steps, but pure Go should not need a handwritten recital of its own import graph.&lt;/p&gt;
&lt;p&gt;The caveat is that this is a preview from Go 1 development, not a retrospective about a finished Go 1 release. Tool behaviour and package APIs deserve checking against the snapshot in use. I am also resisting the urge to wrap the three commands in a larger script before there is any larger problem.&lt;/p&gt;
&lt;p&gt;For this package, deleting build instructions was the feature. My build system now contains less personal folklore, which is generally where folklore is safest.&lt;/p&gt;</description></item><item><title>Installing Go Code With goinstall</title><link>https://rselbach.com/installing-go-code-with-goinstall/</link><pubDate>Tue, 18 May 2010 17:36:00 +0000</pubDate><guid>https://rselbach.com/installing-go-code-with-goinstall/</guid><description>&lt;p&gt;The new &lt;code&gt;goinstall&lt;/code&gt; tool removes some Makefile work from small Go packages. Given an import path on a host it recognizes, it fetches the source, builds dependencies, and installs the package in the Go tree under &lt;code&gt;GOROOT&lt;/code&gt;. This predates the workspace layout I keep wishing into existence.&lt;/p&gt;
&lt;p&gt;For a package hosted on GitHub I can run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ goinstall github.com/rselbach/lines.git
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;GitHub is one of the repository hosts this version knows how to fetch, provided the repository name includes the &lt;code&gt;.git&lt;/code&gt; suffix it expects. The import path is also the package identity: source lands below &lt;code&gt;$GOROOT/src/pkg/github.com/rselbach/lines.git&lt;/code&gt;, and the installed archive goes into the corresponding package tree below &lt;code&gt;$GOROOT/pkg&lt;/code&gt;. There is no GOPATH here yet.&lt;/p&gt;
&lt;p&gt;This is early machinery. Repository conventions, supported fetch methods, command flags, and even package locations are changing between weekly snapshots. I would not encode today&amp;rsquo;s behavior into a company-wide build system without pinning the toolchain and keeping the escape hatch labeled.&lt;/p&gt;
&lt;p&gt;It also does not solve version selection. Installing the latest source from a remote location is convenient for experiments and rather less comforting for reproducing a build six months later. For serious work I still record the exact revisions of the compiler and imported code.&lt;/p&gt;
&lt;p&gt;Even with those caveats, &lt;code&gt;goinstall&lt;/code&gt; saves the old fetching, directory arranging, dependency chasing, and archive copying dance. The machine can have that ritual; it will invent another soon enough.&lt;/p&gt;</description></item></channel></rss>