import (
"bytes"
+ "errors"
"exec"
"fmt"
"os"
)
// Build produces a build Script for the given package.
-func Build(tree *Tree, pkg string, info *DirInfo) (*Script, os.Error) {
+func Build(tree *Tree, pkg string, info *DirInfo) (*Script, error) {
s := &Script{}
b := &build{
script: s,
if g := os.Getenv("GOARCH"); g != "" {
b.goarch = g
}
- var err os.Error
+ var err error
b.arch, err = ArchChar(b.goarch)
if err != nil {
return nil, err
// FindTree should always be able to suggest an import
// path and tree. The path must be malformed
// (for example, an absolute or relative path).
- return nil, os.NewError("build: invalid import: " + pkg)
+ return nil, errors.New("build: invalid import: " + pkg)
}
s.addInput(filepath.Join(t.PkgDir(), p+".a"))
}
}
if len(ofiles) == 0 {
- return nil, os.NewError("make: no object files to build")
+ return nil, errors.New("make: no object files to build")
}
// choose target file
}
// Run runs the Script's Cmds in order.
-func (s *Script) Run() os.Error {
+func (s *Script) Run() error {
for _, c := range s.Cmd {
if err := c.Run(); err != nil {
return err
// Clean removes the Script's Intermediate files.
// It tries to remove every file and returns the first error it encounters.
-func (s *Script) Clean() (err os.Error) {
+func (s *Script) Clean() (err error) {
// Reverse order so that directories get removed after the files they contain.
for i := len(s.Intermediate) - 1; i >= 0; i-- {
if e := os.Remove(s.Intermediate[i]); err == nil {
// Nuke removes the Script's Intermediate and Output files.
// It tries to remove every file and returns the first error it encounters.
-func (s *Script) Nuke() (err os.Error) {
+func (s *Script) Nuke() (err error) {
// Reverse order so that directories get removed after the files they contain.
for i := len(s.Output) - 1; i >= 0; i-- {
if e := os.Remove(s.Output[i]); err == nil {
}
// Run executes the Cmd.
-func (c *Cmd) Run() os.Error {
+func (c *Cmd) Run() error {
if c.Args[0] == "mkdir" {
for _, p := range c.Output {
if err := os.MkdirAll(p, 0777); err != nil {
// ArchChar returns the architecture character for the given goarch.
// For example, ArchChar("amd64") returns "6".
-func ArchChar(goarch string) (string, os.Error) {
+func ArchChar(goarch string) (string, error) {
switch goarch {
case "386":
return "8", nil
case "arm":
return "5", nil
}
- return "", os.NewError("unsupported GOARCH " + goarch)
+ return "", errors.New("unsupported GOARCH " + goarch)
}
type build struct {