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

fix: gazelle failing on Windows with "panic: runtime error: invalid memory address or nil pointer dereference" #1872

Merged
merged 7 commits into from
May 19, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ A brief description of the categories of changes:
version dependency select statements when the `experimental_target_platforms`
includes the Python ABI. The default python version case within the select is
also now handled correctly, stabilizing the implementation.
* (gazelle) Fix Gazelle failing on Windows with
"panic: runtime error: invalid memory address or nil pointer dereference"

### Added
* (rules) Precompiling Python source at build time is available. but is
Expand Down
4 changes: 2 additions & 2 deletions gazelle/pythonconfig/pythonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package pythonconfig

import (
"fmt"
"path/filepath"
"path"
"strings"

"github.com/emirpasic/gods/lists/singlylinkedlist"
Expand Down Expand Up @@ -126,7 +126,7 @@ type Configs map[string]*Config

// ParentForPackage returns the parent Config for the given Bazel package.
func (c *Configs) ParentForPackage(pkg string) *Config {
dir := filepath.Dir(pkg)
dir := path.Dir(pkg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, I am not sure it is working the way you think. path.Dir will just split at / if I understand things correctly and filepath.Path is much more sophisticated and I am surprised that this is not working correctly.

I don't have a Windows machine, but the code change looks suspicious.

Copy link
Contributor Author

@bartoszpop bartoszpop May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aignas the same issue I have fixed here. My initial approach was to use cfgs[filepath.FromSlash(rel)] but a more targeted fix was proposed in this comment.

Basically, it fails because pythonconfig.go#ParentForPackage delegates to filepath.Dir(pkg) to replace the separator character "\" with "/", hence for a 2-levels deep path, e.g. rootDir\nestedDir1\nestedDir2, a parent is searched with "/" (rootDir/nestedDir1) but Configs contains a key with "\" (rootDir\nestedDir1).

Copy link
Collaborator

@aignas aignas May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, thanks for the context, it was much needed here. Could you please rebase and add Changelog notes to the Changelog.md please?

EDIT: Would it be possible to add a test for this?

if dir == "." {
dir = ""
}
Expand Down
Loading