aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorDokyung Song <dokyungs@google.com>2018-09-05 12:45:17 -0700
committerDmitry Vyukov <dvyukov@google.com>2018-09-06 21:18:15 +0200
commite30d3b524053cf8d688a1f486a5cde9b67d49e87 (patch)
tree8743bf3e125c306042793f7f7f23822e747715c0 /sys
parent0bb7a7eb8e0958c6fbe2d69615b9fae4af88c8ee (diff)
sys/fuchsia: add Go script that generates fidl descriptions
Diffstat (limited to 'sys')
-rw-r--r--sys/fuchsia/fidlgen/main.go78
-rw-r--r--sys/fuchsia/init.go2
2 files changed, 80 insertions, 0 deletions
diff --git a/sys/fuchsia/fidlgen/main.go b/sys/fuchsia/fidlgen/main.go
new file mode 100644
index 000000000..38189bae8
--- /dev/null
+++ b/sys/fuchsia/fidlgen/main.go
@@ -0,0 +1,78 @@
+// Copyright 2018 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "time"
+
+ "github.com/google/syzkaller/pkg/osutil"
+ "github.com/google/syzkaller/sys/targets"
+)
+
+var zirconLibs = []string{
+ "fuchsia-process",
+ "fuchsia-io",
+}
+
+func main() {
+ targetArch := os.Getenv("TARGETARCH")
+ target := targets.Get("fuchsia", targetArch)
+ if target == nil {
+ failf("unknown TARGETARCH %s", targetArch)
+ }
+ arch := target.KernelHeaderArch
+
+ sourceDir := os.Getenv("SOURCEDIR")
+ if !osutil.IsExist(sourceDir) {
+ failf("cannot find SOURCEDIR %s", sourceDir)
+ }
+
+ fidlgenPath := filepath.Join(
+ sourceDir,
+ "out",
+ arch,
+ fmt.Sprintf("host_%s", arch),
+ "fidlgen",
+ )
+ if !osutil.IsExist(fidlgenPath) {
+ failf("cannot find fidlgen %s", fidlgenPath)
+ }
+
+ for _, lib := range zirconLibs {
+ jsonPath := filepath.Join(
+ sourceDir,
+ "out",
+ arch,
+ "fidling/gen/zircon/public/fidl",
+ lib,
+ fmt.Sprintf("%s.fidl.json", lib),
+ )
+
+ if !osutil.IsExist(jsonPath) {
+ failf("cannot find %s", jsonPath)
+ }
+
+ txtPath := strings.Replace(lib, "fuchsia-", "fidl_", 1)
+ _, err := osutil.RunCmd(time.Minute, "",
+ fidlgenPath,
+ "-generators", "syzkaller",
+ "-json", jsonPath,
+ "-output-base", txtPath,
+ "-include-base", txtPath,
+ )
+
+ if err != nil {
+ failf("fidlgen failed: %v\n", err)
+ }
+ }
+}
+
+func failf(msg string, args ...interface{}) {
+ fmt.Fprintf(os.Stderr, msg+"\n", args...)
+ os.Exit(1)
+}
diff --git a/sys/fuchsia/init.go b/sys/fuchsia/init.go
index eefba3950..30cb3d7d1 100644
--- a/sys/fuchsia/init.go
+++ b/sys/fuchsia/init.go
@@ -1,6 +1,8 @@
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+//go:generate go run fidlgen/main.go
+
package fuchsia
import (