Commit 1e5b7e70 authored by Gustavo Niemeyer's avatar Gustavo Niemeyer

cmd/goinstall: remove now that 'go get' works

The changes to builder were not tested.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5572083
parent d91ade02
......@@ -40,7 +40,6 @@ CLEANDIRS=\
godoc\
fix\
gofmt\
goinstall\
gotest\
vet\
yacc\
......
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../Make.inc
TARG=goinstall
GOFILES=\
download.go\
main.go\
make.go\
include ../../Make.cmd
test:
gotest
testshort:
gotest -test.short
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Goinstall is an experiment in automatic package installation.
It installs packages, possibly downloading them from the internet.
It maintains a list of public Go packages at
http://godashboard.appspot.com/package.
Usage:
goinstall [flags] importpath...
goinstall [flags] -a
Flags and default settings:
-a=false install all previously installed packages
-clean=false clean the package directory before installing
-dashboard=true tally public packages on godashboard.appspot.com
-install=true build and install the package and its dependencies
-nuke=false remove the target object and clean before installing
-u=false update already-downloaded packages
-v=false verbose operation
Goinstall installs each of the packages identified on the command line. It
installs a package's prerequisites before trying to install the package
itself. Unless -log=false is specified, goinstall logs the import path of each
installed package to $GOROOT/goinstall.log for use by goinstall -a.
If the -a flag is given, goinstall reinstalls all previously installed
packages, reading the list from $GOROOT/goinstall.log. After updating to a
new Go release, which deletes all package binaries, running
goinstall -a
will recompile and reinstall goinstalled packages.
Another common idiom is to use
goinstall -a -u
to update, recompile, and reinstall all goinstalled packages.
The source code for a package with import path foo/bar is expected
to be in the directory $GOROOT/src/pkg/foo/bar/ or $GOPATH/src/foo/bar/.
See "The GOPATH Environment Variable" for more about GOPATH.
By default, goinstall prints output only when it encounters an error.
The -v flag causes goinstall to print information about packages
being considered and installed.
Goinstall ignores Makefiles.
Remote Repositories
If a package import path refers to a remote repository, goinstall will
download the code if necessary.
Goinstall recognizes packages from a few common code hosting sites:
BitBucket (Git, Mercurial)
import "bitbucket.org/user/project"
import "bitbucket.org/user/project/sub/directory"
GitHub (Git)
import "github.com/user/project"
import "github.com/user/project/sub/directory"
Google Code Project Hosting (Git, Mercurial, Subversion)
import "project.googlecode.com/git"
import "project.googlecode.com/git/sub/directory"
import "project.googlecode.com/hg"
import "project.googlecode.com/hg/sub/directory"
import "project.googlecode.com/svn/trunk"
import "project.googlecode.com/svn/trunk/sub/directory"
Google Code Project Hosting sub-repositories:
import "code.google.com/p/project.subrepo/sub/directory
Launchpad (Bazaar)
import "launchpad.net/project"
import "launchpad.net/project/series"
import "launchpad.net/project/series/sub/directory"
import "launchpad.net/~user/project/branch"
import "launchpad.net/~user/project/branch/sub/directory"
If the destination directory (e.g., $GOROOT/src/pkg/bitbucket.org/user/project)
already exists and contains an appropriate checkout, goinstall will not
attempt to fetch updates. The -u flag changes this behavior,
causing goinstall to update all remote packages encountered during
the installation.
When downloading or updating, goinstall looks for a tag with the "go." prefix
that corresponds to the local Go version. For Go "release.r58" it looks for a
tag named "go.r58". For "weekly.2011-06-03" it looks for "go.weekly.2011-06-03".
If the specific "go.X" tag is not found, it chooses the closest earlier version.
If an appropriate tag is found, goinstall uses that version of the code.
Otherwise it uses the default version selected by the version control
system, typically HEAD for git, tip for Mercurial.
After a successful download and installation of one of these import paths,
goinstall reports the installation to godashboard.appspot.com, which
increments a count associated with the package and the time of its most
recent installation. This mechanism powers the package list at
http://godashboard.appspot.com/package, allowing Go programmers to learn about
popular packages that might be worth looking at.
The -dashboard=false flag disables this reporting.
For code hosted on other servers, goinstall recognizes the general form
repository.vcs/path
as denoting the given repository, with or without the .vcs suffix, using
the named version control system, and then the path inside that repository.
The supported version control systems are:
Bazaar .bzr
Git .git
Mercurial .hg
Subversion .svn
For example,
import "example.org/user/foo.hg"
denotes the root directory of the Mercurial repository at example.org/user/foo
or foo.hg, and
import "example.org/repo.git/foo/bar"
denotes the foo/bar directory of the Git repository at example.com/repo or
repo.git.
When a version control system supports multiple protocols, goinstall tries each
in turn.
For example, for Git it tries git://, then https://, then http://.
The GOPATH Environment Variable
GOPATH may be set to a colon-separated list of paths inside which Go code,
package objects, and executables may be found.
Set a GOPATH to use goinstall to build and install your own code and
external libraries outside of the Go tree (and to avoid writing Makefiles).
The top-level directory structure of a GOPATH is prescribed:
The 'src' directory is for source code. The directory naming inside 'src'
determines the package import path or executable name.
The 'pkg' directory is for package objects. Like the Go tree, package objects
are stored inside a directory named after the target operating system and
processor architecture ('pkg/$GOOS_$GOARCH').
A package whose source is located at '$GOPATH/src/foo/bar' would be imported
as 'foo/bar' and installed as '$GOPATH/pkg/$GOOS_$GOARCH/foo/bar.a'.
The 'bin' directory is for executable files.
Goinstall installs program binaries using the name of the source folder.
A binary whose source is at 'src/foo/qux' would be built and installed to
'$GOPATH/bin/qux'. (Note 'bin/qux', not 'bin/foo/qux' - this is such that
you can put the bin directory in your PATH.)
Here's an example directory layout:
GOPATH=/home/user/gocode
/home/user/gocode/
src/foo/
bar/ (go code in package bar)
qux/ (go code in package main)
bin/qux (executable file)
pkg/linux_amd64/foo/bar.a (object file)
Run 'goinstall foo/bar' to build and install the package 'foo/bar'
(and its dependencies).
Goinstall will search each GOPATH (in order) for 'src/foo/bar'.
If the directory cannot be found, goinstall will attempt to fetch the
source from a remote repository and write it to the 'src' directory of the
first GOPATH (or $GOROOT/src/pkg if GOPATH is not set).
Goinstall recognizes relative and absolute paths (paths beginning with / or .).
The following commands would build our example packages:
goinstall /home/user/gocode/src/foo/bar # build and install foo/bar
cd /home/user/gocode/src/foo
goinstall ./bar # build and install foo/bar (again)
cd qux
goinstall . # build and install foo/qux
*/
package documentation
This diff is collapsed.
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"errors"
"io/ioutil"
"net/http"
"testing"
)
var FindPublicRepoTests = []struct {
pkg string
vcs, root, url string
transport *testTransport
}{
{
"code.google.com/p/repo/path/foo",
"hg",
"code.google.com/p/repo",
"https://code.google.com/p/repo",
&testTransport{
"https://code.google.com/p/repo/source/checkout",
`<tt id="checkoutcmd">hg clone https://...`,
},
},
{
"code.google.com/p/repo/path/foo",
"svn",
"code.google.com/p/repo",
"http://repo.googlecode.com/svn",
&testTransport{
"https://code.google.com/p/repo/source/checkout",
`<tt id="checkoutcmd">svn checkout https://...`,
},
},
{
"code.google.com/p/repo/path/foo",
"git",
"code.google.com/p/repo",
"https://code.google.com/p/repo",
&testTransport{
"https://code.google.com/p/repo/source/checkout",
`<tt id="checkoutcmd">git clone https://...`,
},
},
{
"code.google.com/p/repo.sub/path",
"hg",
"code.google.com/p/repo.sub",
"https://code.google.com/p/repo.sub",
&testTransport{
"https://code.google.com/p/repo/source/checkout?repo=sub",
`<tt id="checkoutcmd">hg clone https://...`,
},
},
{
"bitbucket.org/user/repo/path/foo",
"hg",
"bitbucket.org/user/repo",
"http://bitbucket.org/user/repo",
&testTransport{
"https://api.bitbucket.org/1.0/repositories/user/repo",
`{"scm": "hg"}`,
},
},
{
"bitbucket.org/user/repo/path/foo",
"git",
"bitbucket.org/user/repo",
"http://bitbucket.org/user/repo.git",
&testTransport{
"https://api.bitbucket.org/1.0/repositories/user/repo",
`{"scm": "git"}`,
},
},
{
"github.com/user/repo/path/foo",
"git",
"github.com/user/repo",
"http://github.com/user/repo.git",
nil,
},
{
"launchpad.net/project/series/path",
"bzr",
"launchpad.net/project/series",
"https://launchpad.net/project/series",
nil,
},
{
"launchpad.net/~user/project/branch/path",
"bzr",
"launchpad.net/~user/project/branch",
"https://launchpad.net/~user/project/branch",
nil,
},
}
func TestFindPublicRepo(t *testing.T) {
for _, test := range FindPublicRepoTests {
client := http.DefaultClient
if test.transport != nil {
client = &http.Client{Transport: test.transport}
}
repo, err := findPublicRepo(test.pkg)
if err != nil {
t.Errorf("findPublicRepo(%s): error: %v", test.pkg, err)
continue
}
if repo == nil {
t.Errorf("%s: got nil match", test.pkg)
continue
}
url, root, vcs, err := repo.Repo(client)
if err != nil {
t.Errorf("%s: repo.Repo error: %v", test.pkg, err)
continue
}
if v := vcsMap[test.vcs]; vcs != v {
t.Errorf("%s: got vcs=%v, want %v", test.pkg, vcs, v)
}
if root != test.root {
t.Errorf("%s: got root=%v, want %v", test.pkg, root, test.root)
}
if url != test.url {
t.Errorf("%s: got url=%v, want %v", test.pkg, url, test.url)
}
}
}
type testTransport struct {
expectURL string
responseBody string
}
func (t *testTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if g, e := req.URL.String(), t.expectURL; g != e {
return nil, errors.New("want " + e)
}
body := ioutil.NopCloser(bytes.NewBufferString(t.responseBody))
return &http.Response{
StatusCode: http.StatusOK,
Body: body,
}, nil
}
This diff is collapsed.
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Run "make install" to build package.
package main
import (
"bytes"
"errors"
"go/build"
"path" // use for import paths
"strings"
"text/template"
)
// domake builds the package in dir.
// domake generates a standard Makefile and passes it
// to make on standard input.
func domake(dir, pkg string, tree *build.Tree, isCmd bool) (err error) {
makefile, err := makeMakefile(dir, pkg, tree, isCmd)
if err != nil {
return err
}
cmd := []string{"bash", "gomake", "-f-"}
if *nuke {
cmd = append(cmd, "nuke")
} else if *clean {
cmd = append(cmd, "clean")
}
if *doInstall {
cmd = append(cmd, "install")
}
if len(cmd) <= 3 { // nothing to do
return nil
}
return run(dir, makefile, cmd...)
}
// makeMakefile computes the standard Makefile for the directory dir
// installing as package pkg. It includes all *.go files in the directory
// except those in package main and those ending in _test.go.
func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, error) {
if !safeName(pkg) {
return nil, errors.New("unsafe name: " + pkg)
}
targ := pkg
targDir := tree.PkgDir()
if isCmd {
// use the last part of the package name for targ
_, targ = path.Split(pkg)
targDir = tree.BinDir()
}
dirInfo, err := build.ScanDir(dir)
if err != nil {
return nil, err
}
cgoFiles := dirInfo.CgoFiles
isCgo := make(map[string]bool, len(cgoFiles))
for _, file := range cgoFiles {
if !safeName(file) {
return nil, errors.New("bad name: " + file)
}
isCgo[file] = true
}
goFiles := make([]string, 0, len(dirInfo.GoFiles))
for _, file := range dirInfo.GoFiles {
if !safeName(file) {
return nil, errors.New("unsafe name: " + file)
}
if !isCgo[file] {
goFiles = append(goFiles, file)
}
}
oFiles := make([]string, 0, len(dirInfo.CFiles)+len(dirInfo.SFiles))
cgoOFiles := make([]string, 0, len(dirInfo.CFiles))
for _, file := range dirInfo.CFiles {
if !safeName(file) {
return nil, errors.New("unsafe name: " + file)
}
// When cgo is in use, C files are compiled with gcc,
// otherwise they're compiled with gc.
if len(cgoFiles) > 0 {
cgoOFiles = append(cgoOFiles, file[:len(file)-2]+".o")
} else {
oFiles = append(oFiles, file[:len(file)-2]+".$O")
}
}
for _, file := range dirInfo.SFiles {
if !safeName(file) {
return nil, errors.New("unsafe name: " + file)
}
oFiles = append(oFiles, file[:len(file)-2]+".$O")
}
var imports []string
for _, t := range build.Path {
imports = append(imports, t.PkgDir())
}
var buf bytes.Buffer
md := makedata{targ, targDir, "pkg", goFiles, oFiles, cgoFiles, cgoOFiles, imports}
if isCmd {
md.Type = "cmd"
}
if err := makefileTemplate.Execute(&buf, &md); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var safeBytes = []byte("+-~./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz")
func safeName(s string) bool {
if s == "" {
return false
}
if strings.Contains(s, "..") {
return false
}
if s[0] == '~' {
return false
}
for i := 0; i < len(s); i++ {
if c := s[i]; c < 0x80 && bytes.IndexByte(safeBytes, c) < 0 {
return false
}
}
return true
}
// makedata is the data type for the makefileTemplate.
type makedata struct {
Targ string // build target
TargDir string // build target directory
Type string // build type: "pkg" or "cmd"
GoFiles []string // list of non-cgo .go files
OFiles []string // list of .$O files
CgoFiles []string // list of cgo .go files
CgoOFiles []string // list of cgo .o files, without extension
Imports []string // gc/ld import paths
}
var makefileTemplate = template.Must(template.New("Makefile").Parse(`
include $(GOROOT)/src/Make.inc
TARG={{.Targ}}
TARGDIR={{.TargDir}}
{{with .GoFiles}}
GOFILES=\
{{range .}} {{.}}\
{{end}}
{{end}}
{{with .OFiles}}
OFILES=\
{{range .}} {{.}}\
{{end}}
{{end}}
{{with .CgoFiles}}
CGOFILES=\
{{range .}} {{.}}\
{{end}}
{{end}}
{{with .CgoOFiles}}
CGO_OFILES=\
{{range .}} {{.}}\
{{end}}
{{end}}
GCIMPORTS={{range .Imports}}-I "{{.}}" {{end}}
LDIMPORTS={{range .Imports}}-L "{{.}}" {{end}}
include $(GOROOT)/src/Make.{{.Type}}
`))
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "testing"
var selectTagTestTags = []string{
"go.r58",
"go.r58.1",
"go.r59",
"go.r59.1",
"go.r61",
"go.r61.1",
"go.weekly.2010-01-02",
"go.weekly.2011-10-12",
"go.weekly.2011-10-12.1",
"go.weekly.2011-10-14",
"go.weekly.2011-11-01",
// these should be ignored:
"release.r59",
"release.r59.1",
"release",
"weekly.2011-10-12",
"weekly.2011-10-12.1",
"weekly",
"foo",
"bar",
"go.f00",
"go!r60",
"go.1999-01-01",
}
var selectTagTests = []struct {
version string
selected string
}{
{"release.r57", ""},
{"release.r58.2", "go.r58.1"},
{"release.r59", "go.r59"},
{"release.r59.1", "go.r59.1"},
{"release.r60", "go.r59.1"},
{"release.r60.1", "go.r59.1"},
{"release.r61", "go.r61"},
{"release.r66", "go.r61.1"},
{"weekly.2010-01-01", ""},
{"weekly.2010-01-02", "go.weekly.2010-01-02"},
{"weekly.2010-01-02.1", "go.weekly.2010-01-02"},
{"weekly.2010-01-03", "go.weekly.2010-01-02"},
{"weekly.2011-10-12", "go.weekly.2011-10-12"},
{"weekly.2011-10-12.1", "go.weekly.2011-10-12.1"},
{"weekly.2011-10-13", "go.weekly.2011-10-12.1"},
{"weekly.2011-10-14", "go.weekly.2011-10-14"},
{"weekly.2011-10-14.1", "go.weekly.2011-10-14"},
{"weekly.2011-11-01", "go.weekly.2011-11-01"},
{"weekly.2014-01-01", "go.weekly.2011-11-01"},
{"weekly.3000-01-01", "go.weekly.2011-11-01"},
// faulty versions:
{"release.f00", ""},
{"weekly.1999-01-01", ""},
{"junk", ""},
{"", ""},
}
func TestSelectTag(t *testing.T) {
for _, c := range selectTagTests {
selected := selectTag(c.version, selectTagTestTags)
if selected != c.selected {
t.Errorf("selectTag(%q) = %q, want %q", c.version, selected, c.selected)
}
}
}
......@@ -158,7 +158,6 @@ DIRS=\
../cmd/godoc\
../cmd/fix\
../cmd/gofmt\
../cmd/goinstall\
../cmd/gotest\
../cmd/vet\
../cmd/yacc\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment