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