huangcm
2025-02-24 69ed55dec4b2116a19e4cca4393cbc014fce5fb2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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")),
   }
}
 
func (ctx *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(ctx.dir, "./.jiri_root/bin/jiri", "update"); err != nil {
       if err := ctx.initRepo(); err != nil {
           return nil, err
       }
   }
   return ctx.zircon.HeadCommit()
}
 
func (ctx *fuchsia) initRepo() error {
   if err := os.RemoveAll(ctx.dir); err != nil {
       return fmt.Errorf("failed to remove repo dir: %v", err)
   }
   tmpDir := ctx.dir + ".tmp"
   if err := osutil.MkdirAll(tmpDir); err != nil {
       return fmt.Errorf("failed to create repo dir: %v", err)
   }
   defer os.RemoveAll(tmpDir)
   if err := osutil.SandboxChown(tmpDir); err != nil {
       return err
   }
   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"), ctx.dir)
}
 
func (ctx *fuchsia) CheckoutBranch(repo, branch string) (*Commit, error) {
   return nil, fmt.Errorf("not implemented for fuchsia")
}
 
func (ctx *fuchsia) CheckoutCommit(repo, commit string) (*Commit, error) {
   return nil, fmt.Errorf("not implemented for fuchsia")
}
 
func (ctx *fuchsia) SwitchCommit(commit string) (*Commit, error) {
   return nil, fmt.Errorf("not implemented for fuchsia")
}
 
func (ctx *fuchsia) HeadCommit() (*Commit, error) {
   return nil, fmt.Errorf("not implemented for fuchsia")
}
 
func (ctx *fuchsia) ListRecentCommits(baseCommit string) ([]string, error) {
   return ctx.zircon.ListRecentCommits(baseCommit)
}
 
func (ctx *fuchsia) ExtractFixTagsFromCommits(baseCommit, email string) ([]FixCommit, error) {
   return ctx.zircon.ExtractFixTagsFromCommits(baseCommit, email)
}
 
func (ctx *fuchsia) Bisect(bad, good string, trace io.Writer, pred func() (BisectResult, error)) (*Commit, error) {
   return nil, fmt.Errorf("not implemented for fuchsia")
}
 
func (ctx *fuchsia) PreviousReleaseTags(commit string) ([]string, error) {
   return nil, fmt.Errorf("not implemented for fuchsia")
}