Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid re-entrance #221

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ Companies with more than 250 employees can contact us at sales@aspect.dev for a

# Installation

## Using a package manager
## In `.bazelversion` (recommended)

> Coming soon
Add a new line at the top of your `.bazelversion` file containing `aspect-build/[version]`,
keeping your original content on following lines.

For example, to use Aspect CLI 1.2.3 with Bazel 5.2.0, your `.bazelversion` would contain

```
aspect-build/1.2.3
5.2.0
```

## Manual installation

Expand Down
9 changes: 9 additions & 0 deletions pkg/bazel/bazelisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,17 @@ func (bazelisk *Bazelisk) getBazelVersion() (string, error) {
defer f.Close()

scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
scanner.Scan()
bazelVersion := scanner.Text()
// If the first line of .bazelversion is Aspect CLI, then when we call
// bazelisk it will read the file again and we'll call ourselves in a loop.
// We don't want to be re-entrant, so detect when our fork is selected.
// In this case, the user should put their bazel version on the following line.
if strings.HasPrefix(bazelVersion, "aspect-build/") {
scanner.Scan()
bazelVersion = scanner.Text()
}
if err := scanner.Err(); err != nil {
return "", fmt.Errorf("could not read version from file %s: %v", bazelVersion, err)
}
Expand Down