Chromium Code Reviews| Index: client/cmd/isolate/exp_archive.go |
| diff --git a/client/cmd/isolate/exp_archive.go b/client/cmd/isolate/exp_archive.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..19bcb7cfb4de843efcba8564c37828e17b82b67b |
| --- /dev/null |
| +++ b/client/cmd/isolate/exp_archive.go |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2015 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package main |
| + |
| +import ( |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "io/ioutil" |
| + "log" |
| + "os" |
| + "path/filepath" |
| + |
| + "github.com/luci/luci-go/client/isolate" |
| + "github.com/luci/luci-go/common/isolated" |
| + "github.com/maruel/subcommands" |
| +) |
| + |
| +var cmdExpArchive = &subcommands.Command{ |
| + UsageLine: "exparchive <options>", |
| + ShortDesc: "EXPERIMENTAL creates a .isolated file and uploads the tree to 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.
|
| + LongDesc: "All the files listed in the .isolated file are put in the isolate server cache. Small files are combined together in a tar archive before uploading.", |
| + CommandRun: func() subcommands.CommandRun { |
| + c := expArchiveRun{} |
| + c.commonServerFlags.Init() |
| + c.isolateFlags.Init(&c.Flags) |
| + return &c |
| + }, |
| +} |
| + |
| +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.
|
| + 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
|
| + isolateFlags |
| +} |
| + |
| +func (c *expArchiveRun) Parse(a subcommands.Application, args []string) error { |
| + if err := c.commonServerFlags.Parse(); err != nil { |
| + return err |
| + } |
| + cwd, err := os.Getwd() |
| + if err != nil { |
| + return err |
| + } |
| + 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.
|
| + return err |
| + } |
| + if len(args) != 0 { |
| + return errors.New("position arguments not expected") |
| + } |
| + return nil |
| +} |
| + |
| +func (c *expArchiveRun) main(a subcommands.Application, args []string) error { |
| + // Parse the incoming isolate file. |
| + deps, rootDir, isol, err := isolate.ProcessIsolate(&c.ArchiveOptions) |
| + if err != nil { |
| + return fmt.Errorf("failed to process isolate: %v", err) |
| + } |
| + log.Printf("Isolate referenced %d deps", len(deps)) |
| + |
| + // TODO(djd): actually do something with the isolated. |
| + _ = rootDir |
| + |
| + // Marshal the isolated file into JSON. |
| + isolJSON, err := json.Marshal(isol) |
| + if err != nil { |
| + return err |
| + } |
| + // TODO(djd): actually check/upload the isolated. |
| + |
| + // Write the isolated file, and emit its digest to stdout. |
| + if err := ioutil.WriteFile(c.ArchiveOptions.Isolated, isolJSON, 0644); err != nil { |
| + return err |
| + } |
| + fmt.Printf("%s\t%s\n", isolated.HashBytes(isolJSON), filepath.Base(c.ArchiveOptions.Isolated)) |
| + |
| + return errors.New("experimental archive is not implemented") |
| +} |
| + |
| +func (c *expArchiveRun) Run(a subcommands.Application, args []string) int { |
| + fmt.Fprintln(a.GetErr(), "WARNING: this command is experimental") |
| + if err := c.Parse(a, args); err != nil { |
| + fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) |
| + return 1 |
| + } |
| + if len(c.ArchiveOptions.Blacklist) != 0 { |
| + fmt.Fprintf(a.GetErr(), "%s: blacklist is not supported\n", a.GetName()) |
| + return 1 |
| + } |
| + if err := c.main(a, args); err != nil { |
| + fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) |
| + return 1 |
| + } |
| + return 0 |
| +} |