github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/vcs/fuchsia.go (about) 1 // Copyright 2018 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package vcs 5 6 import ( 7 "fmt" 8 "os" 9 "path/filepath" 10 11 "github.com/google/syzkaller/pkg/osutil" 12 ) 13 14 type fuchsia struct { 15 dir string 16 repo *git 17 } 18 19 func newFuchsia(dir string, opts []RepoOpt) *fuchsia { 20 return &fuchsia{ 21 dir: dir, 22 repo: newGit(dir, nil, opts), 23 } 24 } 25 26 func (ctx *fuchsia) Poll(repo, branch string) (*Commit, error) { 27 if repo != "https://fuchsia.googlesource.com" || branch != "master" { 28 // Fuchsia ecosystem is hard-wired to the main repo. 29 return nil, fmt.Errorf("fuchsia: can only check out https://fuchsia.googlesource.com/master") 30 } 31 if _, err := runSandboxed(ctx.dir, "./.jiri_root/bin/jiri", "update"); err != nil { 32 if err := ctx.initRepo(); err != nil { 33 return nil, err 34 } 35 } 36 return ctx.repo.HeadCommit() 37 } 38 39 func (ctx *fuchsia) initRepo() error { 40 if err := os.RemoveAll(ctx.dir); err != nil { 41 return fmt.Errorf("failed to remove repo dir: %w", err) 42 } 43 tmpDir := ctx.dir + ".tmp" 44 if err := osutil.MkdirAll(tmpDir); err != nil { 45 return fmt.Errorf("failed to create repo dir: %w", err) 46 } 47 defer os.RemoveAll(tmpDir) 48 if err := osutil.SandboxChown(tmpDir); err != nil { 49 return err 50 } 51 cmd := "curl -s 'https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT' |" + 52 "base64 --decode | bash" 53 if _, err := runSandboxed(tmpDir, "bash", "-c", cmd); err != nil { 54 return err 55 } 56 return osutil.Rename(filepath.Join(tmpDir, "fuchsia"), ctx.dir) 57 } 58 59 func (ctx *fuchsia) CheckoutBranch(repo, branch string) (*Commit, error) { 60 return nil, fmt.Errorf("not implemented for fuchsia") 61 } 62 63 func (ctx *fuchsia) CheckoutCommit(repo, commit string) (*Commit, error) { 64 return nil, fmt.Errorf("not implemented for fuchsia") 65 } 66 67 func (ctx *fuchsia) SwitchCommit(commit string) (*Commit, error) { 68 return nil, fmt.Errorf("not implemented for fuchsia") 69 } 70 71 func (ctx *fuchsia) HeadCommit() (*Commit, error) { 72 return nil, fmt.Errorf("not implemented for fuchsia") 73 } 74 75 func (ctx *fuchsia) GetCommitByTitle(title string) (*Commit, error) { 76 return ctx.repo.GetCommitByTitle(title) 77 } 78 79 func (ctx *fuchsia) GetCommitsByTitles(titles []string) ([]*Commit, []string, error) { 80 return ctx.repo.GetCommitsByTitles(titles) 81 } 82 83 func (ctx *fuchsia) ExtractFixTagsFromCommits(baseCommit, email string) ([]*Commit, error) { 84 return ctx.repo.ExtractFixTagsFromCommits(baseCommit, email) 85 } 86 87 func (ctx *fuchsia) ReleaseTag(commit string) (string, error) { 88 return "", fmt.Errorf("not implemented for fuchsia") 89 } 90 91 func (ctx *fuchsia) Contains(commit string) (bool, error) { 92 return false, fmt.Errorf("not implemented for fuchsia") 93 } 94 95 func (ctx *fuchsia) ListCommitHashes(base string) ([]string, error) { 96 return ctx.repo.ListCommitHashes(base) 97 } 98 99 func (ctx *fuchsia) Object(name, commit string) ([]byte, error) { 100 return ctx.repo.Object(name, commit) 101 } 102 103 func (ctx *fuchsia) MergeBases(firstCommit, secondCommit string) ([]*Commit, error) { 104 return ctx.repo.MergeBases(firstCommit, secondCommit) 105 }