LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "container/heap" | 9 "container/heap" |
10 "errors" | 10 "errors" |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } | 807 } |
808 cgoObjects = append(cgoObjects, outObj...) | 808 cgoObjects = append(cgoObjects, outObj...) |
809 gofiles = append(gofiles, outGo...) | 809 gofiles = append(gofiles, outGo...) |
810 } | 810 } |
811 | 811 |
812 // Prepare Go import path list. | 812 // Prepare Go import path list. |
813 inc := b.includeArgs("-I", a.deps) | 813 inc := b.includeArgs("-I", a.deps) |
814 | 814 |
815 // Compile Go. | 815 // Compile Go. |
816 if len(gofiles) > 0 { | 816 if len(gofiles) > 0 { |
817 » » out, err := buildToolchain.gc(b, a.p, obj, inc, gofiles) | 817 » » ofile, out, err := buildToolchain.gc(b, a.p, obj, inc, gofiles) |
| 818 » » if len(out) > 0 { |
| 819 » » » b.showOutput(a.p.Dir, a.p.ImportPath, b.processOutput(ou
t)) |
| 820 » » » if err != nil { |
| 821 » » » » return errPrintedOutput |
| 822 » » » } |
| 823 » » } |
818 if err != nil { | 824 if err != nil { |
819 return err | 825 return err |
820 } | 826 } |
821 » » objects = append(objects, out) | 827 » » objects = append(objects, ofile) |
822 } | 828 } |
823 | 829 |
824 // Copy .h files named for goos or goarch or goos_goarch | 830 // Copy .h files named for goos or goarch or goos_goarch |
825 // to names using GOOS and GOARCH. | 831 // to names using GOOS and GOARCH. |
826 // For example, defs_linux_amd64.h becomes defs_GOOS_GOARCH.h. | 832 // For example, defs_linux_amd64.h becomes defs_GOOS_GOARCH.h. |
827 _goos_goarch := "_" + goos + "_" + goarch + ".h" | 833 _goos_goarch := "_" + goos + "_" + goarch + ".h" |
828 _goos := "_" + goos + ".h" | 834 _goos := "_" + goos + ".h" |
829 _goarch := "_" + goarch + ".h" | 835 _goarch := "_" + goarch + ".h" |
830 for _, file := range a.p.HFiles { | 836 for _, file := range a.p.HFiles { |
831 switch { | 837 switch { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 var errPrintedOutput = errors.New("already printed output - no need to show erro
r") | 1184 var errPrintedOutput = errors.New("already printed output - no need to show erro
r") |
1179 | 1185 |
1180 var cgoLine = regexp.MustCompile(`\[[^\[\]]+\.cgo1\.go:[0-9]+\]`) | 1186 var cgoLine = regexp.MustCompile(`\[[^\[\]]+\.cgo1\.go:[0-9]+\]`) |
1181 | 1187 |
1182 // run runs the command given by cmdline in the directory dir. | 1188 // run runs the command given by cmdline in the directory dir. |
1183 // If the command fails, run prints information about the failure | 1189 // If the command fails, run prints information about the failure |
1184 // and returns a non-nil error. | 1190 // and returns a non-nil error. |
1185 func (b *builder) run(dir string, desc string, cmdargs ...interface{}) error { | 1191 func (b *builder) run(dir string, desc string, cmdargs ...interface{}) error { |
1186 out, err := b.runOut(dir, desc, cmdargs...) | 1192 out, err := b.runOut(dir, desc, cmdargs...) |
1187 if len(out) > 0 { | 1193 if len(out) > 0 { |
1188 if out[len(out)-1] != '\n' { | |
1189 out = append(out, '\n') | |
1190 } | |
1191 if desc == "" { | 1194 if desc == "" { |
1192 desc = b.fmtcmd(dir, "%s", strings.Join(stringList(cmdar
gs...), " ")) | 1195 desc = b.fmtcmd(dir, "%s", strings.Join(stringList(cmdar
gs...), " ")) |
1193 } | 1196 } |
1194 » » out := string(out) | 1197 » » b.showOutput(dir, desc, b.processOutput(out)) |
1195 » » // Fix up output referring to cgo-generated code to be more read
able. | |
1196 » » // Replace x.go:19[/tmp/.../x.cgo1.go:18] with x.go:19. | |
1197 » » // Replace _Ctype_foo with C.foo. | |
1198 » » // If we're using -x, assume we're debugging and want the full d
ump, so disable the rewrite. | |
1199 » » if !buildX && cgoLine.MatchString(out) { | |
1200 » » » out = cgoLine.ReplaceAllString(out, "") | |
1201 » » » out = strings.Replace(out, "type _Ctype_", "type C.", -1
) | |
1202 » » } | |
1203 » » b.showOutput(dir, desc, out) | |
1204 if err != nil { | 1198 if err != nil { |
1205 err = errPrintedOutput | 1199 err = errPrintedOutput |
1206 } | 1200 } |
1207 } | 1201 } |
1208 return err | 1202 return err |
| 1203 } |
| 1204 |
| 1205 // processOutput prepares the output of runOut to be output to the console. |
| 1206 func (b *builder) processOutput(out []byte) string { |
| 1207 if out[len(out)-1] != '\n' { |
| 1208 out = append(out, '\n') |
| 1209 } |
| 1210 messages := string(out) |
| 1211 // Fix up output referring to cgo-generated code to be more readable. |
| 1212 // Replace x.go:19[/tmp/.../x.cgo1.go:18] with x.go:19. |
| 1213 // Replace _Ctype_foo with C.foo. |
| 1214 // If we're using -x, assume we're debugging and want the full dump, so
disable the rewrite. |
| 1215 if !buildX && cgoLine.MatchString(messages) { |
| 1216 messages = cgoLine.ReplaceAllString(messages, "") |
| 1217 messages = strings.Replace(messages, "type _Ctype_", "type C.",
-1) |
| 1218 } |
| 1219 return messages |
1209 } | 1220 } |
1210 | 1221 |
1211 // runOut runs the command given by cmdline in the directory dir. | 1222 // runOut runs the command given by cmdline in the directory dir. |
1212 // It returns the command output and any errors that occurred. | 1223 // It returns the command output and any errors that occurred. |
1213 func (b *builder) runOut(dir string, desc string, cmdargs ...interface{}) ([]byt
e, error) { | 1224 func (b *builder) runOut(dir string, desc string, cmdargs ...interface{}) ([]byt
e, error) { |
1214 cmdline := stringList(cmdargs...) | 1225 cmdline := stringList(cmdargs...) |
1215 if buildN || buildX { | 1226 if buildN || buildX { |
1216 b.showcmd(dir, "%s", strings.Join(cmdline, " ")) | 1227 b.showcmd(dir, "%s", strings.Join(cmdline, " ")) |
1217 if buildN { | 1228 if buildN { |
1218 return nil, nil | 1229 return nil, nil |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 if filepath.IsAbs(f) || strings.HasPrefix(f, "$WORK") { | 1329 if filepath.IsAbs(f) || strings.HasPrefix(f, "$WORK") { |
1319 return f | 1330 return f |
1320 } | 1331 } |
1321 return filepath.Join(dir, f) | 1332 return filepath.Join(dir, f) |
1322 } | 1333 } |
1323 | 1334 |
1324 type toolchain interface { | 1335 type toolchain interface { |
1325 // gc runs the compiler in a specific directory on a set of files | 1336 // gc runs the compiler in a specific directory on a set of files |
1326 // and returns the name of the generated output file. | 1337 // and returns the name of the generated output file. |
1327 // The compiler runs in the directory dir. | 1338 // The compiler runs in the directory dir. |
1328 » gc(b *builder, p *Package, obj string, importArgs []string, gofiles []st
ring) (ofile string, err error) | 1339 » gc(b *builder, p *Package, obj string, importArgs []string, gofiles []st
ring) (ofile string, out []byte, err error) |
1329 // cc runs the toolchain's C compiler in a directory on a C file | 1340 // cc runs the toolchain's C compiler in a directory on a C file |
1330 // to produce an output file. | 1341 // to produce an output file. |
1331 cc(b *builder, p *Package, objdir, ofile, cfile string) error | 1342 cc(b *builder, p *Package, objdir, ofile, cfile string) error |
1332 // asm runs the assembler in a specific directory on a specific file | 1343 // asm runs the assembler in a specific directory on a specific file |
1333 // to generate the named output file. | 1344 // to generate the named output file. |
1334 asm(b *builder, p *Package, obj, ofile, sfile string) error | 1345 asm(b *builder, p *Package, obj, ofile, sfile string) error |
1335 // pkgpath builds an appropriate path for a temporary package file. | 1346 // pkgpath builds an appropriate path for a temporary package file. |
1336 pkgpath(basedir string, p *Package) string | 1347 pkgpath(basedir string, p *Package) string |
1337 // pack runs the archive packer in a specific directory to create | 1348 // pack runs the archive packer in a specific directory to create |
1338 // an archive from a set of object files. | 1349 // an archive from a set of object files. |
(...skipping 16 matching lines...) Expand all Loading... |
1355 func (noToolchain) compiler() string { | 1366 func (noToolchain) compiler() string { |
1356 noCompiler() | 1367 noCompiler() |
1357 return "" | 1368 return "" |
1358 } | 1369 } |
1359 | 1370 |
1360 func (noToolchain) linker() string { | 1371 func (noToolchain) linker() string { |
1361 noCompiler() | 1372 noCompiler() |
1362 return "" | 1373 return "" |
1363 } | 1374 } |
1364 | 1375 |
1365 func (noToolchain) gc(b *builder, p *Package, obj string, importArgs []string, g
ofiles []string) (ofile string, err error) { | 1376 func (noToolchain) gc(b *builder, p *Package, obj string, importArgs []string, g
ofiles []string) (ofile string, out []byte, err error) { |
1366 » return "", noCompiler() | 1377 » return "", nil, noCompiler() |
1367 } | 1378 } |
1368 | 1379 |
1369 func (noToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error { | 1380 func (noToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error { |
1370 return noCompiler() | 1381 return noCompiler() |
1371 } | 1382 } |
1372 | 1383 |
1373 func (noToolchain) pkgpath(basedir string, p *Package) string { | 1384 func (noToolchain) pkgpath(basedir string, p *Package) string { |
1374 noCompiler() | 1385 noCompiler() |
1375 return "" | 1386 return "" |
1376 } | 1387 } |
(...skipping 14 matching lines...) Expand all Loading... |
1391 type gcToolchain struct{} | 1402 type gcToolchain struct{} |
1392 | 1403 |
1393 func (gcToolchain) compiler() string { | 1404 func (gcToolchain) compiler() string { |
1394 return tool(archChar + "g") | 1405 return tool(archChar + "g") |
1395 } | 1406 } |
1396 | 1407 |
1397 func (gcToolchain) linker() string { | 1408 func (gcToolchain) linker() string { |
1398 return tool(archChar + "l") | 1409 return tool(archChar + "l") |
1399 } | 1410 } |
1400 | 1411 |
1401 func (gcToolchain) gc(b *builder, p *Package, obj string, importArgs []string, g
ofiles []string) (ofile string, err error) { | 1412 func (gcToolchain) gc(b *builder, p *Package, obj string, importArgs []string, g
ofiles []string) (ofile string, output []byte, err error) { |
1402 out := "_go_." + archChar | 1413 out := "_go_." + archChar |
1403 ofile = obj + out | 1414 ofile = obj + out |
1404 gcargs := []string{"-p", p.ImportPath} | 1415 gcargs := []string{"-p", p.ImportPath} |
1405 if p.Standard && p.ImportPath == "runtime" { | 1416 if p.Standard && p.ImportPath == "runtime" { |
1406 // runtime compiles with a special 6g flag to emit | 1417 // runtime compiles with a special 6g flag to emit |
1407 // additional reflect type data. | 1418 // additional reflect type data. |
1408 gcargs = append(gcargs, "-+") | 1419 gcargs = append(gcargs, "-+") |
1409 } | 1420 } |
1410 | 1421 |
1411 // If we're giving the compiler the entire package (no C etc files), tel
l it that, | 1422 // If we're giving the compiler the entire package (no C etc files), tel
l it that, |
1412 // so that it can give good error messages about forward declarations. | 1423 // so that it can give good error messages about forward declarations. |
1413 // Exceptions: a few standard packages have forward declarations for | 1424 // Exceptions: a few standard packages have forward declarations for |
1414 // pieces supplied behind-the-scenes by package runtime. | 1425 // pieces supplied behind-the-scenes by package runtime. |
1415 extFiles := len(p.CgoFiles) + len(p.CFiles) + len(p.SFiles) + len(p.Syso
Files) + len(p.SwigFiles) + len(p.SwigCXXFiles) | 1426 extFiles := len(p.CgoFiles) + len(p.CFiles) + len(p.SFiles) + len(p.Syso
Files) + len(p.SwigFiles) + len(p.SwigCXXFiles) |
1416 if p.Standard { | 1427 if p.Standard { |
1417 switch p.ImportPath { | 1428 switch p.ImportPath { |
1418 case "os", "runtime/pprof", "sync", "time": | 1429 case "os", "runtime/pprof", "sync", "time": |
1419 extFiles++ | 1430 extFiles++ |
1420 } | 1431 } |
1421 } | 1432 } |
1422 if extFiles == 0 { | 1433 if extFiles == 0 { |
1423 gcargs = append(gcargs, "-complete") | 1434 gcargs = append(gcargs, "-complete") |
1424 } | 1435 } |
1425 | 1436 |
1426 args := stringList(tool(archChar+"g"), "-o", ofile, buildGcflags, gcargs
, "-D", p.localPrefix, importArgs) | 1437 args := stringList(tool(archChar+"g"), "-o", ofile, buildGcflags, gcargs
, "-D", p.localPrefix, importArgs) |
1427 for _, f := range gofiles { | 1438 for _, f := range gofiles { |
1428 args = append(args, mkAbs(p.Dir, f)) | 1439 args = append(args, mkAbs(p.Dir, f)) |
1429 } | 1440 } |
1430 » return ofile, b.run(p.Dir, p.ImportPath, args) | 1441 |
| 1442 » output, err = b.runOut(p.Dir, p.ImportPath, args) |
| 1443 » return ofile, output, err |
1431 } | 1444 } |
1432 | 1445 |
1433 func (gcToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error { | 1446 func (gcToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error { |
1434 sfile = mkAbs(p.Dir, sfile) | 1447 sfile = mkAbs(p.Dir, sfile) |
1435 return b.run(p.Dir, p.ImportPath, tool(archChar+"a"), "-I", obj, "-o", o
file, "-D", "GOOS_"+goos, "-D", "GOARCH_"+goarch, sfile) | 1448 return b.run(p.Dir, p.ImportPath, tool(archChar+"a"), "-I", obj, "-o", o
file, "-D", "GOOS_"+goos, "-D", "GOARCH_"+goarch, sfile) |
1436 } | 1449 } |
1437 | 1450 |
1438 func (gcToolchain) pkgpath(basedir string, p *Package) string { | 1451 func (gcToolchain) pkgpath(basedir string, p *Package) string { |
1439 end := filepath.FromSlash(p.ImportPath + ".a") | 1452 end := filepath.FromSlash(p.ImportPath + ".a") |
1440 return filepath.Join(basedir, end) | 1453 return filepath.Join(basedir, end) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 var gccgoBin, _ = exec.LookPath("gccgo") | 1493 var gccgoBin, _ = exec.LookPath("gccgo") |
1481 | 1494 |
1482 func (gccgoToolchain) compiler() string { | 1495 func (gccgoToolchain) compiler() string { |
1483 return gccgoBin | 1496 return gccgoBin |
1484 } | 1497 } |
1485 | 1498 |
1486 func (gccgoToolchain) linker() string { | 1499 func (gccgoToolchain) linker() string { |
1487 return gccgoBin | 1500 return gccgoBin |
1488 } | 1501 } |
1489 | 1502 |
1490 func (gccgoToolchain) gc(b *builder, p *Package, obj string, importArgs []string
, gofiles []string) (ofile string, err error) { | 1503 func (gccgoToolchain) gc(b *builder, p *Package, obj string, importArgs []string
, gofiles []string) (ofile string, output []byte, err error) { |
1491 out := p.Name + ".o" | 1504 out := p.Name + ".o" |
1492 ofile = obj + out | 1505 ofile = obj + out |
1493 gcargs := []string{"-g"} | 1506 gcargs := []string{"-g"} |
1494 gcargs = append(gcargs, b.gccArchArgs()...) | 1507 gcargs = append(gcargs, b.gccArchArgs()...) |
1495 if pkgpath := gccgoPkgpath(p); pkgpath != "" { | 1508 if pkgpath := gccgoPkgpath(p); pkgpath != "" { |
1496 gcargs = append(gcargs, "-fgo-pkgpath="+pkgpath) | 1509 gcargs = append(gcargs, "-fgo-pkgpath="+pkgpath) |
1497 } | 1510 } |
1498 if p.localPrefix != "" { | 1511 if p.localPrefix != "" { |
1499 gcargs = append(gcargs, "-fgo-relative-import-path="+p.localPref
ix) | 1512 gcargs = append(gcargs, "-fgo-relative-import-path="+p.localPref
ix) |
1500 } | 1513 } |
1501 args := stringList("gccgo", importArgs, "-c", gcargs, "-o", ofile, build
Gccgoflags) | 1514 args := stringList("gccgo", importArgs, "-c", gcargs, "-o", ofile, build
Gccgoflags) |
1502 for _, f := range gofiles { | 1515 for _, f := range gofiles { |
1503 args = append(args, mkAbs(p.Dir, f)) | 1516 args = append(args, mkAbs(p.Dir, f)) |
1504 } | 1517 } |
1505 » return ofile, b.run(p.Dir, p.ImportPath, args) | 1518 |
| 1519 » output, err = b.runOut(p.Dir, p.ImportPath, args) |
| 1520 » return ofile, output, err |
1506 } | 1521 } |
1507 | 1522 |
1508 func (gccgoToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) erro
r { | 1523 func (gccgoToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) erro
r { |
1509 sfile = mkAbs(p.Dir, sfile) | 1524 sfile = mkAbs(p.Dir, sfile) |
1510 defs := []string{"-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch} | 1525 defs := []string{"-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch} |
1511 if pkgpath := gccgoCleanPkgpath(p); pkgpath != "" { | 1526 if pkgpath := gccgoCleanPkgpath(p); pkgpath != "" { |
1512 defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`) | 1527 defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`) |
1513 } | 1528 } |
1514 defs = append(defs, b.gccArchArgs()...) | 1529 defs = append(defs, b.gccArchArgs()...) |
1515 return b.run(p.Dir, p.ImportPath, "gccgo", "-I", obj, "-o", ofile, defs,
sfile) | 1530 return b.run(p.Dir, p.ImportPath, "gccgo", "-I", obj, "-o", ofile, defs,
sfile) |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 // NOTE(rsc): The importObj is a 5c/6c/8c object and on Windows | 1909 // NOTE(rsc): The importObj is a 5c/6c/8c object and on Windows |
1895 // must be processed before the gcc-generated objects. | 1910 // must be processed before the gcc-generated objects. |
1896 // Put it first. http://golang.org/issue/2601 | 1911 // Put it first. http://golang.org/issue/2601 |
1897 outObj = stringList(importObj, nonGccObjs, ofile) | 1912 outObj = stringList(importObj, nonGccObjs, ofile) |
1898 | 1913 |
1899 return outGo, outObj, nil | 1914 return outGo, outObj, nil |
1900 } | 1915 } |
1901 | 1916 |
1902 // Run SWIG on all SWIG input files. | 1917 // Run SWIG on all SWIG input files. |
1903 func (b *builder) swig(p *Package, obj string, gccfiles []string) (outGo, outObj
[]string, err error) { | 1918 func (b *builder) swig(p *Package, obj string, gccfiles []string) (outGo, outObj
[]string, err error) { |
| 1919 |
| 1920 intgosize, err := b.swigIntSize(obj) |
| 1921 if err != nil { |
| 1922 return nil, nil, err |
| 1923 } |
| 1924 |
1904 for _, f := range p.SwigFiles { | 1925 for _, f := range p.SwigFiles { |
1905 » » goFile, objFile, err := b.swigOne(p, f, obj, false) | 1926 » » goFile, objFile, err := b.swigOne(p, f, obj, false, intgosize) |
1906 if err != nil { | 1927 if err != nil { |
1907 return nil, nil, err | 1928 return nil, nil, err |
1908 } | 1929 } |
1909 if goFile != "" { | 1930 if goFile != "" { |
1910 outGo = append(outGo, goFile) | 1931 outGo = append(outGo, goFile) |
1911 } | 1932 } |
1912 if objFile != "" { | 1933 if objFile != "" { |
1913 outObj = append(outObj, objFile) | 1934 outObj = append(outObj, objFile) |
1914 } | 1935 } |
1915 } | 1936 } |
1916 for _, f := range p.SwigCXXFiles { | 1937 for _, f := range p.SwigCXXFiles { |
1917 » » goFile, objFile, err := b.swigOne(p, f, obj, true) | 1938 » » goFile, objFile, err := b.swigOne(p, f, obj, true, intgosize) |
1918 if err != nil { | 1939 if err != nil { |
1919 return nil, nil, err | 1940 return nil, nil, err |
1920 } | 1941 } |
1921 if goFile != "" { | 1942 if goFile != "" { |
1922 outGo = append(outGo, goFile) | 1943 outGo = append(outGo, goFile) |
1923 } | 1944 } |
1924 if objFile != "" { | 1945 if objFile != "" { |
1925 outObj = append(outObj, objFile) | 1946 outObj = append(outObj, objFile) |
1926 } | 1947 } |
1927 } | 1948 } |
1928 return outGo, outObj, nil | 1949 return outGo, outObj, nil |
1929 } | 1950 } |
1930 | 1951 |
| 1952 // This code fails to build if sizeof(int) <= 32 |
| 1953 const swigIntSizeCode = ` |
| 1954 package main |
| 1955 const i int = 1 << 32 |
| 1956 ` |
| 1957 |
| 1958 // Determine the size of int on the target system for the -intgosize option |
| 1959 // of swig >= 2.0.9 |
| 1960 func (b *builder) swigIntSize(obj string) (intsize string, err error) { |
| 1961 src := filepath.Join(b.work, "swig_intsize.go") |
| 1962 if err = ioutil.WriteFile(src, []byte(swigIntSizeCode), 0644); err != ni
l { |
| 1963 return |
| 1964 } |
| 1965 srcs := []string{src} |
| 1966 |
| 1967 p := goFilesPackage(srcs) |
| 1968 |
| 1969 if _, _, e := buildToolchain.gc(b, p, obj, nil, srcs); e != nil { |
| 1970 return "32", nil |
| 1971 } |
| 1972 return "64", nil |
| 1973 } |
| 1974 |
1931 // Run SWIG on one SWIG input file. | 1975 // Run SWIG on one SWIG input file. |
1932 func (b *builder) swigOne(p *Package, file, obj string, cxx bool) (outGo, outObj
string, err error) { | 1976 func (b *builder) swigOne(p *Package, file, obj string, cxx bool, intgosize stri
ng) (outGo, outObj string, err error) { |
1933 n := 5 // length of ".swig" | 1977 n := 5 // length of ".swig" |
1934 if cxx { | 1978 if cxx { |
1935 n = 8 // length of ".swigcxx" | 1979 n = 8 // length of ".swigcxx" |
1936 } | 1980 } |
1937 base := file[:len(file)-n] | 1981 base := file[:len(file)-n] |
1938 goFile := base + ".go" | 1982 goFile := base + ".go" |
1939 cBase := base + "_gc." | 1983 cBase := base + "_gc." |
1940 gccBase := base + "_wrap." | 1984 gccBase := base + "_wrap." |
1941 gccExt := "c" | 1985 gccExt := "c" |
1942 if cxx { | 1986 if cxx { |
1943 gccExt = "cxx" | 1987 gccExt = "cxx" |
1944 } | 1988 } |
1945 soname := p.swigSoname(file) | 1989 soname := p.swigSoname(file) |
1946 | 1990 |
1947 _, gccgo := buildToolchain.(gccgoToolchain) | 1991 _, gccgo := buildToolchain.(gccgoToolchain) |
1948 | 1992 |
1949 // swig | 1993 // swig |
1950 args := []string{ | 1994 args := []string{ |
1951 "-go", | 1995 "-go", |
| 1996 "-intgosize", intgosize, |
1952 "-module", base, | 1997 "-module", base, |
1953 "-soname", soname, | 1998 "-soname", soname, |
1954 "-o", obj + gccBase + gccExt, | 1999 "-o", obj + gccBase + gccExt, |
1955 "-outdir", obj, | 2000 "-outdir", obj, |
1956 } | 2001 } |
1957 if gccgo { | 2002 if gccgo { |
1958 args = append(args, "-gccgo") | 2003 args = append(args, "-gccgo") |
1959 } | 2004 } |
1960 if cxx { | 2005 if cxx { |
1961 args = append(args, "-c++") | 2006 args = append(args, "-c++") |
1962 } | 2007 } |
1963 | 2008 |
1964 » if err := b.run(p.Dir, p.ImportPath, "swig", args, file); err != nil { | 2009 » if out, err := b.runOut(p.Dir, p.ImportPath, "swig", args, file); err !=
nil { |
| 2010 » » if len(out) > 0 { |
| 2011 » » » if bytes.Contains(out, []byte("Unrecognized option -intg
osize")) { |
| 2012 » » » » return "", "", errors.New("must have SWIG versio
n >= 2.0.9\n") |
| 2013 » » » } |
| 2014 » » » b.showOutput(p.Dir, p.ImportPath, b.processOutput(out)) |
| 2015 » » » return "", "", errPrintedOutput |
| 2016 » » } |
1965 return "", "", err | 2017 return "", "", err |
1966 } | 2018 } |
1967 | 2019 |
1968 var cObj string | 2020 var cObj string |
1969 if !gccgo { | 2021 if !gccgo { |
1970 // cc | 2022 // cc |
1971 cObj = obj + cBase + archChar | 2023 cObj = obj + cBase + archChar |
1972 if err := buildToolchain.cc(b, p, obj, cObj, obj+cBase+"c"); err
!= nil { | 2024 if err := buildToolchain.cc(b, p, obj, cObj, obj+cBase+"c"); err
!= nil { |
1973 return "", "", err | 2025 return "", "", err |
1974 } | 2026 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2027 if goarch != "amd64" || goos != "linux" && goos != "darwin" && goos != "
windows" { | 2079 if goarch != "amd64" || goos != "linux" && goos != "darwin" && goos != "
windows" { |
2028 fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/
amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0]) | 2080 fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/
amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0]) |
2029 os.Exit(2) | 2081 os.Exit(2) |
2030 } | 2082 } |
2031 buildGcflags = append(buildGcflags, "-race") | 2083 buildGcflags = append(buildGcflags, "-race") |
2032 buildLdflags = append(buildLdflags, "-race") | 2084 buildLdflags = append(buildLdflags, "-race") |
2033 buildCcflags = append(buildCcflags, "-D", "RACE") | 2085 buildCcflags = append(buildCcflags, "-D", "RACE") |
2034 buildContext.InstallTag = "race" | 2086 buildContext.InstallTag = "race" |
2035 buildContext.BuildTags = append(buildContext.BuildTags, "race") | 2087 buildContext.BuildTags = append(buildContext.BuildTags, "race") |
2036 } | 2088 } |
LEFT | RIGHT |