Skip to content

Commit

Permalink
Fix resolve bug
Browse files Browse the repository at this point in the history
  • Loading branch information
srikrsna-buf committed May 22, 2024
1 parent 98bebcd commit cc5c491
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
38 changes: 19 additions & 19 deletions gazelle/buf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ func loadConfig(gazelleConfig *config.Config, packageRelativePath string, file *
config.ModuleRoot = true
config.BufConfigFile = label.New("", packageRelativePath, bufConfigFile)
}
// When using workspaces, for gazelle to generate accurate proto_library rules
// we need add `# gazelle:proto_strip_import_prefix /path` to BUILD file at each module root
//
// Here we set the config if the directive is not present
if config.ModuleRoot && packageRelativePath != "" {
protoConfig := proto.GetProtoConfig(gazelleConfig)
stripImportPrefix := "/" + packageRelativePath
if protoConfig.StripImportPrefix == "" {
protoConfig.StripImportPrefix = stripImportPrefix
}
if protoConfig.StripImportPrefix != stripImportPrefix {
log.Printf(
"strip_import_prefix at %s should be %s but is %s",
packageRelativePath,
stripImportPrefix,
protoConfig.StripImportPrefix,
)
}
}
if file == nil {
return config
}
Expand All @@ -120,25 +139,6 @@ func loadConfig(gazelleConfig *config.Config, packageRelativePath string, file *
config.BreakingMode = breakingMode
}
}
// When using workspaces, for gazelle to generate accurate proto_library rules
// we need add `# gazelle:proto_strip_import_prefix /path` to BUILD file at each module root
//
// Here we set the config if the directive is not present
if config.ModuleRoot && packageRelativePath != "" {
protoConfig := proto.GetProtoConfig(gazelleConfig)
stripImportPrefix := "/" + packageRelativePath
if protoConfig.StripImportPrefix == "" {
protoConfig.StripImportPrefix = stripImportPrefix
}
if protoConfig.StripImportPrefix != stripImportPrefix {
log.Printf(
"strip_import_prefix at %s should be %s but is %s",
packageRelativePath,
stripImportPrefix,
protoConfig.StripImportPrefix,
)
}
}
return config
}

Expand Down
1 change: 0 additions & 1 deletion gazelle/buf/testdata/v2/cross_resolve/petapis/BUILD.in

This file was deleted.

11 changes: 0 additions & 11 deletions gazelle/buf/testdata/v2/cross_resolve/petapis/BUILD.out

This file was deleted.

0 comments on commit cc5c491

Please sign in to comment.