本文整理汇总了Golang中go/build.Package.SFiles方法的典型用法代码示例。如果您正苦于以下问题:Golang Package.SFiles方法的具体用法?Golang Package.SFiles怎么用?Golang Package.SFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/build.Package
的用法示例。
在下文中一共展示了Package.SFiles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getPackage
func getPackage(pkgpath string) (*build.Package, error) {
var err error
var pkg *build.Package
pkg, err = build.Import(pkgpath, "", 0)
if err != nil {
return nil, err
} else {
for i, filename := range pkg.GoFiles {
pkg.GoFiles[i] = path.Join(pkg.Dir, filename)
}
for i, filename := range pkg.CFiles {
pkg.CFiles[i] = path.Join(pkg.Dir, filename)
}
// Look for .ll files, treat them the same as .s.
// TODO look for build tags in the .ll file, check filename
// for GOOS/GOARCH, etc.
var llfiles []string
llfiles, err = filepath.Glob(pkg.Dir + "/*.ll")
for _, file := range llfiles {
pkg.SFiles = append(pkg.SFiles, file)
}
}
return pkg, nil
}
示例2: buildPackage
func buildPackage(pkg *build.Package, output string) error {
args := []string{"-c", "-triple", triple}
dir, file := path.Split(pkg.ImportPath)
if pkg.IsCommand() || test {
if output == "" {
output = file
}
} else {
dir = filepath.Join(pkgroot, dir)
err := os.MkdirAll(dir, os.FileMode(0755))
if err != nil {
return err
}
if output == "" {
output = path.Join(dir, file+".bc")
}
}
if !pkg.IsCommand() || test {
args = append(args, "-importpath", pkg.ImportPath)
}
var cgoCFLAGS, cgoCPPFLAGS, cgoLDFLAGS []string
if len(pkg.CFiles) > 0 || len(pkg.CgoFiles) > 0 {
// TODO(axw) process pkg-config
cgoCFLAGS = append(envFields("CGO_CFLAGS"), pkg.CgoCFLAGS...)
cgoCPPFLAGS = append(envFields("CGO_CPPFLAGS"), pkg.CgoCPPFLAGS...)
//cgoCXXFLAGS = append(envFields("CGO_CXXFLAGS"), pkg.CgoCXXFLAGS...)
cgoCPPFLAGS = append(cgoCPPFLAGS, "-I", workdir, "-I", pkg.Dir)
cgoLDFLAGS = append(envFields("CGO_LDFLAGS"), pkg.CgoLDFLAGS...)
// Get the library dir in which to find libgcc, libstdc++, etc.
// We need to do this because we rely on clang to link; in Ubuntu 14.04
// beta 1, there is no g++-4.9, but there is gccgo-4.9. Clang sees the
// partial 4.9 lib directory and uses it instead of 4.8, which is what
// should be used.
if gcclib, err := findGcclib(); err != nil {
return fmt.Errorf("failed to locate gcc lib dir: %v", err)
} else if gcclib != "." {
cgoLDFLAGS = append(cgoLDFLAGS, "-L", gcclib)
}
}
var gofiles, cfiles []string
if len(pkg.CgoFiles) > 0 {
var err error
gofiles, cfiles, err = runCgo(pkg.ImportPath, pkg.CgoFiles, cgoCPPFLAGS, cgoCFLAGS)
if err != nil {
return err
}
}
gofiles = append(gofiles, pkg.GoFiles...)
cfiles = append(cfiles, pkg.CFiles...)
_, file = path.Split(output)
tempfile := path.Join(workdir, file+".bc")
args = append(args, fmt.Sprintf("-g=%v", generateDebug))
args = append(args, "-o", tempfile)
args = append(args, gofiles...)
if test {
args = append(args, pkg.TestGoFiles...)
}
cmd := exec.Command(llgobin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := runCmd(cmd); err != nil {
return err
}
// Remove the .S files and add them to cfiles.
for i := 0; i < len(pkg.SFiles); i++ {
sfile := pkg.SFiles[i]
if strings.HasSuffix(sfile, ".S") {
cfiles = append(cfiles, sfile)
pkg.SFiles = append(pkg.SFiles[:i], pkg.SFiles[i+1:]...)
i--
}
}
// Compile and link .c files in.
llvmlink := filepath.Join(llvmbindir, "llvm-link")
for _, cfile := range cfiles {
bcfile := filepath.Join(workdir, filepath.Base(cfile+".bc"))
args = []string{"-c", "-o", bcfile}
if triple != "pnacl" {
args = append(args, "-target", triple, "-emit-llvm")
}
args = append(args, cgoCFLAGS...)
args = append(args, cgoCPPFLAGS...)
args = append(args, cfile)
cmd := exec.Command(clang, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := runCmd(cmd)
if err != nil {
os.Remove(bcfile)
return err
}
cmd = exec.Command(llvmlink, "-o", tempfile, tempfile, bcfile)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = runCmd(cmd)
//.........这里部分代码省略.........