Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package application | 5 package application |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strings" | 8 "strings" |
| 9 | 9 |
| 10 "github.com/maruel/subcommands" | 10 "github.com/maruel/subcommands" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 func (cr *verifyCommandRun) Run(app subcommands.Application, args []string, env subcommands.Env) int { | 36 func (cr *verifyCommandRun) Run(app subcommands.Application, args []string, env subcommands.Env) int { |
| 37 c := cli.GetContext(app, cr, env) | 37 c := cli.GetContext(app, cr, env) |
| 38 a := getApplication(c, args) | 38 a := getApplication(c, args) |
| 39 | 39 |
| 40 return run(c, func(c context.Context) error { | 40 return run(c, func(c context.Context) error { |
| 41 // Make sure that we can resolve the referenced specifiction. | 41 // Make sure that we can resolve the referenced specifiction. |
| 42 if err := a.opts.ResolveSpec(c); err != nil { | 42 if err := a.opts.ResolveSpec(c); err != nil { |
| 43 return errors.Annotate(err).Reason("failed to resolve sp ecification").Err() | 43 return errors.Annotate(err).Reason("failed to resolve sp ecification").Err() |
| 44 } | 44 } |
| 45 » » if a.opts.EnvConfig.Spec.Virtualenv == nil { | 45 |
| 46 » » » a.opts.EnvConfig.Spec.Virtualenv = &a.opts.EnvConfig.Pac kage | 46 » » s := a.opts.EnvConfig.Spec |
| 47 » » if s == nil { | |
| 48 » » » s = &vpython.Spec{} | |
| 47 } | 49 } |
| 48 » » if err := spec.NormalizeSpec(a.opts.EnvConfig.Spec); err != nil { | 50 » » if s.Virtualenv == nil { |
| 51 » » » s.Virtualenv = &a.opts.EnvConfig.Package | |
| 52 » » } | |
| 53 | |
| 54 » » // Verify that the spec can be normalized. This may modify it, s o we will | |
| 55 » » // normalizse a clone. | |
|
qyearsley
2017/06/05 20:20:08
Nit: spelling
dnj
2017/06/06 13:59:10
Done.
| |
| 56 » » if err := spec.NormalizeSpec(s.Clone(), nil); err != nil { | |
| 49 return errors.Annotate(err).Reason("failed to normalize specification").Err() | 57 return errors.Annotate(err).Reason("failed to normalize specification").Err() |
| 50 } | 58 } |
| 51 » » s := a.opts.EnvConfig.Spec | 59 |
| 52 renderedSpec := spec.Render(s) | 60 renderedSpec := spec.Render(s) |
| 53 logging.Infof(c, "Successfully verified specification:\n%s", ren deredSpec) | 61 logging.Infof(c, "Successfully verified specification:\n%s", ren deredSpec) |
| 54 | 62 |
| 55 // Run our Verification generator and verify each generated envi ronment. | 63 // Run our Verification generator and verify each generated envi ronment. |
| 56 if a.WithVerificationConfig != nil { | 64 if a.WithVerificationConfig != nil { |
| 57 err := a.WithVerificationConfig(c, func(cfg Config, veri ficationScenarios []*vpython.Pep425Tag) error { | 65 err := a.WithVerificationConfig(c, func(cfg Config, veri ficationScenarios []*vpython.Pep425Tag) error { |
| 58 if len(s.VerifyPep425Tag) > 0 { | 66 if len(s.VerifyPep425Tag) > 0 { |
| 59 verificationScenarios = s.VerifyPep425Ta g | 67 verificationScenarios = s.VerifyPep425Ta g |
| 60 } | 68 } |
| 61 if len(verificationScenarios) == 0 { | 69 if len(verificationScenarios) == 0 { |
| 62 return nil | 70 return nil |
| 63 } | 71 } |
| 64 | 72 |
| 65 var failures []string | 73 var failures []string |
| 66 for _, vs := range verificationScenarios { | 74 for _, vs := range verificationScenarios { |
| 67 // Create a verification environment to pass to our package loader. | 75 // Create a verification environment to pass to our package loader. |
| 68 e := vpython.Environment{ | 76 e := vpython.Environment{ |
| 69 Spec: s.Clone(), | 77 Spec: s.Clone(), |
| 70 Pep425Tag: []*vpython.Pep425Tag{ vs}, | 78 Pep425Tag: []*vpython.Pep425Tag{ vs}, |
| 71 } | 79 } |
| 80 if err := spec.NormalizeEnvironment(&e); err != nil { | |
| 81 logging.Errorf(c, "Failed to nor malize environment against %q: %s", vs.TagString(), err) | |
| 82 failures = append(failures, vs.T agString()) | |
| 83 continue | |
| 84 } | |
| 72 | 85 |
| 73 if err := cfg.PackageLoader.Resolve(c, & e); err != nil { | 86 if err := cfg.PackageLoader.Resolve(c, & e); err != nil { |
| 74 logging.Errorf(c, "Failed to res olve against %q: %s", vs.TagString(), err) | 87 logging.Errorf(c, "Failed to res olve against %q: %s", vs.TagString(), err) |
| 75 failures = append(failures, vs.T agString()) | 88 failures = append(failures, vs.T agString()) |
| 76 } | 89 } |
| 77 } | 90 } |
| 78 | 91 |
| 79 if len(failures) > 0 { | 92 if len(failures) > 0 { |
| 80 logging.Errorf(c, "Verification failed f or %d scenario(s): %s\n%s", | 93 logging.Errorf(c, "Verification failed f or %d scenario(s): %s\n%s", |
| 81 len(failures), strings.Join(fail ures, ", "), renderedSpec) | 94 len(failures), strings.Join(fail ures, ", "), renderedSpec) |
| 82 return errors.New("verification failed") | 95 return errors.New("verification failed") |
| 83 } | 96 } |
| 84 | 97 |
| 85 logging.Infof(c, "Verified %d scenario(s).", len (verificationScenarios)) | 98 logging.Infof(c, "Verified %d scenario(s).", len (verificationScenarios)) |
| 86 return nil | 99 return nil |
| 87 }) | 100 }) |
| 88 if err != nil { | 101 if err != nil { |
| 89 return err | 102 return err |
| 90 } | 103 } |
| 91 } | 104 } |
| 92 | 105 |
| 93 return nil | 106 return nil |
| 94 }) | 107 }) |
| 95 } | 108 } |
| OLD | NEW |