Skip to content

Commit f4194e6

Browse files
mknyszekgopherbot
authored andcommitted
sweet: disable get subcommand on wasm
This depends on LUCI libraries which don't build on Wasm. I don't expect anyone to be running the Sweet tool under Wasm. Fixes #74517. Fixes #74518. Change-Id: I80766e091ba986f35100b0fe995eb39e6b1a07b0 Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/689197 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
1 parent aabe7ef commit f4194e6

File tree

3 files changed

+122
-94
lines changed

3 files changed

+122
-94
lines changed

sweet/cmd/sweet/get.go

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@
55
package main
66

77
import (
8-
"context"
98
"flag"
109
"fmt"
1110
"io"
12-
"os"
13-
"path/filepath"
1411

1512
"golang.org/x/benchmarks/sweet/cli/assets"
1613
"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"
2314
)
2415

2516
const (
@@ -48,88 +39,3 @@ func (c *getCmd) SetFlags(f *flag.FlagSet) {
4839
f.StringVar(&c.copyDir, "copy", "", "location to extract assets into, useful for development")
4940
f.BoolVar(&c.clean, "clean", false, "delete all cached assets before installing new ones")
5041
}
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-
}

sweet/cmd/sweet/get_nowasm.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !wasm
6+
7+
package main
8+
9+
import (
10+
"context"
11+
"fmt"
12+
"os"
13+
"path/filepath"
14+
15+
"go.chromium.org/luci/cipd/client/cipd"
16+
"go.chromium.org/luci/cipd/client/cipd/pkg"
17+
cipdc "go.chromium.org/luci/cipd/common"
18+
"go.chromium.org/luci/hardcoded/chromeinfra"
19+
"golang.org/x/benchmarks/sweet/cli/assets"
20+
"golang.org/x/benchmarks/sweet/common/log"
21+
)
22+
23+
func (c *getCmd) Run(_ []string) error {
24+
log.SetActivityLog(true)
25+
ctx := context.Background()
26+
27+
// Do some cleanup, if needed.
28+
if c.clean {
29+
for {
30+
log.Printf("Deleting cache directory %s", c.cache)
31+
fmt.Print("This is a destructive action. Please confirm. (y/n): ")
32+
var r string
33+
_, err := fmt.Scanf("%s\n", &r)
34+
if err != nil {
35+
fmt.Printf("Invalid input: %v\n", err)
36+
} else {
37+
if r == "y" {
38+
break
39+
} else if r == "n" {
40+
return nil
41+
} else {
42+
fmt.Println("Input must be exactly 'y' or 'n'.")
43+
}
44+
}
45+
}
46+
if err := os.RemoveAll(c.cache); err != nil {
47+
return fmt.Errorf("failed to delete cache directory %s: %v", c.cache, err)
48+
}
49+
}
50+
51+
// Load CIPD options, including auth, cache dir, etc. from env. The package is public, but we
52+
// want to be authenticated transparently when we pull the assets down on the builders.
53+
var opts cipd.ClientOptions
54+
if err := opts.LoadFromEnv(ctx); err != nil {
55+
return err
56+
}
57+
if opts.ServiceURL == "" {
58+
opts.ServiceURL = chromeinfra.CIPDServiceURL
59+
}
60+
// Use an existing CIPD cache in the environment, if available.
61+
// Otherwise, set up the default.
62+
if opts.CacheDir == "" {
63+
opts.CacheDir = filepath.Join(c.cache, assets.CIPDCacheDir)
64+
}
65+
66+
// Figure out the destination directory.
67+
var ensureOpts cipd.EnsureOptions
68+
ensureOpts.Paranoia = cipd.CheckIntegrity
69+
if c.copyDir != "" {
70+
ensureOpts.OverrideInstallMode = pkg.InstallModeCopy
71+
opts.Root = c.copyDir
72+
} else {
73+
assetsDir, err := assets.CachedAssets(c.cache, c.version)
74+
if err == nil {
75+
// Nothing to do.
76+
return nil
77+
}
78+
if err != assets.ErrNotInCache {
79+
return err
80+
}
81+
opts.Root = assetsDir
82+
}
83+
84+
// Find the assets by version.
85+
cc, err := cipd.NewClient(opts)
86+
if err != nil {
87+
return err
88+
}
89+
defer cc.Close(ctx)
90+
pins, err := cc.SearchInstances(ctx, "golang/sweet/assets", []string{"version:" + assets.ToCIPDVersion(c.version)})
91+
if err != nil {
92+
return err
93+
}
94+
if len(pins) == 0 {
95+
return fmt.Errorf("unable to find CIPD package instance for version %s", c.version)
96+
}
97+
98+
log.Printf("Fetching assets %s", c.version)
99+
100+
// Fetch the instance.
101+
_, err = cc.EnsurePackages(ctx, map[string]cipdc.PinSlice{"": pins[:1]}, &ensureOpts)
102+
if err != nil {
103+
return fmt.Errorf("fetching CIPD package instance %s: %v", pins[0], err)
104+
}
105+
return nil
106+
}

sweet/cmd/sweet/get_wasm.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"errors"
9+
10+
"golang.org/x/benchmarks/sweet/common/log"
11+
)
12+
13+
func (c *getCmd) Run(_ []string) error {
14+
log.SetActivityLog(true)
15+
return errors.New("get unsupported on wasm: CIPD not supported on wasm")
16+
}

0 commit comments

Comments
 (0)