Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
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
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
377 additions
and
68 deletions
+377
-68
src/cmd/goinstall/main.go
src/cmd/goinstall/main.go
+7
-6
src/cmd/goinstall/make.go
src/cmd/goinstall/make.go
+3
-3
src/cmd/gotest/gotest.go
src/cmd/gotest/gotest.go
+1
-1
src/pkg/go/build/build_test.go
src/pkg/go/build/build_test.go
+17
-8
src/pkg/go/build/cgotest/cgotest.go
src/pkg/go/build/cgotest/cgotest.go
+3
-0
src/pkg/go/build/dir.go
src/pkg/go/build/dir.go
+344
-48
src/pkg/go/build/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,7 +38,7 @@ var buildPkgs = []struct {
"go/build/cmdtest"
,
&
DirInfo
{
GoFiles
:
[]
string
{
"main.go"
},
P
kgNam
e
:
"main"
,
P
ackag
e
:
"main"
,
Imports
:
[]
string
{
"go/build/pkgtest"
},
},
},
...
...
@@ -48,7 +48,9 @@ var buildPkgs = []struct {
CgoFiles
:
[]
string
{
"cgotest.go"
},
CFiles
:
[]
string
{
"cgotest.c"
},
Imports
:
[]
string
{
"C"
,
"unsafe"
},
PkgName
:
"cgotest"
,
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