| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 package main | 7 package main |
| 8 | 8 |
| 9 // Example use: | 9 // Example use: |
| 10 // git clone https://skia.googlesource.com/skia.git | 10 // git clone https://skia.googlesource.com/skia.git |
| 11 // cd skia | 11 // cd skia |
| 12 // SKIA=$PWD | 12 // SKIA=$PWD |
| 13 // cd experimental/fiddle | 13 // cd tools/fiddle |
| 14 // go get github.com/skia-dev/glog | 14 // go get github.com/skia-dev/glog |
| 15 // go get go.skia.org/infra/go/util | 15 // go get go.skia.org/infra/go/util |
| 16 // go build fiddler.go | 16 // go build fiddler.go |
| 17 // # compile prerequisites | 17 // # compile prerequisites |
| 18 // ./fiddler "$SKIA" | 18 // ./fiddler "$SKIA" |
| 19 // # compile and run a fiddle | 19 // # compile and run a fiddle |
| 20 // ./fiddler "$SKIA" draw.cpp | ./parse-fiddle-output | 20 // ./fiddler "$SKIA" draw.cpp | ./parse-fiddle-output |
| 21 // # compile and run a different fiddle | 21 // # compile and run a different fiddle |
| 22 // ./fiddler "$SKIA" ANOTHER_FIDDLE.cpp | ./parse-fiddle-output | 22 // ./fiddler "$SKIA" ANOTHER_FIDDLE.cpp | ./parse-fiddle-output |
| 23 | 23 |
| 24 import ( | 24 import ( |
| 25 "bytes" | 25 "bytes" |
| 26 "fmt" | 26 "fmt" |
| 27 "io" | 27 "io" |
| 28 "io/ioutil" | 28 "io/ioutil" |
| 29 "os" | 29 "os" |
| 30 "os/exec" | 30 "os/exec" |
| 31 "path" | 31 "path" |
| 32 "syscall" | 32 "syscall" |
| 33 | 33 |
| 34 "github.com/skia-dev/glog" | 34 "github.com/skia-dev/glog" |
| 35 "go.skia.org/infra/go/util" | 35 "go.skia.org/infra/go/util" |
| 36 ) | 36 ) |
| 37 | 37 |
| 38 func fiddlePath() string { |
| 39 return path.Join("tools", "fiddle") |
| 40 } |
| 38 func setResourceLimits() error { | 41 func setResourceLimits() error { |
| 39 const maximumTimeInSeconds = 5 | 42 const maximumTimeInSeconds = 5 |
| 40 limit := syscall.Rlimit{maximumTimeInSeconds, maximumTimeInSeconds} | 43 limit := syscall.Rlimit{maximumTimeInSeconds, maximumTimeInSeconds} |
| 41 if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &limit); err != nil { | 44 if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &limit); err != nil { |
| 42 return err | 45 return err |
| 43 } | 46 } |
| 44 const maximumMemoryInBytes = 1 << 28 | 47 const maximumMemoryInBytes = 1 << 28 |
| 45 limit = syscall.Rlimit{maximumMemoryInBytes, maximumMemoryInBytes} | 48 limit = syscall.Rlimit{maximumMemoryInBytes, maximumMemoryInBytes} |
| 46 return syscall.Setrlimit(syscall.RLIMIT_AS, &limit) | 49 return syscall.Setrlimit(syscall.RLIMIT_AS, &limit) |
| 47 } | 50 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 69 return "@" + path.Join(skiaSrc, "cmake", "skia_link_arguments.txt") | 72 return "@" + path.Join(skiaSrc, "cmake", "skia_link_arguments.txt") |
| 70 } | 73 } |
| 71 | 74 |
| 72 // fiddler compiles the input, links against skia, and runs the executable. | 75 // fiddler compiles the input, links against skia, and runs the executable. |
| 73 // @param skiaSrc: the base directory of the Skia repository | 76 // @param skiaSrc: the base directory of the Skia repository |
| 74 // @param inputReader: C++ fiddle source | 77 // @param inputReader: C++ fiddle source |
| 75 // @param output: stdout of executable sent here | 78 // @param output: stdout of executable sent here |
| 76 // @param tempDir: where to place the compiled executable | 79 // @param tempDir: where to place the compiled executable |
| 77 func fiddler(skiaSrc string, inputReader io.Reader, output io.Writer, tempDir st
ring) error { | 80 func fiddler(skiaSrc string, inputReader io.Reader, output io.Writer, tempDir st
ring) error { |
| 78 binarypath := path.Join(tempDir, "fiddle") | 81 binarypath := path.Join(tempDir, "fiddle") |
| 79 » fiddle_dir := path.Join(skiaSrc, "experimental", "fiddle") | 82 » fiddle_dir := path.Join(skiaSrc, fiddlePath()) |
| 80 if err := execCommand(inputReader, fiddle_dir, | 83 if err := execCommand(inputReader, fiddle_dir, |
| 81 "c++", | 84 "c++", |
| 82 compileArgs(skiaSrc), | 85 compileArgs(skiaSrc), |
| 83 "-I", fiddle_dir, | 86 "-I", fiddle_dir, |
| 84 "-o", binarypath, | 87 "-o", binarypath, |
| 85 "-x", "c++", "-", "-x", "none", | 88 "-x", "c++", "-", "-x", "none", |
| 86 "fiddle_main.o", | 89 "fiddle_main.o", |
| 87 "-lOSMesa", | 90 "-lOSMesa", |
| 88 linkArgs(skiaSrc), | 91 linkArgs(skiaSrc), |
| 89 ); err != nil { | 92 ); err != nil { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 // Compile Skia library and fiddle_main.cpp | 103 // Compile Skia library and fiddle_main.cpp |
| 101 // @param skiaSrc: the base directory of the Skia repository. | 104 // @param skiaSrc: the base directory of the Skia repository. |
| 102 func fiddlerPrerequisites(skiaSrc string) error { | 105 func fiddlerPrerequisites(skiaSrc string) error { |
| 103 cmakeDir := path.Join(skiaSrc, "cmake") | 106 cmakeDir := path.Join(skiaSrc, "cmake") |
| 104 if err := execCommand(nil, cmakeDir, "cmake", "-G", "Ninja", "."); err !
= nil { | 107 if err := execCommand(nil, cmakeDir, "cmake", "-G", "Ninja", "."); err !
= nil { |
| 105 return err | 108 return err |
| 106 } | 109 } |
| 107 if err := execCommand(nil, cmakeDir, "ninja", "skia"); err != nil { | 110 if err := execCommand(nil, cmakeDir, "ninja", "skia"); err != nil { |
| 108 return err | 111 return err |
| 109 } | 112 } |
| 110 » fiddle_dir := path.Join(skiaSrc, "experimental", "fiddle") | 113 » fiddle_dir := path.Join(skiaSrc, fiddlePath()) |
| 111 if err := execCommand(nil, fiddle_dir, "c++", compileArgs(skiaSrc), | 114 if err := execCommand(nil, fiddle_dir, "c++", compileArgs(skiaSrc), |
| 112 "fiddle_main.h"); err != nil { | 115 "fiddle_main.h"); err != nil { |
| 113 return err | 116 return err |
| 114 } | 117 } |
| 115 return execCommand(nil, fiddle_dir, "c++", compileArgs(skiaSrc), | 118 return execCommand(nil, fiddle_dir, "c++", compileArgs(skiaSrc), |
| 116 "-c", "-o", "fiddle_main.o", "fiddle_main.cpp") | 119 "-c", "-o", "fiddle_main.o", "fiddle_main.cpp") |
| 117 } | 120 } |
| 118 | 121 |
| 119 func main() { | 122 func main() { |
| 120 if len(os.Args) < 2 { | 123 if len(os.Args) < 2 { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 150 if err != nil { | 153 if err != nil { |
| 151 glog.Fatalf("unable to open \"%s\": %v", os.Args
[2], err) | 154 glog.Fatalf("unable to open \"%s\": %v", os.Args
[2], err) |
| 152 } | 155 } |
| 153 defer util.Close(inputFile) | 156 defer util.Close(inputFile) |
| 154 if err = fiddler(skiaSrc, inputFile, os.Stdout, tempDir)
; err != nil { | 157 if err = fiddler(skiaSrc, inputFile, os.Stdout, tempDir)
; err != nil { |
| 155 glog.Fatal(err) | 158 glog.Fatal(err) |
| 156 } | 159 } |
| 157 } | 160 } |
| 158 } | 161 } |
| 159 } | 162 } |
| OLD | NEW |