func (c *Class) Dump() { var tmp = fmt.Sprintln("########################################\t\t\tFUNCTIONS\t\t\t########################################") for _, f := range c.Functions { tmp += fmt.Sprintln(f) } tmp += fmt.Sprintln("########################################\t\t\tENUMS\t\t\t########################################") for _, e := range c.Enums { tmp += fmt.Sprintln(e) } utils.MakeFolder(utils.GetQtPkgPath("internal", "binding", "dump", c.Module)) utils.Save(utils.GetQtPkgPath("internal", "binding", "dump", c.Module, fmt.Sprintf("%v.txt", c.Name)), tmp) }
func createCgoLinux(module string) { var tmp string tmp += fmt.Sprintf("package %v\n", strings.ToLower(module)) tmp += "/*\n" tmp += "#cgo CPPFLAGS: -pipe -O2 -Wall -W -D_REENTRANT\n" tmp += "#cgo CPPFLAGS: -DQT_NO_DEBUG" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -DQT_%v_LIB", strings.ToUpper(m)) } tmp += "\n" tmp += "#cgo CPPFLAGS: -I/usr/local/Qt5.5.1/5.5/gcc/include -I/usr/local/Qt5.5.1/5.5/gcc/mkspecs/linux-g++\n" tmp += "#cgo CPPFLAGS:" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -I/usr/local/Qt5.5.1/5.5/gcc/include/Qt%v", m) } tmp += "\n\n" tmp += "#cgo LDFLAGS: -Wl,-O1 -Wl,-rpath,/usr/local/Qt5.5.1/5.5/gcc -Wl,-rpath,/usr/local/Qt5.5.1/5.5/gcc/lib\n" tmp += "#cgo LDFLAGS: -L/usr/local/Qt5.5.1/5.5/gcc/lib -L/usr/lib64" for _, m := range append(LibDeps[module], module) { if m == "UiTools" { tmp += fmt.Sprintf(" -lQt5%v", m) } } for _, m := range append(LibDeps[module], module) { if m != "UiTools" { tmp += fmt.Sprintf(" -lQt5%v", m) } } tmp += " -lpthread\n" tmp += "*/\n" tmp += fmt.Sprintf("import \"C\"\n") utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_linux_386.go"), strings.Replace(tmp, "lib64", "lib", -1)) utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_linux_amd64.go"), strings.Replace(tmp, "gcc", "gcc_64", -1)) }
func GenModule(name string) { var ( moduleT = name cppTmp string ) name = strings.ToLower(name) parser.GetModule(name) if ShouldBuild(moduleT) { utils.RemoveAll(utils.GetQtPkgPath(name)) utils.RemoveAll(utils.GetQtPkgPath("internal", "binding", "dump", moduleT)) var fcount = 0 for _, c := range parser.ClassMap { if moduleT == strings.TrimPrefix(c.Module, "Qt") { //Dry run to catch all unsupported for _, f := range map[string]func(*parser.Class) string{"cpp": CppTemplate, "h": HTemplate, "go": GoTemplate} { f(c) } for e, f := range map[string]func(*parser.Class) string{"cpp": CppTemplate, "h": HTemplate, "go": GoTemplate} { utils.MakeFolder(utils.GetQtPkgPath(name)) CopyCgo(moduleT) if moduleT == "AndroidExtras" { utils.Save(utils.GetQtPkgPath(name, fmt.Sprintf("%v_android.%v", strings.ToLower(c.Name), e)), f(c)) if e == "go" { c.Stub = true utils.Save(utils.GetQtPkgPath(name, fmt.Sprintf("%v.%v", strings.ToLower(c.Name), e)), f(c)) c.Stub = false } } else { if e == "cpp" { cppTmp += f(c) } else { utils.Save(utils.GetQtPkgPath(name, fmt.Sprintf("%v.%v", strings.ToLower(c.Name), e)), f(c)) } } } c.Dump() fcount += len(c.Functions) } } utils.Save(utils.GetQtPkgPath(name, fmt.Sprintf("%v.cpp", strings.ToLower(moduleT))), cppTmp) fmt.Printf("%v%v\tfunctions:%v", name, terminalSeperator(name), fcount) } }
func createCgoDarwin(module string) { var tmp string tmp += fmt.Sprintf("package %v\n", strings.ToLower(module)) tmp += "/*\n" tmp += "#cgo CPPFLAGS: -pipe -O2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W\n" tmp += "#cgo CPPFLAGS: -DQT_NO_DEBUG" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -DQT_%v_LIB", strings.ToUpper(m)) } tmp += "\n" tmp += "#cgo CPPFLAGS: -I/usr/local/Qt5.5.1/5.5/clang_64/mkspecs/macx-clang -F/usr/local/Qt5.5.1/5.5/clang_64/lib\n" tmp += "#cgo CPPFLAGS:" for _, m := range append(LibDeps[module], module) { if m == "UiTools" { tmp += fmt.Sprintf(" -I/usr/local/Qt5.5.1/5.5/clang_64/include/Qt%v", m) } else { tmp += fmt.Sprintf(" -I/usr/local/Qt5.5.1/5.5/clang_64/lib/Qt%v.framework/Headers", m) } } tmp += "\n" tmp += "#cgo CPPFLAGS: -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AGL.framework/Headers\n" tmp += "\n" tmp += "#cgo LDFLAGS: -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7\n" tmp += "#cgo LDFLAGS: -F/usr/local/Qt5.5.1/5.5/clang_64/lib" for _, m := range append(LibDeps[module], module) { if m == "UiTools" { tmp += fmt.Sprintf(" -L/usr/local/Qt5.5.1/5.5/clang_64/lib -lQt5%v", m) } } for _, m := range append(LibDeps[module], module) { if m != "UiTools" { tmp += fmt.Sprintf(" -framework Qt%v", m) } } tmp += " -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL\n" tmp += "*/\n" tmp += fmt.Sprintf("import \"C\"\n") utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_darwin_amd64.go"), tmp) }
func GenModule(name string) { if ShouldBuild(name) { var ( pkgName = strings.ToLower(name) suffix string ) if name == "AndroidExtras" { suffix = "_android" } //cleanup utils.RemoveAll(utils.GetQtPkgPath(pkgName)) utils.RemoveAll(utils.GetQtPkgPath("internal", "binding", "dump", name)) //prepare utils.MakeFolder(utils.GetQtPkgPath(pkgName)) CopyCgo(name) if name == "AndroidExtras" { utils.Save(utils.GetQtPkgPath(pkgName, "utils-androidextras_android.go"), utils.Load(utils.GetQtPkgPath("internal", "binding", "files", "utils-androidextras_android.go"))) } //dry run for _, c := range parser.ClassMap { if strings.TrimPrefix(c.Module, "Qt") == name { AddObjectNameFunctionIfNeeded(c) ManualWeakLink(c) } } CppTemplate("Qt" + name) HTemplate("Qt" + name) GoTemplate("Qt"+name, false) //generate utils.Save(utils.GetQtPkgPath(pkgName, pkgName+suffix+".cpp"), CppTemplate("Qt"+name)) utils.Save(utils.GetQtPkgPath(pkgName, pkgName+suffix+".h"), HTemplate("Qt"+name)) if name == "AndroidExtras" { utils.Save(utils.GetQtPkgPath(pkgName, pkgName+suffix+".go"), GoTemplate("Qt"+name, false)) } utils.Save(utils.GetQtPkgPath(pkgName, pkgName+".go"), GoTemplate("Qt"+name, name == "AndroidExtras")) } }
func createCgoWindows(module string) { var tmp string tmp += fmt.Sprintf("package %v\n", strings.ToLower(module)) tmp += "/*\n" tmp += "#cgo CPPFLAGS: -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra\n" tmp += "#cgo CPPFLAGS: -DUNICODE -DQT_NO_DEBUG" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -DQT_%v_LIB", strings.ToUpper(m)) } tmp += "\n" tmp += "#cgo CPPFLAGS: -IC:/Qt/Qt5.5.1/5.5/mingw492_32/include -IC:/Qt/Qt5.5.1/5.5/mingw492_32/mkspecs/win32-g++\n" tmp += "#cgo CPPFLAGS:" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -IC:/Qt/Qt5.5.1/5.5/mingw492_32/include/Qt%v", m) } tmp += "\n\n" tmp += "#cgo LDFLAGS: -Wl,-s -Wl,-subsystem,windows -mthreads -Wl,--allow-multiple-definition\n" tmp += "#cgo LDFLAGS: -LC:/Qt/Qt5.5.1/5.5/mingw492_32/lib" for _, m := range append(LibDeps[module], module) { if m == "UiTools" { tmp += fmt.Sprintf(" -lQt5%v", m) } } for _, m := range append(LibDeps[module], module) { if m != "UiTools" { tmp += fmt.Sprintf(" -lQt5%v", m) } } tmp += " -lmingw32 -lqtmain -lshell32\n" tmp += "*/\n" tmp += fmt.Sprintf("import \"C\"\n") utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_windows_386.go"), tmp) }
func createCgoandroidWindows(module string) { var tmp string tmp += fmt.Sprintf("package %v\n", strings.ToLower(module)) tmp += "/*\n" tmp += "#cgo CPPFLAGS: -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT\n" tmp += "#cgo CPPFLAGS: -DQT_NO_DEBUG" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -DQT_%v_LIB", strings.ToUpper(m)) } tmp += "\n" tmp += "#cgo CPPFLAGS: -IC:/Qt/Qt5.5.1/5.5/android_armv7/include -isystem C:/android/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem C:/android/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem C:/android/android-ndk/platforms/android-9/arch-arm/usr/include -IC:/Qt/Qt5.5.1/5.5/android_armv7/mkspecs/android-g++\n" tmp += "#cgo CPPFLAGS:" for _, m := range append(LibDeps[module], module) { tmp += fmt.Sprintf(" -IC:/Qt/Qt5.5.1/5.5/android_armv7/include/Qt%v", m) } tmp += "\n\n" tmp += "#cgo LDFLAGS: --sysroot=C:/android/android-ndk/platforms/android-9/arch-arm/ -Wl,-rpath=C:/Qt/Qt5.5.1/5.5/android_armv7/lib -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--allow-multiple-definition\n" tmp += "#cgo LDFLAGS: -LC:/android/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -LC:/android/android-ndk/platforms/android-9/arch-arm//usr/lib -LC:/Qt/Qt5.5.1/5.5/android_armv7/lib -LC:/android/android/ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -LC:/android/android/ndk/platforms/android-9/arch-arm//usr/lib" for _, m := range append(LibDeps[module], module) { if m == "UiTools" { tmp += fmt.Sprintf(" -lQt5%v", m) } } for _, m := range append(LibDeps[module], module) { if m != "UiTools" { tmp += fmt.Sprintf(" -lQt5%v", m) } } tmp += " -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc\n" tmp += "*/\n" tmp += fmt.Sprintf("import \"C\"\n") utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_android_arm.go"), tmp) }
func main() { var ( ending string buildTarget = "desktop" ) if len(os.Args) > 1 { buildTarget = os.Args[1] } if runtime.GOOS == "windows" { ending = ".exe" } fmt.Printf("_________________________Test-%v__________________________\n", buildTarget) runCmd(exec.Command("go", "build", "-o", path.Join(runtime.GOROOT(), "bin", fmt.Sprintf("qtdeploy%v", ending)), utils.GetQtPkgPath("internal", "deploy", "deploy.go")), "qtdeploy") for _, example := range []string{"widgets", path.Join("quick", "calc"), path.Join("quick", "dialog"), path.Join("quick", "view"), path.Join("qml", "application"), path.Join("qml", "prop")} { var before = time.Now() fmt.Print(example) runCmd(exec.Command(fmt.Sprintf("qtdeploy%v", ending), "test", buildTarget, path.Join(utils.GetQtPkgPath("internal", "examples"), example)), fmt.Sprintf("test.%v", example)) var sep = "\t" if len(example) < 8 { sep += "\t\t" } if len(example) >= 8 && len(example) < 17 { sep += "\t" } fmt.Printf("%v\t\t%v\n", sep, time.Since(before)/time.Second*time.Second) } }
func predeploy() { var copyCmd string switch runtime.GOOS { case "windows": copyCmd = "xcopy" default: copyCmd = "cp" } switch buildTarget { case "android": { utils.MakeFolder(filepath.Join(appPath, "android")) for _, dir := range []string{"drawable-hdpi", "drawable-ldpi", "drawable-mdpi"} { utils.MakeFolder(filepath.Join(depPath, "build", "res", dir)) runCmdOptional(exec.Command(copyCmd, filepath.Join(appPath, "android", "icon.png"), filepath.Join(depPath, "build", "res", dir, "icon.png")), "predeploy.cpicon") } var libPath = filepath.Join(depPath, "build", "libs", "armeabi-v7a") utils.MakeFolder(libPath) runCmd(exec.Command(copyCmd, filepath.Join(depPath, "libgo.so"), libPath), "predeploy.cplib") var ( qtPrefix string androidPrefix string ndkhost string ) switch runtime.GOOS { case "darwin", "linux": { qtPrefix = "/usr/local" androidPrefix = "/opt" ndkhost = runtime.GOOS + "-x86_64" runCmd(exec.Command("cp", "/usr/local/Qt5.5.1/5.5/android_armv7/jar/QtAndroid-bundled.jar", filepath.Join(depPath, "build", "libs")), "predeploy.cpqtandroid") runCmd(exec.Command("zip", "-d", filepath.Join(depPath, "build", "libs", "QtAndroid-bundled.jar"), "org/qtproject/qt5/android/QtNative.class"), "predeploy.patchqtandroid_main") for i := 1; i < 19; i++ { runCmd(exec.Command("zip", "-d", filepath.Join(depPath, "build", "libs", "QtAndroid-bundled.jar"), fmt.Sprintf("org/qtproject/qt5/android/QtNative$%v.class", i)), fmt.Sprintf("predeploy.patchqtandroid_%v", i)) } } case "windows": { qtPrefix = "C:\\Qt" androidPrefix = "C:\\android" ndkhost = runtime.GOOS var ( jdkVersion = strings.Split(runCmd(exec.Command("java", "-version"), "predeploy.jdk"), "\"")[1] jarPath = fmt.Sprintf("C:\\Program Files\\Java\\jdk%v\\bin\\jar.exe", jdkVersion) ) runCmd(exec.Command("xcopy", "C:\\Qt\\Qt5.5.1\\5.5\\android_armv7\\jar\\QtAndroid-bundled.jar", filepath.Join(depPath, "build", "libs")), "predeploy.cpqtandroid") var jarUnzip = exec.Command(jarPath, "-xf", filepath.Join(depPath, "build", "libs", "QtAndroid-bundled.jar")) jarUnzip.Dir = filepath.Join(depPath, "build", "libs") runCmd(jarUnzip, "predeploy.unzipqtandroid") utils.RemoveAll(filepath.Join(depPath, "build", "libs", "QtAndroid-bundled.jar")) utils.RemoveAll(filepath.Join(depPath, "build", "libs", "org", "qtproject", "qt5", "android", "QtNative.class")) for i := 1; i < 19; i++ { utils.RemoveAll(filepath.Join(depPath, "build", "libs", "org", "qtproject", "qt5", "android", fmt.Sprintf("QtNative$%v.class", i))) } var zipQtAndroid = exec.Command(jarPath, "-cmf", filepath.Join(depPath, "build", "libs", "META-INF", "MANIFEST.MF"), filepath.Join(depPath, "build", "libs", "QtAndroid-bundled.jar"), "org") zipQtAndroid.Dir = filepath.Join(depPath, "build", "libs") runCmd(zipQtAndroid, "predeploy.zipqtandroid") utils.RemoveAll(filepath.Join(depPath, "build", "libs", "org")) utils.RemoveAll(filepath.Join(depPath, "build", "libs", "META-INF")) } } utils.MakeFolder(filepath.Join(depPath, "build", "src", "org", "qtproject", "qt5", "android")) runCmd(exec.Command(copyCmd, utils.GetQtPkgPath("internal", "android", "patch", "QtNative.java"), filepath.Join(depPath, "build", "src", "org", "qtproject", "qt5", "android")), "predeploy.cpqtandroidpatched") var out, err = json.Marshal(&struct { Qt string `json:"qt"` Sdk string `json:"sdk"` SdkBuildToolsRevision string `json:"sdkBuildToolsRevision"` Ndk string `json:"ndk"` Toolchainprefix string `json:"toolchain-prefix"` Toolprefix string `json:"tool-prefix"` Toolchainversion string `json:"toolchain-version"` Ndkhost string `json:"ndk-host"` Targetarchitecture string `json:"target-architecture"` AndroidPackageSourceDirectory string `json:"android-package-source-directory"` Qmlrootpath string `json:"qml-root-path"` Applicationbinary string `json:"application-binary"` }{ Qt: filepath.Join(qtPrefix, "Qt5.5.1", "5.5", "android_armv7"), Sdk: filepath.Join(androidPrefix, "android-sdk"), SdkBuildToolsRevision: "23.0.2", Ndk: filepath.Join(androidPrefix, "android-ndk"), Toolchainprefix: "arm-linux-androideabi", Toolprefix: "arm-linux-androideabi", Toolchainversion: "4.9", Ndkhost: ndkhost, Targetarchitecture: "armeabi-v7a", AndroidPackageSourceDirectory: filepath.Join(appPath, "android"), Qmlrootpath: filepath.Join(appPath, "qml"), Applicationbinary: filepath.Join(depPath, "libgo.so"), }) if err != nil { fmt.Println("predeploy.json", string(out), err) os.Exit(1) } utils.Save(filepath.Join(depPath, "android-libgo.so-deployment-settings.json"), string(out)) } case "desktop": { switch runtime.GOOS { case "darwin": { utils.Save(filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v_sh", appName, appName)), darwinSH()) utils.Save(filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/Info.plist", appName)), darwinPLIST()) //TODO: icon + plist } case "linux": { utils.Save(filepath.Join(depPath, fmt.Sprintf("%v.sh", appName)), linuxSH()) } case "windows": { //TODO: icon windres } } } } }