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 parses a .isolate file to creates a .isolated f ile, and uploads it and all referenced files to an isolate server", | |
|
mcgreevy
2016/11/22 23:43:35
s/to creates/to create/
djd-OOO-Apr2017
2016/11/23 00:12:11
Done.
| |
| 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 // expArchiveRun contains the logic for the experimental archive subcommand. | |
| 34 // It implements subcommand.CommandRun | |
| 35 type expArchiveRun struct { | |
| 36 commonServerFlags // Provides the GetFlags method. | |
| 37 isolateFlags isolateFlags | |
| 38 } | |
| 39 | |
| 40 // main contains the core logic for experimental archive. | |
| 41 func (c *expArchiveRun) main() error { | |
| 42 // Parse the incoming isolate file. | |
| 43 deps, rootDir, isol, err := isolate.ProcessIsolate(&c.isolateFlags.Archi veOptions) | |
|
mcgreevy
2016/11/22 23:43:35
before this, can you do:
archiveOpts := &c.isolat
djd-OOO-Apr2017
2016/11/23 00:12:11
I would like to be able to do that, but I don't th
| |
| 44 if err != nil { | |
| 45 return fmt.Errorf("failed to process isolate: %v", err) | |
| 46 } | |
| 47 log.Printf("Isolate referenced %d deps", len(deps)) | |
| 48 | |
| 49 // TODO(djd): actually do something with the isolated. | |
| 50 _ = rootDir | |
| 51 | |
| 52 // Marshal the isolated file into JSON. | |
| 53 isolJSON, err := json.Marshal(isol) | |
| 54 if err != nil { | |
| 55 return err | |
| 56 } | |
| 57 // TODO(djd): actually check/upload the isolated. | |
| 58 | |
| 59 // Write the isolated file, and emit its digest to stdout. | |
| 60 if err := ioutil.WriteFile(c.isolateFlags.ArchiveOptions.Isolated, isolJ SON, 0644); err != nil { | |
| 61 return err | |
| 62 } | |
| 63 fmt.Printf("%s\t%s\n", isolated.HashBytes(isolJSON), filepath.Base(c.iso lateFlags.ArchiveOptions.Isolated)) | |
| 64 | |
| 65 return errors.New("experimental archive is not implemented") | |
| 66 } | |
| 67 | |
| 68 func (c *expArchiveRun) parseFlags(a subcommands.Application, args []string) err or { | |
|
mcgreevy
2016/11/22 23:54:38
The "a" parameter does not seem to be used.
djd-OOO-Apr2017
2016/11/23 00:12:11
Done.
| |
| 69 if err := c.commonServerFlags.Parse(); err != nil { | |
| 70 return err | |
| 71 } | |
| 72 cwd, err := os.Getwd() | |
| 73 if err != nil { | |
| 74 return err | |
| 75 } | |
| 76 if err := c.isolateFlags.Parse(cwd, RequireIsolateFile&RequireIsolatedFi le); err != nil { | |
| 77 return err | |
| 78 } | |
| 79 if len(args) != 0 { | |
|
mcgreevy
2016/11/22 23:54:38
This seems like something you could do up-front be
djd-OOO-Apr2017
2016/11/23 00:12:11
Done.
| |
| 80 return errors.New("position arguments not expected") | |
| 81 } | |
| 82 return nil | |
| 83 } | |
| 84 | |
| 85 func (c *expArchiveRun) Run(a subcommands.Application, args []string) int { | |
| 86 fmt.Fprintln(a.GetErr(), "WARNING: this command is experimental") | |
| 87 if err := c.parseFlags(a, args); err != nil { | |
| 88 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | |
| 89 return 1 | |
| 90 } | |
| 91 if len(c.isolateFlags.ArchiveOptions.Blacklist) != 0 { | |
| 92 fmt.Fprintf(a.GetErr(), "%s: blacklist is not supported\n", a.Ge tName()) | |
| 93 return 1 | |
| 94 } | |
| 95 if err := c.main(); err != nil { | |
| 96 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | |
| 97 return 1 | |
| 98 } | |
| 99 return 0 | |
| 100 } | |
| OLD | NEW |