8000 fix(gazelle): runfiles discovery (#1429) · bazel-contrib/rules_python@48daf52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48daf52

Browse files
authored
fix(gazelle): runfiles discovery (#1429)
Pass the environment generated by the `runfiles` helper so that the Python launcher can find the runfiles correctly as implemented in bazelbuild/bazel#14740. Fixes #1426
1 parent d8966b8 commit 48daf52

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ A brief description of the categories of changes:
6363
dependencies improving initial build times involving external dependency
6464
fetching.
6565

66+
* (gazelle) Improve runfiles lookup hermeticity.
67+
6668
## [0.25.0] - 2023-08-22
6769

6870
### Changed

gazelle/python/parser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ var (
3838
)
3939

4040
func startParserProcess(ctx context.Context) {
41-
parseScriptRunfile, err := runfiles.Rlocation("rules_python_gazelle_plugin/python/parse")
41+
rfiles, err := runfiles.New()
42+
if err != nil {
43+
log.Printf("failed to create a runfiles object: %v\n", err)
44+
os.Exit(1)
45+
}
46+
47+
parseScriptRunfile, err := rfiles.Rlocation("rules_python_gazelle_plugin/python/parse")
4248
if err != nil {
4349
log.Printf("failed to initialize parser: %v\n", err)
4450
os.Exit(1)
4551
}
4652

4753
cmd := exec.CommandContext(ctx, parseScriptRunfile)
54+
cmd.Env = append(os.Environ(), rfiles.Env()...)
4855

4956
cmd.Stderr = os.Stderr
5057

gazelle/python/std_modules.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ var (
3939
func startStdModuleProcess(ctx context.Context) {
4040
stdModulesSeen = make(map[string]struct{})
4141

42-
stdModulesScriptRunfile, err := runfiles.Rlocation("rules_python_gazelle_plugin/python/std_modules")
42+
rfiles, err := runfiles.New()
43+
if err != nil {
44+
log.Printf("failed to create a runfiles object: %v\n", err)
45+
os.Exit(1)
46+
}
47+
48+
stdModulesScriptRunfile, err := rfiles.Rlocation("rules_python_gazelle_plugin/python/std_modules")
4349
if err != nil {
4450
log.Printf("failed to initialize std_modules: %v\n", err)
4551
os.Exit(1)
@@ -49,7 +55,8 @@ func startStdModuleProcess(ctx context.Context) {
4955

5056
cmd.Stderr = os.Stderr
5157
// All userland site-packages should be ignored.
52-
cmd.Env = []string{"PYTHONNOUSERSITE=1"}
58+
cmd.Env = append([]string{"PYTHONNOUSERSITE=1"}, rfiles.Env()...)
59+
5360
stdin, err := cmd.StdinPipe()
5461
if err != nil {
5562
log.Printf("failed to initialize std_modules: %v\n", err)

0 commit comments

Comments
 (0)
0