Best Syzkaller code snippet using vcs.ReleaseTag
kconf.go
Source:kconf.go
...85 ctx := &Context{86 Inst: inst1,87 ConfigDir: filepath.Dir(*flagConfig),88 SourceDir: *flagSourceDir,89 ReleaseTag: releaseTag,90 }91 go func() {92 if err := ctx.generate(); err != nil {93 results <- fmt.Errorf("%v failed:\n%v", ctx.Inst.Name, err)94 }95 results <- nil96 }()97 }98 for i := 0; i < batch; i++ {99 if err := <-results; err != nil {100 fmt.Printf("%v\n", err)101 failed = true102 }103 }104 }105 if failed {106 tool.Failf("some configs failed")107 }108 if len(generated) == 0 {109 tool.Failf("unknown instance name")110 }111}112func checkConfigs(instances []*Instance, unusedFeatures []string) error {113 allFeatures := make(Features)114 for _, feat := range unusedFeatures {115 allFeatures[feat] = true116 }117 for _, inst := range instances {118 for feat := range inst.Features {119 allFeatures[feat] = true120 }121 }122 dedup := make(map[string]bool)123 errorString := ""124 for _, inst := range instances {125 for _, cfg := range inst.Configs {126 for _, feat := range cfg.Constraints {127 if feat[0] == '-' {128 feat = feat[1:]129 }130 if allFeatures[feat] || releaseRe.MatchString(feat) {131 continue132 }133 msg := fmt.Sprintf("%v:%v: unknown feature %v", cfg.File, cfg.Line, feat)134 if dedup[msg] {135 continue136 }137 dedup[msg] = true138 errorString += "\n" + msg139 }140 }141 }142 if errorString != "" {143 return errors.New(errorString[1:])144 }145 return nil146}147// Generation context for a single instance.148type Context struct {149 Inst *Instance150 Target *targets.Target151 Kconf *kconfig.KConfig152 ConfigDir string153 BuildDir string154 SourceDir string155 ReleaseTag string156}157func (ctx *Context) generate() error {158 var err error159 if ctx.BuildDir, err = ioutil.TempDir("", "syz-kconf"); err != nil {160 return err161 }162 defer os.RemoveAll(ctx.BuildDir)163 if err := ctx.setTarget(); err != nil {164 return err165 }166 if ctx.Kconf, err = kconfig.Parse(ctx.Target, filepath.Join(ctx.SourceDir, "Kconfig")); err != nil {167 return err168 }169 if err := ctx.setReleaseFeatures(); err != nil {170 return err171 }172 if err := ctx.mrProper(); err != nil {173 return err174 }175 if err := ctx.executeShell(); err != nil {176 return err177 }178 configFile := filepath.Join(ctx.BuildDir, ".config")179 cf, err := kconfig.ParseConfig(configFile)180 if err != nil {181 return err182 }183 if !ctx.Inst.Features[featBaseline] {184 if err := ctx.addUSBConfigs(cf); err != nil {185 return err186 }187 }188 ctx.applyConfigs(cf)189 cf.ModToYes()190 // Set all configs that are not present (actually not present, rather than "is not set") to "is not set".191 // This avoids olddefconfig turning on random things we did not ask for.192 for _, cfg := range ctx.Kconf.Configs {193 if (cfg.Type == kconfig.TypeTristate || cfg.Type == kconfig.TypeBool) && cf.Map[cfg.Name] == nil {194 cf.Set(cfg.Name, kconfig.No)195 }196 }197 original := cf.Serialize()198 if err := osutil.WriteFile(configFile, original); err != nil {199 return fmt.Errorf("failed to write .config file: %v", err)200 }201 // Save what we've got before olddefconfig for debugging purposes, it allows to see if we did not set a config,202 // or olddefconfig removed it. Save as .tmp so that it's not checked-in accidentially.203 outputFile := filepath.Join(ctx.ConfigDir, ctx.Inst.Name+".config")204 outputFileTmp := outputFile + ".tmp"205 if err := osutil.WriteFile(outputFileTmp, original); err != nil {206 return fmt.Errorf("failed to write tmp config file: %v", err)207 }208 if err := ctx.Make("olddefconfig"); err != nil {209 return err210 }211 cf, err = kconfig.ParseConfig(configFile)212 if err != nil {213 return err214 }215 if err := ctx.verifyConfigs(cf); err != nil {216 return fmt.Errorf("%vsaved config before olddefconfig to %v", err, outputFileTmp)217 }218 cf.ModToNo()219 config := []byte(fmt.Sprintf(`# Automatically generated by syz-kconf; DO NOT EDIT.220# Kernel: %v %v221%s222%s223`,224 ctx.Inst.Kernel.Repo, ctx.Inst.Kernel.Tag, cf.Serialize(), ctx.Inst.Verbatim))225 return osutil.WriteFile(outputFile, config)226}227func (ctx *Context) executeShell() error {228 for _, shell := range ctx.Inst.Shell {229 if !ctx.Inst.Features.Match(shell.Constraints) {230 continue231 }232 args := strings.Split(shell.Cmd, " ")233 for i := 1; i < len(args); i++ {234 args[i] = ctx.replaceVars(args[i])235 }236 if args[0] == "make" {237 if err := ctx.Make(args[1:]...); err != nil {238 return err239 }240 continue241 }242 if _, err := osutil.RunCmd(10*time.Minute, ctx.SourceDir, args[0], args[1:]...); err != nil {243 return err244 }245 }246 return nil247}248func (ctx *Context) applyConfigs(cf *kconfig.ConfigFile) {249 for _, cfg := range ctx.Inst.Configs {250 if !ctx.Inst.Features.Match(cfg.Constraints) {251 continue252 }253 if cfg.Value != kconfig.No {254 // If this is a choice, first unset all other options.255 // If we leave 2 choice options enabled, the last one will win.256 // It can make sense to move this code to kconfig in some form,257 // it's needed everywhere configs are changed.258 if m := ctx.Kconf.Configs[cfg.Name]; m != nil && m.Parent.Kind == kconfig.MenuChoice {259 for _, choice := range m.Parent.Elems {260 cf.Unset(choice.Name)261 }262 }263 }264 cf.Set(cfg.Name, cfg.Value)265 }266}267func (ctx *Context) verifyConfigs(cf *kconfig.ConfigFile) error {268 errs := new(Errors)269 for _, cfg := range ctx.Inst.Configs {270 act := cf.Value(cfg.Name)271 if act == cfg.Value || cfg.Optional || !ctx.Inst.Features.Match(cfg.Constraints) {272 continue273 }274 if act == kconfig.No {275 errs.push("%v:%v: %v is not present in the final config", cfg.File, cfg.Line, cfg.Name)276 } else if cfg.Value == kconfig.No {277 errs.push("%v:%v: %v is present in the final config", cfg.File, cfg.Line, cfg.Name)278 } else {279 errs.push("%v:%v: %v does not match final config %v vs %v",280 cfg.File, cfg.Line, cfg.Name, cfg.Value, act)281 }282 }283 return errs.err()284}285func (ctx *Context) addUSBConfigs(cf *kconfig.ConfigFile) error {286 prefix := ""287 switch {288 case ctx.Inst.Features[featAndroid]:289 prefix = "android"290 case ctx.Inst.Features[featChromeos]:291 prefix = "chromeos"292 }293 distroConfig := filepath.Join(ctx.ConfigDir, "distros", prefix+"*")294 // Some USB drivers don't depend on any USB related symbols, but rather on a generic symbol295 // for some input subsystem (e.g. HID), so include it as well.296 return ctx.addDependentConfigs(cf, []string{"USB_SUPPORT", "HID"}, distroConfig)297}298func (ctx *Context) addDependentConfigs(dst *kconfig.ConfigFile, include []string, configGlob string) error {299 configFiles, err := filepath.Glob(configGlob)300 if err != nil {301 return err302 }303 includes := func(a []string, b map[string]bool) bool {304 for _, x := range a {305 if b[x] {306 return true307 }308 }309 return false310 }311 selected := make(map[string]bool)312 for _, cfg := range ctx.Kconf.Configs {313 deps := cfg.DependsOn()314 if !includes(include, deps) {315 continue316 }317 selected[cfg.Name] = true318 for dep := range deps {319 selected[dep] = true320 }321 }322 dedup := make(map[string]bool)323 for _, file := range configFiles {324 cf, err := kconfig.ParseConfig(file)325 if err != nil {326 return err327 }328 for _, cfg := range cf.Configs {329 if cfg.Value == kconfig.No || dedup[cfg.Name] || !selected[cfg.Name] {330 continue331 }332 dedup[cfg.Name] = true333 dst.Set(cfg.Name, cfg.Value)334 }335 }336 return nil337}338func (ctx *Context) setTarget() error {339 for _, target := range targets.List[targets.Linux] {340 if ctx.Inst.Features[target.KernelArch] {341 if ctx.Target != nil {342 return fmt.Errorf("arch is set twice")343 }344 ctx.Target = targets.GetEx(targets.Linux, target.Arch, ctx.Inst.Features[featClang])345 }346 }347 if ctx.Target == nil {348 return fmt.Errorf("no arch feature")349 }350 return nil351}352func (ctx *Context) setReleaseFeatures() error {353 tag := ctx.ReleaseTag354 match := releaseRe.FindStringSubmatch(tag)355 if match == nil {356 return fmt.Errorf("bad release tag %q", tag)357 }358 major, err := strconv.ParseInt(match[1], 10, 32)359 if err != nil {360 return fmt.Errorf("bad release tag %q: %v", tag, err)361 }362 minor, err := strconv.ParseInt(match[2], 10, 32)363 if err != nil {364 return fmt.Errorf("bad release tag %q: %v", tag, err)365 }366 for ; major >= 2; major-- {367 for ; minor >= 0; minor-- {...
ReleaseTag
Using AI Code Generation
1import (2func main() {3 r, _ := git.PlainOpen("C:\\Users\\user\\Desktop\\go\\src\\github.com\\src-d\\go-git")4 ref, _ := r.Head()5 commit, _ := r.CommitObject(ref.Hash())6 fmt.Println(commit.Message)7 cIter, _ := r.Log(&git.LogOptions{From: plumbing.NewHash("f0a2e6c")})8 err := cIter.ForEach(func(c *object.Commit) error {9 fmt.Println(c)10 })11}12import (13func main() {14 r, _ := git.PlainOpen("C:\\Users\\user\\Desktop\\go\\src\\github.com\\src-d\\go-git")15 ref, _ := r.Head()16 commit, _ := r.CommitObject(ref.Hash())17 fmt.Println(commit.Message)18 cIter, _ := r.Log(&git.LogOptions{From: plumbing.NewHash("f0a2e6c")})19 err := cIter.ForEach(func(c *object.Commit) error {20 fmt.Println(c)21 })22}23import (24func main() {25 r, _ := git.PlainOpen("C:\\Users\\user\\Desktop\\go\\src\\github.com\\src-d\\go-git")26 ref, _ := r.Head()27 commit, _ := r.CommitObject(ref.Hash())28 fmt.Println(commit.Message)29 cIter, _ := r.Log(&git.Log
ReleaseTag
Using AI Code Generation
1import (2func main() {3 repo, err := vcs.RepoRootForImportPath("golang.org/x/tools", false)4 if err != nil {5 fmt.Println("Error in getting repo root:", err)6 }7 tag := repo.ReleaseTag()8 fmt.Println("Release tag:", tag)9}
ReleaseTag
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("git", "tag")4 out, err := cmd.Output()5 if err != nil {6 log.Fatal(err)7 }8 fmt.Printf("The date is %s9}
ReleaseTag
Using AI Code Generation
1import (2func main() {3 vcsObj.ReleaseTag()4}5import (6func main() {7 vcsObj.ReleaseTag()8}
ReleaseTag
Using AI Code Generation
1import (2func main() {3 v, err := vcs.New("git", "/home/skaji/work/sandbox/test")4 if err != nil {5 panic(err)6 }7 tag, err := v.ReleaseTag("v1.0.0")8 if err != nil {9 panic(err)10 }11 fmt.Println(tag)12}13import (14func main() {15 v, err := vcs.New("git", "/home/skaji/work/sandbox/test")16 if err != nil {17 panic(err)18 }19 tag, err := v.LatestTag()20 if err != nil {21 panic(err)22 }23 fmt.Println(tag)24}25import (26func main() {27 v, err := vcs.New("git", "/home/skaji/work/sandbox/test")28 if err != nil {29 panic(err)30 }31 tag, err := v.LatestTag("v1")32 if err != nil {33 panic(err)34 }35 fmt.Println(tag)36}37import (38func main() {39 v, err := vcs.New("git", "/home/skaji/work/sandbox/test")40 if err != nil {41 panic(err)42 }43 commit, err := v.LatestCommit("
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!