|
5 | 5 | package main |
6 | 6 |
|
7 | 7 | import ( |
8 | | - "context" |
9 | 8 | "flag" |
10 | 9 | "fmt" |
11 | 10 | "io" |
12 | | - "os" |
13 | | - "path/filepath" |
14 | 11 |
|
15 | 12 | "golang.org/x/benchmarks/sweet/cli/assets" |
16 | 13 | "golang.org/x/benchmarks/sweet/common" |
17 | | - "golang.org/x/benchmarks/sweet/common/log" |
18 | | - |
19 | | - "go.chromium.org/luci/cipd/client/cipd" |
20 | | - "go.chromium.org/luci/cipd/client/cipd/pkg" |
21 | | - cipdc "go.chromium.org/luci/cipd/common" |
22 | | - "go.chromium.org/luci/hardcoded/chromeinfra" |
23 | 14 | ) |
24 | 15 |
|
25 | 16 | const ( |
@@ -48,88 +39,3 @@ func (c *getCmd) SetFlags(f *flag.FlagSet) { |
48 | 39 | f.StringVar(&c.copyDir, "copy", "", "location to extract assets into, useful for development") |
49 | 40 | f.BoolVar(&c.clean, "clean", false, "delete all cached assets before installing new ones") |
50 | 41 | } |
51 | | - |
52 | | -func (c *getCmd) Run(_ []string) error { |
53 | | - log.SetActivityLog(true) |
54 | | - ctx := context.Background() |
55 | | - |
56 | | - // Do some cleanup, if needed. |
57 | | - if c.clean { |
58 | | - for { |
59 | | - log.Printf("Deleting cache directory %s", c.cache) |
60 | | - fmt.Print("This is a destructive action. Please confirm. (y/n): ") |
61 | | - var r string |
62 | | - _, err := fmt.Scanf("%s\n", &r) |
63 | | - if err != nil { |
64 | | - fmt.Printf("Invalid input: %v\n", err) |
65 | | - } else { |
66 | | - if r == "y" { |
67 | | - break |
68 | | - } else if r == "n" { |
69 | | - return nil |
70 | | - } else { |
71 | | - fmt.Println("Input must be exactly 'y' or 'n'.") |
72 | | - } |
73 | | - } |
74 | | - } |
75 | | - if err := os.RemoveAll(c.cache); err != nil { |
76 | | - return fmt.Errorf("failed to delete cache directory %s: %v", c.cache, err) |
77 | | - } |
78 | | - } |
79 | | - |
80 | | - // Load CIPD options, including auth, cache dir, etc. from env. The package is public, but we |
81 | | - // want to be authenticated transparently when we pull the assets down on the builders. |
82 | | - var opts cipd.ClientOptions |
83 | | - if err := opts.LoadFromEnv(ctx); err != nil { |
84 | | - return err |
85 | | - } |
86 | | - if opts.ServiceURL == "" { |
87 | | - opts.ServiceURL = chromeinfra.CIPDServiceURL |
88 | | - } |
89 | | - // Use an existing CIPD cache in the environment, if available. |
90 | | - // Otherwise, set up the default. |
91 | | - if opts.CacheDir == "" { |
92 | | - opts.CacheDir = filepath.Join(c.cache, assets.CIPDCacheDir) |
93 | | - } |
94 | | - |
95 | | - // Figure out the destination directory. |
96 | | - var ensureOpts cipd.EnsureOptions |
97 | | - ensureOpts.Paranoia = cipd.CheckIntegrity |
98 | | - if c.copyDir != "" { |
99 | | - ensureOpts.OverrideInstallMode = pkg.InstallModeCopy |
100 | | - opts.Root = c.copyDir |
101 | | - } else { |
102 | | - assetsDir, err := assets.CachedAssets(c.cache, c.version) |
103 | | - if err == nil { |
104 | | - // Nothing to do. |
105 | | - return nil |
106 | | - } |
107 | | - if err != assets.ErrNotInCache { |
108 | | - return err |
109 | | - } |
110 | | - opts.Root = assetsDir |
111 | | - } |
112 | | - |
113 | | - // Find the assets by version. |
114 | | - cc, err := cipd.NewClient(opts) |
115 | | - if err != nil { |
116 | | - return err |
117 | | - } |
118 | | - defer cc.Close(ctx) |
119 | | - pins, err := cc.SearchInstances(ctx, "golang/sweet/assets", []string{"version:" + assets.ToCIPDVersion(c.version)}) |
120 | | - if err != nil { |
121 | | - return err |
122 | | - } |
123 | | - if len(pins) == 0 { |
124 | | - return fmt.Errorf("unable to find CIPD package instance for version %s", c.version) |
125 | | - } |
126 | | - |
127 | | - log.Printf("Fetching assets %s", c.version) |
128 | | - |
129 | | - // Fetch the instance. |
130 | | - _, err = cc.EnsurePackages(ctx, map[string]cipdc.PinSlice{"": pins[:1]}, &ensureOpts) |
131 | | - if err != nil { |
132 | | - return fmt.Errorf("fetching CIPD package instance %s: %v", pins[0], err) |
133 | | - } |
134 | | - return nil |
135 | | -} |
0 commit comments