~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/cmd/goinstall/make.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2010 The Go Authors.  All rights reserved.
 
1
// Copyright 2011 The Go Authors.  All rights reserved.
2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
 
8
8
 
9
9
import (
10
10
        "bytes"
 
11
        "go/build"
11
12
        "os"
12
13
        "path/filepath"
 
14
        "strings"
13
15
        "template"
14
16
)
15
17
 
16
18
// domake builds the package in dir.
17
19
// domake generates a standard Makefile and passes it
18
20
// to make on standard input.
19
 
func domake(dir, pkg string, root *pkgroot, isCmd bool) (err os.Error) {
20
 
        makefile, err := makeMakefile(dir, pkg, root, isCmd)
 
21
func domake(dir, pkg string, tree *build.Tree, isCmd bool) (err os.Error) {
 
22
        makefile, err := makeMakefile(dir, pkg, tree, isCmd)
21
23
        if err != nil {
22
24
                return err
23
25
        }
24
26
        cmd := []string{"bash", "gomake", "-f-"}
25
 
        if *clean {
 
27
        if *nuke {
 
28
                cmd = append(cmd, "nuke")
 
29
        } else if *clean {
26
30
                cmd = append(cmd, "clean")
27
31
        }
28
32
        cmd = append(cmd, "install")
32
36
// makeMakefile computes the standard Makefile for the directory dir
33
37
// installing as package pkg.  It includes all *.go files in the directory
34
38
// except those in package main and those ending in _test.go.
35
 
func makeMakefile(dir, pkg string, root *pkgroot, isCmd bool) ([]byte, os.Error) {
 
39
func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Error) {
36
40
        if !safeName(pkg) {
37
 
                return nil, os.ErrorString("unsafe name: " + pkg)
 
41
                return nil, os.NewError("unsafe name: " + pkg)
38
42
        }
39
43
        targ := pkg
40
 
        targDir := root.pkgDir()
 
44
        targDir := tree.PkgDir()
41
45
        if isCmd {
42
46
                // use the last part of the package name for targ
43
47
                _, targ = filepath.Split(pkg)
44
 
                targDir = root.binDir()
 
48
                targDir = tree.BinDir()
45
49
        }
46
 
        dirInfo, err := scanDir(dir, isCmd)
 
50
        dirInfo, err := build.ScanDir(dir, isCmd)
47
51
        if err != nil {
48
52
                return nil, err
49
53
        }
50
54
 
51
 
        cgoFiles := dirInfo.cgoFiles
 
55
        cgoFiles := dirInfo.CgoFiles
52
56
        isCgo := make(map[string]bool, len(cgoFiles))
53
57
        for _, file := range cgoFiles {
54
58
                if !safeName(file) {
55
 
                        return nil, os.ErrorString("bad name: " + file)
 
59
                        return nil, os.NewError("bad name: " + file)
56
60
                }
57
61
                isCgo[file] = true
58
62
        }
59
63
 
60
 
        goFiles := make([]string, 0, len(dirInfo.goFiles))
61
 
        for _, file := range dirInfo.goFiles {
 
64
        goFiles := make([]string, 0, len(dirInfo.GoFiles))
 
65
        for _, file := range dirInfo.GoFiles {
62
66
                if !safeName(file) {
63
 
                        return nil, os.ErrorString("unsafe name: " + file)
 
67
                        return nil, os.NewError("unsafe name: " + file)
64
68
                }
65
69
                if !isCgo[file] {
66
70
                        goFiles = append(goFiles, file)
67
71
                }
68
72
        }
69
73
 
70
 
        oFiles := make([]string, 0, len(dirInfo.cFiles)+len(dirInfo.sFiles))
71
 
        cgoOFiles := make([]string, 0, len(dirInfo.cFiles))
72
 
        for _, file := range dirInfo.cFiles {
 
74
        oFiles := make([]string, 0, len(dirInfo.CFiles)+len(dirInfo.SFiles))
 
75
        cgoOFiles := make([]string, 0, len(dirInfo.CFiles))
 
76
        for _, file := range dirInfo.CFiles {
73
77
                if !safeName(file) {
74
 
                        return nil, os.ErrorString("unsafe name: " + file)
 
78
                        return nil, os.NewError("unsafe name: " + file)
75
79
                }
76
80
                // When cgo is in use, C files are compiled with gcc,
77
81
                // otherwise they're compiled with gc.
82
86
                }
83
87
        }
84
88
 
85
 
        for _, file := range dirInfo.sFiles {
 
89
        for _, file := range dirInfo.SFiles {
86
90
                if !safeName(file) {
87
 
                        return nil, os.ErrorString("unsafe name: " + file)
 
91
                        return nil, os.NewError("unsafe name: " + file)
88
92
                }
89
93
                oFiles = append(oFiles, file[:len(file)-2]+".$O")
90
94
        }
91
95
 
 
96
        var imports []string
 
97
        for _, t := range build.Path {
 
98
                imports = append(imports, t.PkgDir())
 
99
        }
 
100
 
92
101
        var buf bytes.Buffer
93
102
        md := makedata{targ, targDir, "pkg", goFiles, oFiles, cgoFiles, cgoOFiles, imports}
94
103
        if isCmd {
106
115
        if s == "" {
107
116
                return false
108
117
        }
 
118
        if strings.Contains(s, "..") {
 
119
                return false
 
120
        }
109
121
        for i := 0; i < len(s); i++ {
110
122
                if c := s[i]; c < 0x80 && bytes.IndexByte(safeBytes, c) < 0 {
111
123
                        return false
134
146
 
135
147
{.section GoFiles}
136
148
GOFILES=\
137
 
{.repeated section GoFiles}
 
149
{.repeated section @}
138
150
        {@}\
139
151
{.end}
140
152
 
141
153
{.end}
142
154
{.section OFiles}
143
155
OFILES=\
144
 
{.repeated section OFiles}
 
156
{.repeated section @}
145
157
        {@}\
146
158
{.end}
147
159
 
148
160
{.end}
149
161
{.section CgoFiles}
150
162
CGOFILES=\
151
 
{.repeated section CgoFiles}
 
163
{.repeated section @}
152
164
        {@}\
153
165
{.end}
154
166
 
155
167
{.end}
156
168
{.section CgoOFiles}
157
169
CGO_OFILES=\
158
 
{.repeated section CgoOFiles}
 
170
{.repeated section @}
159
171
        {@}\
160
172
{.end}
161
173