llvm.org GIT mirror llvm / 064517f
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276829 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Wilkins 3 years ago
2 changed file(s) with 26 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
996996 endforeach(d)
997997 set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
998998 add_custom_command(OUTPUT ${binpath}
999 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"
999 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "packages=${LLVM_GO_PACKAGES}"
10001000 ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
10011001 DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
10021002 ${llvmlibs} ${ARG_DEPENDS}
3434
3535 var packages = []pkg{
3636 {"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"},
37 {"tools/llgo", "llvm.org/llgo"},
3837 }
3938
4039 type compilerFlags struct {
144143 `, flags.cpp, flags.cxx, flags.ld)
145144 }
146145
147 func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string) {
146 func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string, packages []pkg) {
148147 args = addTag(args, "byollvm")
149148
150149 srcdir := llvmConfig("--src-root")
161160 panic(err.Error())
162161 }
163162
164 err = os.Symlink(filepath.Join(srcdir, p.llvmpath), path)
163 abspath := p.llvmpath
164 if !filepath.IsAbs(abspath) {
165 abspath = filepath.Join(srcdir, abspath)
166 }
167
168 err = os.Symlink(abspath, path)
165169 if err != nil {
166170 panic(err.Error())
167171 }
241245 ldflags := os.Getenv("CGO_LDFLAGS")
242246 gocmd := "go"
243247 llgo := ""
248 packagesString := ""
244249
245250 flags := []struct {
246251 name string
252257 {"llgo", &llgo},
253258 {"cppflags", &cppflags},
254259 {"ldflags", &ldflags},
260 {"packages", &packagesString},
255261 }
256262
257263 args := os.Args[1:]
270276 break
271277 }
272278
279 packages := packages
280 if packagesString != "" {
281 for _, field := range strings.Fields(packagesString) {
282 pos := strings.IndexRune(field, '=')
283 if pos == -1 {
284 fmt.Fprintf(os.Stderr, "invalid packages value %q, expected 'pkgpath=llvmpath [pkgpath=llvmpath ...]'\n", packagesString)
285 os.Exit(1)
286 }
287 packages = append(packages, pkg{
288 pkgpath: field[:pos],
289 llvmpath: field[pos+1:],
290 })
291 }
292 }
293
273294 switch args[0] {
274295 case "build", "get", "install", "run", "test":
275 runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags)
296 runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, packages)
276297 case "print-components":
277298 printComponents()
278299 case "print-config":