forked from OSchip/llvm-project
[llvm-go] parameterize $GOPATH construction
Summary: To build llgo, you must currently ensure that llgo is in the tools/llgo directory, due to a hard-coded path in llvm-go. To support the use of LLVM_EXTERNAL_LLGO_SOURCE_DIR, we introduce a flag to llvm-go that enables the caller to specify the paths to symlink in the temporary $GOPATH. Reviewers: pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D21634 llvm-svn: 276829
This commit is contained in:
parent
5fdb3b89da
commit
5bf7d8102d
|
@ -997,7 +997,7 @@ function(llvm_add_go_executable binary pkgpath)
|
||||||
endforeach(d)
|
endforeach(d)
|
||||||
set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
|
set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
add_custom_command(OUTPUT ${binpath}
|
add_custom_command(OUTPUT ${binpath}
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"
|
COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "packages=${LLVM_GO_PACKAGES}"
|
||||||
${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
|
${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
|
||||||
DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
|
DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
|
||||||
${llvmlibs} ${ARG_DEPENDS}
|
${llvmlibs} ${ARG_DEPENDS}
|
||||||
|
|
|
@ -35,7 +35,6 @@ type pkg struct {
|
||||||
|
|
||||||
var packages = []pkg{
|
var packages = []pkg{
|
||||||
{"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"},
|
{"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"},
|
||||||
{"tools/llgo", "llvm.org/llgo"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type compilerFlags struct {
|
type compilerFlags struct {
|
||||||
|
@ -145,7 +144,7 @@ type (run_build_sh int)
|
||||||
`, flags.cpp, flags.cxx, flags.ld)
|
`, flags.cpp, flags.cxx, flags.ld)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string) {
|
func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string, packages []pkg) {
|
||||||
args = addTag(args, "byollvm")
|
args = addTag(args, "byollvm")
|
||||||
|
|
||||||
srcdir := llvmConfig("--src-root")
|
srcdir := llvmConfig("--src-root")
|
||||||
|
@ -162,7 +161,12 @@ func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, l
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Symlink(filepath.Join(srcdir, p.llvmpath), path)
|
abspath := p.llvmpath
|
||||||
|
if !filepath.IsAbs(abspath) {
|
||||||
|
abspath = filepath.Join(srcdir, abspath)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Symlink(abspath, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -242,6 +246,7 @@ func main() {
|
||||||
ldflags := os.Getenv("CGO_LDFLAGS")
|
ldflags := os.Getenv("CGO_LDFLAGS")
|
||||||
gocmd := "go"
|
gocmd := "go"
|
||||||
llgo := ""
|
llgo := ""
|
||||||
|
packagesString := ""
|
||||||
|
|
||||||
flags := []struct {
|
flags := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -253,6 +258,7 @@ func main() {
|
||||||
{"llgo", &llgo},
|
{"llgo", &llgo},
|
||||||
{"cppflags", &cppflags},
|
{"cppflags", &cppflags},
|
||||||
{"ldflags", &ldflags},
|
{"ldflags", &ldflags},
|
||||||
|
{"packages", &packagesString},
|
||||||
}
|
}
|
||||||
|
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
|
@ -271,9 +277,24 @@ LOOP:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packages := packages
|
||||||
|
if packagesString != "" {
|
||||||
|
for _, field := range strings.Fields(packagesString) {
|
||||||
|
pos := strings.IndexRune(field, '=')
|
||||||
|
if pos == -1 {
|
||||||
|
fmt.Fprintf(os.Stderr, "invalid packages value %q, expected 'pkgpath=llvmpath [pkgpath=llvmpath ...]'\n", packagesString)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
packages = append(packages, pkg{
|
||||||
|
pkgpath: field[:pos],
|
||||||
|
llvmpath: field[pos+1:],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "build", "get", "install", "run", "test":
|
case "build", "get", "install", "run", "test":
|
||||||
runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags)
|
runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, packages)
|
||||||
case "print-components":
|
case "print-components":
|
||||||
printComponents()
|
printComponents()
|
||||||
case "print-config":
|
case "print-config":
|
||||||
|
|
Loading…
Reference in New Issue