Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
17bebd3c
Commit
17bebd3c
authored
Sep 15, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/build: handle cgo, //build comments
R=adg CC=golang-dev
https://golang.org/cl/5018044
parent
ce008f8c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
20 deletions
+33
-20
main.go
src/cmd/goinstall/main.go
+7
-6
make.go
src/cmd/goinstall/make.go
+3
-3
gotest.go
src/cmd/gotest/gotest.go
+1
-1
build_test.go
src/pkg/go/build/build_test.go
+17
-8
cgotest.go
src/pkg/go/build/cgotest/cgotest.go
+3
-0
dir.go
src/pkg/go/build/dir.go
+0
-0
syslist_test.go
src/pkg/go/build/syslist_test.go
+2
-2
No files found.
src/cmd/goinstall/main.go
View file @
17bebd3c
...
...
@@ -13,7 +13,7 @@ import (
"go/token"
"io/ioutil"
"os"
"path/filepath"
"path/filepath"
// use for file system paths
"regexp"
"runtime"
"strings"
...
...
@@ -190,7 +190,7 @@ func install(pkg, parent string) {
}()
// Don't allow trailing '/'
if
_
,
f
:=
filepath
.
Split
(
pkg
);
f
==
""
{
if
strings
.
HasSuffix
(
pkg
,
"/"
)
{
errorf
(
"%s should not have trailing '/'
\n
"
,
pkg
)
return
}
...
...
@@ -225,16 +225,17 @@ func install(pkg, parent string) {
terrorf
(
tree
,
"%s: %v
\n
"
,
pkg
,
err
)
return
}
dir
:=
filepath
.
Join
(
tree
.
SrcDir
(),
pkg
)
dir
:=
filepath
.
Join
(
tree
.
SrcDir
(),
filepath
.
FromSlash
(
pkg
)
)
// Install prerequisites.
dirInfo
,
err
:=
build
.
ScanDir
(
dir
,
parent
==
""
)
dirInfo
,
err
:=
build
.
ScanDir
(
dir
)
if
err
!=
nil
{
terrorf
(
tree
,
"%s: %v
\n
"
,
pkg
,
err
)
return
}
if
len
(
dirInfo
.
GoFiles
)
+
len
(
dirInfo
.
CgoFiles
)
==
0
{
terrorf
(
tree
,
"%s: package has no files
\n
"
,
pkg
)
// We reserve package main to identify commands.
if
parent
!=
""
&&
dirInfo
.
Package
==
"main"
{
terrorf
(
tree
,
"%s: found only package main in %s; cannot import"
,
pkg
,
dir
)
return
}
for
_
,
p
:=
range
dirInfo
.
Imports
{
...
...
src/cmd/goinstall/make.go
View file @
17bebd3c
...
...
@@ -10,7 +10,7 @@ import (
"bytes"
"go/build"
"os"
"path
/filepath"
"path
"
// use for import paths
"strings"
"template"
)
...
...
@@ -44,10 +44,10 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
targDir
:=
tree
.
PkgDir
()
if
isCmd
{
// use the last part of the package name for targ
_
,
targ
=
file
path
.
Split
(
pkg
)
_
,
targ
=
path
.
Split
(
pkg
)
targDir
=
tree
.
BinDir
()
}
dirInfo
,
err
:=
build
.
ScanDir
(
dir
,
isCmd
)
dirInfo
,
err
:=
build
.
ScanDir
(
dir
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
src/cmd/gotest/gotest.go
View file @
17bebd3c
...
...
@@ -165,7 +165,7 @@ func setEnvironment() {
func
getTestFileNames
()
{
names
:=
fileNames
if
len
(
names
)
==
0
{
info
,
err
:=
build
.
ScanDir
(
"."
,
true
)
info
,
err
:=
build
.
ScanDir
(
"."
)
if
err
!=
nil
{
Fatalf
(
"scanning directory: %v"
,
err
)
}
...
...
src/pkg/go/build/build_test.go
View file @
17bebd3c
...
...
@@ -27,7 +27,7 @@ var buildPkgs = []struct {
&
DirInfo
{
GoFiles
:
[]
string
{
"pkgtest.go"
},
SFiles
:
[]
string
{
"sqrt_"
+
runtime
.
GOARCH
+
".s"
},
P
kgNam
e
:
"pkgtest"
,
P
ackag
e
:
"pkgtest"
,
Imports
:
[]
string
{
"os"
},
TestImports
:
[]
string
{
"fmt"
,
"pkgtest"
},
TestGoFiles
:
sortstr
([]
string
{
"sqrt_test.go"
,
"sqrt_"
+
runtime
.
GOARCH
+
"_test.go"
}),
...
...
@@ -38,17 +38,19 @@ var buildPkgs = []struct {
"go/build/cmdtest"
,
&
DirInfo
{
GoFiles
:
[]
string
{
"main.go"
},
P
kgNam
e
:
"main"
,
P
ackag
e
:
"main"
,
Imports
:
[]
string
{
"go/build/pkgtest"
},
},
},
{
"go/build/cgotest"
,
&
DirInfo
{
CgoFiles
:
[]
string
{
"cgotest.go"
},
CFiles
:
[]
string
{
"cgotest.c"
},
Imports
:
[]
string
{
"C"
,
"unsafe"
},
PkgName
:
"cgotest"
,
CgoFiles
:
[]
string
{
"cgotest.go"
},
CFiles
:
[]
string
{
"cgotest.c"
},
Imports
:
[]
string
{
"C"
,
"unsafe"
},
Package
:
"cgotest"
,
CgoLDFLAGS
:
[]
string
{
"-lregexp"
},
CgoPkgConfig
:
[]
string
{
"cairo"
,
"moscow"
},
},
},
}
...
...
@@ -56,11 +58,11 @@ var buildPkgs = []struct {
const
cmdtestOutput
=
"3"
func
TestBuild
(
t
*
testing
.
T
)
{
var
ctxt
=
Context
{
GOOS
:
"darwin"
,
GOARCH
:
"amd64"
}
for
_
,
tt
:=
range
buildPkgs
{
tree
:=
Path
[
0
]
// Goroot
dir
:=
filepath
.
Join
(
tree
.
SrcDir
(),
tt
.
dir
)
info
,
err
:=
ScanDir
(
dir
,
true
)
info
,
err
:=
ctxt
.
ScanDir
(
dir
)
if
err
!=
nil
{
t
.
Errorf
(
"ScanDir(%#q): %v"
,
tt
.
dir
,
err
)
continue
...
...
@@ -70,6 +72,13 @@ func TestBuild(t *testing.T) {
continue
}
if
tt
.
dir
==
"go/build/cgotest"
{
// Don't actually run cgo.
// Among other things our test depends
// on pkg-config, which is not present on all systems.
continue
}
s
,
err
:=
Build
(
tree
,
tt
.
dir
,
info
)
if
err
!=
nil
{
t
.
Errorf
(
"Build(%#q): %v"
,
tt
.
dir
,
err
)
...
...
src/pkg/go/build/cgotest/cgotest.go
View file @
17bebd3c
...
...
@@ -6,6 +6,9 @@ package cgotest
/*
char* greeting = "hello, world";
#cgo darwin/amd64 LDFLAGS: -lregexp
#cgo linux CFLAGS: -m32
#cgo pkg-config: cairo moscow
*/
// #include "cgotest.h"
import
"C"
...
...
src/pkg/go/build/dir.go
View file @
17bebd3c
This diff is collapsed.
Click to expand it.
src/pkg/go/build/syslist_test.go
View file @
17bebd3c
...
...
@@ -55,8 +55,8 @@ var tests = []GoodFileTest{
func
TestGoodOSArch
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
tests
{
if
DefaultContext
.
goodOSArch
(
test
.
name
)
!=
test
.
result
{
t
.
Fatalf
(
"goodOSArch(%q) != %v"
,
test
.
name
,
test
.
result
)
if
DefaultContext
.
goodOSArch
File
(
test
.
name
)
!=
test
.
result
{
t
.
Fatalf
(
"goodOSArch
File
(%q) != %v"
,
test
.
name
,
test
.
result
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment