// NAME // specgen - generates Go code from the UPnP specification files. // // DESCRIPTION // The specification is available for download from: // // OPTIONS // -s, --specs_dir=<spec directory> // Path to the specification storage directory. This is used to find (and download if not present) the specification ZIP files. Defaults to 'specs' // -o, --out_dir=<output directory> // Path to the output directory. This is is where the DCP source files will be placed. Should normally correspond to the directory for github.com/huin/goupnp/dcps. Defaults to '../dcps' // --nogofmt // Disable passing the output through gofmt. Do this if debugging code output problems and needing to see the generated code prior to being passed through gofmt. func TaskSpecgen(t *tasking.T) { specsDir := fallbackStrValue("specs", t.Flags.String("specs_dir"), t.Flags.String("s")) if err := os.MkdirAll(specsDir, os.ModePerm); err != nil { t.Fatalf("Could not create specs-dir %q: %v\n", specsDir, err) } outDir := fallbackStrValue("../dcps", t.Flags.String("out_dir"), t.Flags.String("o")) useGofmt := !t.Flags.Bool("nogofmt") NEXT_DCP: for _, d := range dcpMetadata { specFilename := filepath.Join(specsDir, d.Name+".zip") err := acquireFile(specFilename, d.XMLSpecURL) if err != nil { t.Logf("Could not acquire spec for %s, skipping: %v\n", d.Name, err) continue NEXT_DCP } dcp := newDCP(d) if err := dcp.processZipFile(specFilename); err != nil { log.Printf("Error processing spec for %s in file %q: %v", d.Name, specFilename, err) continue NEXT_DCP } for i, hack := range d.Hacks { if err := hack(dcp); err != nil { log.Printf("Error with Hack[%d] for %s: %v", i, d.Name, err) continue NEXT_DCP } } dcp.writePackage(outDir, useGofmt) if err := dcp.writePackage(outDir, useGofmt); err != nil { log.Printf("Error writing package %q: %v", dcp.Metadata.Name, err) continue NEXT_DCP } } }
// NAME // deploy - Deploy the application // // DESCRIPTION // Build and deploy the application on the device via ant. // // OPTIONS // --verbose, -v // run in verbose mode func TaskDeploy(t *tasking.T) { deployAndroid(t) if t.Failed() { t.Fatalf("%-20s %s\n", status(t.Failed()), "Build and deploy the application on the device via ant.") } t.Logf("%-20s %s\n", status(t.Failed()), "Build and deploy the application on the device via ant.") }
func deployAndroid(t *tasking.T) { buildAndroid(t) err := t.Exec("ant -f android/build.xml clean debug") if err != nil { t.Error(err) } uploadAndroid(t) }
// NAME // say-hello - Say hello to current user // // DESCRIPTION // Print out hello to current user // // OPTIONS // --verbose, -v // run in verbose mode func TaskSayHello(t *tasking.T) { user, _ := user.Current() if t.Flags.Bool("v") || t.Flags.Bool("verbose") { t.Logf("Hello %s, the time now is %s\n", user.Name, time.Now()) } else { t.Logf("Hello %s\n", user.Name) } }
func runXorg(t *tasking.T, flags string) { err := t.Exec( filepath.Join("bin", LibName), flags, ) if err != nil { t.Error(err) } }
func init() { var t *tasking.T u, err := user.Current() if err != nil { t.Fatal(err) } username = u.Username }
// NAME // build - Build the application // // DESCRIPTION // Build the application for the given platforms. // // OPTIONS // --flags=<FLAGS> // pass FLAGS to the compiler // --verbose, -v // run in verbose mode func TaskBuild(t *tasking.T) { for _, platform := range t.Args { buildFun[platform](t) } if t.Failed() { t.Fatalf("%-20s %s\n", status(t.Failed()), "Build the application for the given platforms.") } t.Logf("%-20s %s\n", status(t.Failed()), "Build the application for the given platforms.") }
func runXorg(t *tasking.T) { err := t.Exec( filepath.Join("bin", LibName), t.Flags.String("flags"), ) if err != nil { t.Error(err) } }
// NAME // test - Run the tests // // DESCRIPTION // Build and run the tests on the given platform returning output using logcat. // // OPTIONS // --flags=<FLAGS> // pass the given flags to the executable // --verbose, -v // run in verbose mode func TaskTest(t *tasking.T) { TaskBuild(t) if f, ok := runFun[t.Args[0]]; ok { f(t) } if t.Failed() { t.Fatalf("%-20s %s\n", status(t.Failed()), "Run the example on the given platforms.") } t.Logf("%-20s %s\n", status(t.Failed()), "Run the example on the given platforms.") }
func runXorg(t *tasking.T) { buildXorg(t) err := t.Exec( filepath.Join("bin", ProjectName), t.Flags.String("flags"), ) if err != nil { t.Error(err) } }
// NAME // test - Run black-box tests // // DESCRIPTION // Build and run the application on the given platforms. // // OPTIONS // --flags=<FLAGS> // pass the flags to the executable // --logcat=Mandala:* stdout:* stderr:* *:S // show logcat output (android only) // --verbose, -v // run in verbose mode func TaskTest(t *tasking.T) { TaskBuild(t) for _, platform := range t.Args { runFun[platform](t) } if t.Failed() { t.Fatalf("%-20s %s\n", status(t.Failed()), "Run the application on the given platforms.") } t.Logf("%-20s %s\n", status(t.Failed()), "Run the application on the given platforms.") }
func buildXorg(t *tasking.T) { err := t.Exec( `sh -c "`, "GOPATH=`pwd`:$GOPATH", `go get`, t.Flags.String("flags"), LibName, `"`, ) if err != nil { t.Error(err) } }
func buildXorg(t *tasking.T) { err := t.Exec( `sh -c "`, "GOPATH=`pwd`:$GOPATH", `go install`, t.Flags.String("buildflags"), ProjectName, `"`, ) if err != nil { t.Error(err) } }
// NAME // release - Build the application in 'release mode' // // DESCRIPTION // Build the application for Android in 'release mode'. // // OPTIONS // --flags=<FLAGS> // pass FLAGS to the compiler // --verbose, -v // run in verbose mode func TaskRelease(t *tasking.T) { // Build app in 'release mode' buildAndroid(t, true) // Sign and 'zipalign' app signAndroid(t) // Check task if t.Failed() { t.Fatalf("%-20s %s\n", status(t.Failed()), "Release the application for Android.") } t.Logf("%-20s %s\n", status(t.Failed()), "Release the application for Android.") }
// NAME // say-hello - Say hello to current user // // DESCRIPTION // Print out hello to current user // // OPTIONS // -n, --name="NAME" // say hello to an user with the given NAME // -v, --verbose // run in verbose mode func TaskSayHello(t *tasking.T) { username := t.Flags.String("name") if username == "" { user, _ := user.Current() username = user.Name } if t.Flags.Bool("verbose") { t.Logf("Hello %s, the time now is %s\n", username, time.Now()) } else { t.Logf("Hello %s\n", username) } }
// NAME // specgen - generates Go code from the UPnP specification files. // // DESCRIPTION // The specification is available for download from: // // OPTIONS // -s, --spec_filename=<upnpresources.zip> // Path to the specification file, available from http://upnp.org/resources/upnpresources.zip // -o, --out_dir=<output directory> // Path to the output directory. This is is where the DCP source files will be placed. Should normally correspond to the directory for github.com/huin/goupnp/dcps // --nogofmt // Disable passing the output through gofmt. Do this if debugging code output problems and needing to see the generated code prior to being passed through gofmt. func TaskSpecgen(t *tasking.T) { specFilename := t.Flags.String("spec-filename") if specFilename == "" { specFilename = t.Flags.String("s") } if specFilename == "" { t.Fatal("--spec_filename is required") } outDir := t.Flags.String("out-dir") if outDir == "" { outDir = t.Flags.String("o") } if outDir == "" { log.Fatal("--out_dir is required") } useGofmt := !t.Flags.Bool("nogofmt") specArchive, err := openZipfile(specFilename) if err != nil { t.Fatalf("Error opening spec file: %v", err) } defer specArchive.Close() dcpCol := newDcpsCollection() for _, f := range globFiles("standardizeddcps/*/*.zip", specArchive.Reader) { dirName := strings.TrimPrefix(f.Name, "standardizeddcps/") slashIndex := strings.Index(dirName, "/") if slashIndex == -1 { // Should not happen. t.Logf("Could not find / in %q", dirName) return } dirName = dirName[:slashIndex] dcp := dcpCol.dcpForDir(dirName) if dcp == nil { t.Logf("No alias defined for directory %q: skipping %s\n", dirName, f.Name) continue } else { t.Logf("Alias found for directory %q: processing %s\n", dirName, f.Name) } dcp.processZipFile(f) } for _, dcp := range dcpCol.dcpByAlias { if err := dcp.writePackage(outDir, useGofmt); err != nil { log.Printf("Error writing package %q: %v", dcp.Metadata.Name, err) } } }
func buildXorg(t *tasking.T, buildAll bool) { allFlagString := "" if buildAll { allFlagString = "-a" } err := t.Exec( `sh -c "`, "GOPATH=`pwd`:$GOPATH", `go install`, allFlagString, LibName, `"`, ) if err != nil { t.Error(err) } }
// NAME // cross-compile - cross-compiles gh for current platform. // // DESCRIPTION // Cross-compiles gh for current platform. Build artifacts will be in target/VERSION func TaskCrossCompile(t *tasking.T) { t.Logf("Cross-compiling gh for %s...\n", runtime.GOOS) t.Logf("GOPATH=%s\n", os.Getenv("GOPATH")) err := t.Exec("goxc", "-wd=.", "-os="+runtime.GOOS, "-c="+runtime.GOOS) if err != nil { t.Fatalf("Can't cross-compile gh: %s\n", err) } }
// NAME // generate files for 'model_task.go' func TaskInit(t *tasking.T) { newTestdata := false src := "model_task.go" srcInfo, err := os.Stat(src) if err != nil { t.Fatal(err) } dstInfo, err := os.Stat(filepath.Join("model", "sqlmodel.go")) if err != nil { newTestdata = true } if err := os.Chdir("test"); err != nil { t.Fatal(err) } if newTestdata || srcInfo.ModTime().After(dstInfo.ModTime()) { taskBuildModel(t) } }
func runAndroid(t *tasking.T) { buildAndroid(t) deployAndroid(t) err := t.Exec( fmt.Sprintf( "adb shell am start -a android.intent.action.MAIN -n net.mandala.%s/android.app.NativeActivity", ProjectName, )) if err != nil { t.Error(err) } err = t.Exec("adb shell logcat", "Mandala:* stdout:* stderr:* *:S") if err != nil { t.Error(err) } }
func runAndroid(t *tasking.T, flags string) { deployAndroid(t) err := t.Exec( fmt.Sprintf( "adb shell am start -a android.intent.action.MAIN -n %s.%s/android.app.NativeActivity", Domain, LibName, )) if err != nil { t.Error(err) } if t.Flags.Bool("logcat") { err = t.Exec("adb shell logcat") if err != nil { t.Error(err) } } }
func runAndroid(t *tasking.T) { deployAndroid(t) err := t.Exec( fmt.Sprintf( "adb shell am start -a android.intent.action.MAIN -n %s.%s/android.app.NativeActivity", Domain, LibName, )) if err != nil { t.Error(err) } if tags := t.Flags.String("logcat"); tags != "" { err = t.Exec("adb", "shell", "logcat", tags) if err != nil { t.Error(err) } } }
// NAME // clean - Clean deployment leftovers and wizard configs // // DESCRIPTION // Runs `rice clean` to remove leftovers from resource embedding, // purges wizard configs if any left in project dir. // // OPTIONS // --all, -a // Remove platform specific output dir func TaskClean(t *tasking.T) { for _, name := range []string{wizardManifest, wizardIcon, docFile} { if err := os.Remove(name); err != nil && !os.IsNotExist(err) { t.Fatalf("clean: %v", err) } } if err := exec.Command("rice", "clean").Run(); err != nil { t.Fatalf("clean: rice: %v", err) } if t.Flags.Bool("all") { path := fmt.Sprintf("%s/%s", outDir, runtime.GOOS) if len(path) < 2 { t.Fatal("can't happen") } if err := os.RemoveAll(path); err != nil { t.Fatal(err) } } }
// NAME // install-deps - install dependencies with go get // // DESCRIPTION // Install dependencies with go get. func TaskInstallDeps(t *tasking.T) { deps := []string{ "github.com/laher/goxc", } for _, dep := range deps { t.Logf("Installing %s\n", dep) err := t.Exec("go get", dep) if err != nil { t.Fatalf("Can't download dependency %s", err) } } }
// NAME // gh-user - Get URL for a given GitHub user login // // DESCRIPTION // Given a GitHub user login, call the GitHub API to get this user and print out the user page URL. // // For example // // $ gotask git-hub-user jingweno // // OPTIONS // --verbose, -v // run in verbose mode func TaskGitHubUser(t *tasking.T) { if len(t.Args) == 0 { t.Error("No GitHub user login is provided!") return } login := t.Args[0] data, err := fetchGitHubUser(login) if err != nil { t.Error(err) return } url, ok := data["html_url"] if !ok { t.Errorf("No URL found for user login %s\n", login) return } t.Logf("The URL for user %s is %s\n", login, url) }
func buildAndroid(t *tasking.T) { os.MkdirAll("android/libs/armeabi-v7a", 0777) os.MkdirAll("android/obj/local/armeabi-v7a", 0777) err := t.Exec(`sh -c "`, `CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`, "GOPATH=`pwd`:$GOPATH", `GOROOT=""`, "GOOS=linux", "GOARCH=arm", "GOARM=7", "CGO_ENABLED=1", "$GOANDROID/go install", t.Flags.String("flags"), "$GOFLAGS", `-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`, "-tags android", ProjectName, `"`, ) if err != nil { t.Error(err) } os.MkdirAll(ARMBinaryPath, 0777) for _, path := range SharedLibraryPaths { err := t.Exec( "cp", filepath.Join(ARMBinaryPath, ProjectName), filepath.Join(path, "lib"+ProjectName+".so"), ) if err != nil { t.Error(err) } } }
// NAME // generate-objects - Generate net/artproto/gen_objects.go // // DESCRIPTION // Generates trivial setter methods and constants for the object types // defined in net/artproto/objects. // // OPTIONS // --nogofmt // do not process the generated code through gofmt func TaskGenerateObjects(t *tasking.T) { var w io.WriteCloser w, err := os.Create(filepath.Join("net", "artproto", "gen_objects.go")) if err != nil { t.Fatal(err) } if !t.Flags.Bool("nogofmt") { if gofmt, err := codegen.NewGofmtWriteCloser(w); err != nil { w.Close() t.Fatal(err) } else { w = gofmt } } defer w.Close() cw := &CodeWriter{W: w} cw.Printf(`// GENERATED CODE - DO NOT EDIT. // This code is generated with the following command: // // gotask generate-objects `) cw.Printf("package artproto\n") for _, typeID := range artproto.ObjTypeIDs { if err := generateForObject(cw, typeID); err != nil { t.Fatal(err) } } if cw.Err != nil { t.Fatal(cw.Err) } }
// NAME // test-mysql - check data generated from ModSQL into a MySQL database // // DESCRIPTION // // To create the database: // // mysql -p // mysql> create database modsql_test; // mysql> GRANT ALL PRIVILEGES ON modsql_test.* to USER@localhost; // // Note: substitute "USER" by your user name. // // To remove it: // // mysql> drop database modsql_test; func TaskTestMySQL(t *tasking.T) { // Format used in "github.com/serbaut/go-mysql" //db, err := sql.Open("mysql", fmt.Sprintf("mysql://%s@(unix)/%s?socket=%s", //username, dbname, host.mysql)) db, err := sql.Open("mysql", fmt.Sprintf("%s@unix(%s)/%s?parseTime=true", username, host.mysql, dbname)) if err != nil { t.Fatal(err) } if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_init.sql")); err != nil { t.Error(err) } else { if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_test.sql")); err != nil { t.Error(err) } testInsert(t, db, modsql.MySQL) if err = modsql.Load(db, filepath.Join("data", "sql", "mysql_drop.sql")); err != nil { t.Error(err) } } db.Close() if !t.Failed() { t.Log("--- PASS") } }
func rm_rf(t *tasking.T, path string) error { return t.Exec("rm -rf", path) }
// NAME // build - Build the application // // DESCRIPTION // Build the application for the given platforms. // // OPTIONS // --flags=<FLAGS> // pass FLAGS to the compiler // --verbose, -v // run in verbose mode func TaskBuild(t *tasking.T) { if len(t.Args) < 1 { t.Error("You must specify a build platform!") } else { for _, platform := range t.Args { buildFun[platform](t) } } if t.Failed() { t.Fatalf("%-20s %s\n", status(t.Failed()), "Build the application for the given platforms.") } t.Logf("%-20s %s\n", status(t.Failed()), "Build the application for the given platforms.") }