Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package main | |
| 6 | |
| 7 import ( | |
| 8 "encoding/json" | |
| 9 "errors" | |
| 10 "fmt" | |
| 11 "io/ioutil" | |
| 12 "log" | |
| 13 "os" | |
| 14 "path/filepath" | |
| 15 | |
| 16 "github.com/luci/luci-go/client/isolate" | |
| 17 "github.com/luci/luci-go/common/isolated" | |
| 18 "github.com/maruel/subcommands" | |
| 19 ) | |
| 20 | |
| 21 var cmdExpArchive = &subcommands.Command{ | |
| 22 UsageLine: "exparchive <options>", | |
| 23 ShortDesc: "EXPERIMENTAL creates a .isolated file and uploads the tree t o an isolate server.", | |
|
mcgreevy
2016/11/22 05:12:12
"the tree" can you be more explicit? what tree?
djd-OOO-Apr2017
2016/11/22 06:12:20
Tried to add a lot more explanatory text, PTAL.
| |
| 24 LongDesc: "All the files listed in the .isolated file are put in the is olate server cache. Small files are combined together in a tar archive before up loading.", | |
| 25 CommandRun: func() subcommands.CommandRun { | |
| 26 c := expArchiveRun{} | |
| 27 c.commonServerFlags.Init() | |
| 28 c.isolateFlags.Init(&c.Flags) | |
| 29 return &c | |
| 30 }, | |
| 31 } | |
| 32 | |
| 33 type expArchiveRun struct { | |
|
mcgreevy
2016/11/22 05:12:12
Can you please document this?
djd-OOO-Apr2017
2016/11/22 06:12:20
Done.
| |
| 34 commonServerFlags | |
|
mcgreevy
2016/11/22 05:12:12
Is there any reason for these to be anonymous fiel
djd-OOO-Apr2017
2016/11/22 06:12:20
commonServerFlags needed to satisfy the subcommand
| |
| 35 isolateFlags | |
| 36 } | |
| 37 | |
| 38 func (c *expArchiveRun) Parse(a subcommands.Application, args []string) error { | |
| 39 if err := c.commonServerFlags.Parse(); err != nil { | |
| 40 return err | |
| 41 } | |
| 42 cwd, err := os.Getwd() | |
| 43 if err != nil { | |
| 44 return err | |
| 45 } | |
| 46 if err := c.isolateFlags.Parse(cwd, RequireIsolatedFile); err != nil { | |
|
mcgreevy
2016/11/22 05:12:12
Don't you need "RequireIsolateFile&RequireIsolated
djd-OOO-Apr2017
2016/11/22 06:12:20
Good call, fixed.
| |
| 47 return err | |
| 48 } | |
| 49 if len(args) != 0 { | |
| 50 return errors.New("position arguments not expected") | |
| 51 } | |
| 52 return nil | |
| 53 } | |
| 54 | |
| 55 func (c *expArchiveRun) main(a subcommands.Application, args []string) error { | |
| 56 // Parse the incoming isolate file. | |
| 57 deps, rootDir, isol, err := isolate.ProcessIsolate(&c.ArchiveOptions) | |
| 58 if err != nil { | |
| 59 return fmt.Errorf("failed to process isolate: %v", err) | |
| 60 } | |
| 61 log.Printf("Isolate referenced %d deps", len(deps)) | |
| 62 | |
| 63 // TODO(djd): actually do something with the isolated. | |
| 64 _ = rootDir | |
| 65 | |
| 66 // Marshal the isolated file into JSON. | |
| 67 isolJSON, err := json.Marshal(isol) | |
| 68 if err != nil { | |
| 69 return err | |
| 70 } | |
| 71 // TODO(djd): actually check/upload the isolated. | |
| 72 | |
| 73 // Write the isolated file, and emit its digest to stdout. | |
| 74 if err := ioutil.WriteFile(c.ArchiveOptions.Isolated, isolJSON, 0644); e rr != nil { | |
| 75 return err | |
| 76 } | |
| 77 fmt.Printf("%s\t%s\n", isolated.HashBytes(isolJSON), filepath.Base(c.Arc hiveOptions.Isolated)) | |
| 78 | |
| 79 return errors.New("experimental archive is not implemented") | |
| 80 } | |
| 81 | |
| 82 func (c *expArchiveRun) Run(a subcommands.Application, args []string) int { | |
| 83 fmt.Fprintln(a.GetErr(), "WARNING: this command is experimental") | |
| 84 if err := c.Parse(a, args); err != nil { | |
| 85 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | |
| 86 return 1 | |
| 87 } | |
| 88 if len(c.ArchiveOptions.Blacklist) != 0 { | |
| 89 fmt.Fprintf(a.GetErr(), "%s: blacklist is not supported\n", a.Ge tName()) | |
| 90 return 1 | |
| 91 } | |
| 92 if err := c.main(a, args); err != nil { | |
| 93 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | |
| 94 return 1 | |
| 95 } | |
| 96 return 0 | |
| 97 } | |
| OLD | NEW |