aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-06-27 14:56:46 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-06-27 14:56:46 +0200
commit919e77001d3bf564557d8b9c553285ac32d02ca7 (patch)
treeea47c4902cc8cae2d7c3a5c11ae8a0ca93738b76 /pkg
parent58e8587f648cb149e15553e4a43749df340adc8b (diff)
pkg/vcs: add fuchsia support
For now only checking out and polling.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/vcs/fuchsia.go94
-rw-r--r--pkg/vcs/git.go16
-rw-r--r--pkg/vcs/vcs.go11
3 files changed, 107 insertions, 14 deletions
diff --git a/pkg/vcs/fuchsia.go b/pkg/vcs/fuchsia.go
new file mode 100644
index 000000000..b8462f5ad
--- /dev/null
+++ b/pkg/vcs/fuchsia.go
@@ -0,0 +1,94 @@
+// 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 vcs
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "path/filepath"
+
+ "github.com/google/syzkaller/pkg/osutil"
+)
+
+type fuchsia struct {
+ vm string
+ dir string
+ zircon *git
+}
+
+func newFuchsia(vm, dir string) *fuchsia {
+ return &fuchsia{
+ vm: vm,
+ dir: dir,
+ zircon: newGit("fuchsia", vm, filepath.Join(dir, "zircon")),
+ }
+}
+
+// mkdir DIR; cd DIR
+// curl -s "https://fuchsia.googlesource.com/scripts/+/master/bootstrap?format=TEXT" | base64 --decode | bash -s topaz
+// (cd fuchsia && .jiri_root/bin/jiri update)
+// (cd fuchsia/zircon/ && git show HEAD)
+
+func (fu *fuchsia) Poll(repo, branch string) (*Commit, error) {
+ if repo != "https://fuchsia.googlesource.com" || branch != "master" {
+ // fuchsia ecosystem is hard-tailored to the main repo.
+ return nil, fmt.Errorf("fuchsia: can only check out https://fuchsia.googlesource.com/master")
+ }
+ if _, err := runSandboxed(fu.dir, "./.jiri_root/bin/jiri", "update"); err != nil {
+ if err := fu.initRepo(); err != nil {
+ return nil, err
+ }
+ }
+ return fu.zircon.HeadCommit()
+}
+
+func (fu *fuchsia) initRepo() error {
+ if err := os.RemoveAll(fu.dir); err != nil {
+ return fmt.Errorf("failed to remove repo dir: %v", err)
+ }
+ tmpDir := fu.dir + ".tmp"
+ if err := osutil.MkdirAll(tmpDir); err != nil {
+ return fmt.Errorf("failed to create repo dir: %v", err)
+ }
+ defer os.RemoveAll(tmpDir)
+ cmd := "curl -s 'https://fuchsia.googlesource.com/scripts/+/master/bootstrap?format=TEXT' |" +
+ "base64 --decode | bash -s topaz"
+ if _, err := runSandboxed(tmpDir, "bash", "-c", cmd); err != nil {
+ return err
+ }
+ return os.Rename(filepath.Join(tmpDir, "fuchsia"), fu.dir)
+}
+
+func (fu *fuchsia) CheckoutBranch(repo, branch string) (*Commit, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
+
+func (fu *fuchsia) CheckoutCommit(repo, commit string) (*Commit, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
+
+func (fu *fuchsia) SwitchCommit(commit string) (*Commit, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
+
+func (fu *fuchsia) HeadCommit() (*Commit, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
+
+func (fu *fuchsia) ListRecentCommits(baseCommit string) ([]string, error) {
+ return nil, nil
+}
+
+func (fu *fuchsia) ExtractFixTagsFromCommits(baseCommit, email string) ([]FixCommit, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
+
+func (fu *fuchsia) Bisect(bad, good string, trace io.Writer, pred func() (BisectResult, error)) (*Commit, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
+
+func (fu *fuchsia) PreviousReleaseTags(commit string) ([]string, error) {
+ return nil, fmt.Errorf("not implemented for fuchsia")
+}
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go
index d1595aaa8..f064dadb1 100644
--- a/pkg/vcs/git.go
+++ b/pkg/vcs/git.go
@@ -1,7 +1,6 @@
// 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.
-// Package vcs provides helper functions for working with git repositories.
package vcs
import (
@@ -137,10 +136,10 @@ func (git *git) initRepo() error {
}
func (git *git) HeadCommit() (*Commit, error) {
- return git.GetCommit("HEAD")
+ return git.getCommit("HEAD")
}
-func (git *git) GetCommit(commit string) (*Commit, error) {
+func (git *git) getCommit(commit string) (*Commit, error) {
output, err := runSandboxed(git.dir, "git", "log", "--format=%H%n%s%n%ae%n%ad%n%b", "-n", "1", commit)
if err != nil {
return nil, err
@@ -285,7 +284,7 @@ func (git *git) Bisect(bad, good string, trace io.Writer, pred func() (BisectRes
dir := git.dir
runSandboxed(dir, "git", "bisect", "reset")
runSandboxed(dir, "git", "reset", "--hard")
- firstBad, err := git.GetCommit(bad)
+ firstBad, err := git.getCommit(bad)
if err != nil {
return nil, err
}
@@ -369,12 +368,3 @@ func gitReleaseTagToInt(tag string) uint64 {
}
return v1*1e6 + v2*1e3 + v3
}
-
-func runSandboxed(dir, command string, args ...string) ([]byte, error) {
- cmd := osutil.Command(command, args...)
- cmd.Dir = dir
- if err := osutil.Sandbox(cmd, true, false); err != nil {
- return nil, err
- }
- return osutil.Run(timeout, cmd)
-}
diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go
index bef279bdc..85e0649cd 100644
--- a/pkg/vcs/vcs.go
+++ b/pkg/vcs/vcs.go
@@ -77,6 +77,8 @@ func NewRepo(os, vm, dir string) (Repo, error) {
switch os {
case "linux":
return newGit(os, vm, dir), nil
+ case "fuchsia":
+ return newFuchsia(vm, dir), nil
}
return nil, fmt.Errorf("vcs is unsupported for %v", os)
}
@@ -138,7 +140,14 @@ func CheckCommitHash(hash string) bool {
return ln == 8 || ln == 10 || ln == 12 || ln == 16 || ln == 20 || ln == 40
}
-const timeout = time.Hour // timeout for all git invocations
+func runSandboxed(dir, command string, args ...string) ([]byte, error) {
+ cmd := osutil.Command(command, args...)
+ cmd.Dir = dir
+ if err := osutil.Sandbox(cmd, true, false); err != nil {
+ return nil, err
+ }
+ return osutil.Run(time.Hour, cmd)
+}
var (
// nolint: lll