2018-05-13 23:32:01 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-05-19 05:38:51 -04:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2018-05-14 00:31:48 -04:00
|
|
|
"github.com/golang/protobuf/proto"
|
2018-05-13 23:32:01 -04:00
|
|
|
"github.com/ry/v8worker2"
|
2018-05-22 11:42:56 -04:00
|
|
|
"log"
|
2018-05-14 00:31:48 -04:00
|
|
|
"os"
|
2018-05-22 11:42:56 -04:00
|
|
|
"runtime/pprof"
|
2018-05-13 23:32:01 -04:00
|
|
|
)
|
|
|
|
|
2018-05-19 05:38:51 -04:00
|
|
|
var flagReload = flag.Bool("reload", false, "Reload cached remote source code.")
|
|
|
|
var flagV8Options = flag.Bool("v8-options", false, "Print V8 command line options.")
|
|
|
|
var flagDebug = flag.Bool("debug", false, "Enable debug output.")
|
2018-05-22 11:42:56 -04:00
|
|
|
var flagGoProf = flag.String("goprof", "", "Write golang cpu profile to file.")
|
2018-05-19 05:38:51 -04:00
|
|
|
|
2018-05-19 04:47:40 -04:00
|
|
|
var DenoDir string
|
|
|
|
var CompileDir string
|
|
|
|
var SrcDir string
|
|
|
|
|
2018-05-21 17:33:33 -04:00
|
|
|
func stringAsset(path string) string {
|
|
|
|
data, err := Asset("dist/" + path)
|
|
|
|
check(err)
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:31:48 -04:00
|
|
|
func main() {
|
2018-05-19 05:38:51 -04:00
|
|
|
flag.Parse()
|
|
|
|
args := flag.Args()
|
|
|
|
if *flagV8Options {
|
|
|
|
args = append(args, "--help")
|
|
|
|
fmt.Println(args)
|
|
|
|
}
|
|
|
|
args = v8worker2.SetFlags(args)
|
|
|
|
|
2018-05-22 11:42:56 -04:00
|
|
|
// Maybe start Golang CPU profiler.
|
|
|
|
// Use --prof for profiling JS.
|
|
|
|
if *flagGoProf != "" {
|
|
|
|
f, err := os.Create(*flagGoProf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
pprof.StartCPUProfile(f)
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
}
|
|
|
|
|
2018-05-15 04:39:03 -04:00
|
|
|
createDirs()
|
2018-05-21 22:07:40 -04:00
|
|
|
createWorker()
|
2018-05-21 23:00:36 -04:00
|
|
|
|
|
|
|
InitOS()
|
|
|
|
InitTimers()
|
2018-05-21 17:33:33 -04:00
|
|
|
|
|
|
|
main_js := stringAsset("main.js")
|
|
|
|
check(worker.Load("/main.js", main_js))
|
|
|
|
main_map := stringAsset("main.map")
|
|
|
|
|
2018-05-14 13:02:47 -04:00
|
|
|
cwd, err := os.Getwd()
|
2018-05-15 04:39:03 -04:00
|
|
|
check(err)
|
|
|
|
|
2018-05-14 13:02:47 -04:00
|
|
|
out, err := proto.Marshal(&Msg{
|
2018-05-15 04:39:03 -04:00
|
|
|
Payload: &Msg_Start{
|
|
|
|
Start: &StartMsg{
|
2018-05-22 14:10:13 -04:00
|
|
|
Cwd: &cwd,
|
2018-05-19 05:38:51 -04:00
|
|
|
Argv: args,
|
2018-05-22 14:10:13 -04:00
|
|
|
DebugFlag: flagDebug,
|
|
|
|
MainJs: &main_js,
|
|
|
|
MainMap: &main_map,
|
2018-05-15 04:39:03 -04:00
|
|
|
},
|
|
|
|
},
|
2018-05-14 13:02:47 -04:00
|
|
|
})
|
2018-05-15 04:39:03 -04:00
|
|
|
check(err)
|
2018-05-21 22:07:40 -04:00
|
|
|
Pub("start", out)
|
2018-05-18 11:49:28 -04:00
|
|
|
|
2018-05-21 22:07:40 -04:00
|
|
|
DispatchLoop()
|
2018-05-13 23:32:01 -04:00
|
|
|
}
|