Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: client/cmd/isolate/exp_archive.go

Issue 2514343005: client/isolate: add skeleton exparchive command (Closed)
Patch Set: mcgreevy comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | client/cmd/isolate/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 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 archiveOpts := &c.isolateFlags.ArchiveOptions
43 // Parse the incoming isolate file.
44 deps, rootDir, isol, err := isolate.ProcessIsolate(archiveOpts)
45 if err != nil {
46 return fmt.Errorf("failed to process isolate: %v", err)
47 }
48 log.Printf("Isolate referenced %d deps", len(deps))
49
50 // TODO(djd): actually do something with the isolated.
51 _ = rootDir
52
53 // Marshal the isolated file into JSON.
54 isolJSON, err := json.Marshal(isol)
55 if err != nil {
56 return err
57 }
58 // TODO(djd): actually check/upload the isolated.
59
60 // Write the isolated file, and emit its digest to stdout.
61 if err := ioutil.WriteFile(archiveOpts.Isolated, isolJSON, 0644); err != nil {
62 return err
63 }
64 fmt.Printf("%s\t%s\n", isolated.HashBytes(isolJSON), filepath.Base(archi veOpts.Isolated))
65
66 return errors.New("experimental archive is not implemented")
67 }
68
69 func (c *expArchiveRun) parseFlags(args []string) error {
70 if len(args) != 0 {
71 return errors.New("position arguments not expected")
72 }
73 if err := c.commonServerFlags.Parse(); err != nil {
74 return err
75 }
76 cwd, err := os.Getwd()
77 if err != nil {
78 return err
79 }
80 if err := c.isolateFlags.Parse(cwd, RequireIsolateFile&RequireIsolatedFi le); err != nil {
81 return err
82 }
83 return nil
84 }
85
86 func (c *expArchiveRun) Run(a subcommands.Application, args []string) int {
87 fmt.Fprintln(a.GetErr(), "WARNING: this command is experimental")
88 if err := c.parseFlags(args); err != nil {
89 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
90 return 1
91 }
92 if len(c.isolateFlags.ArchiveOptions.Blacklist) != 0 {
93 fmt.Fprintf(a.GetErr(), "%s: blacklist is not supported\n", a.Ge tName())
94 return 1
95 }
96 if err := c.main(); err != nil {
97 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
98 return 1
99 }
100 return 0
101 }
OLDNEW
« no previous file with comments | « no previous file | client/cmd/isolate/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698