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

Support MODULE.bazel in FindRepoBuildFiles() #1287

Open
mering opened this issue Aug 22, 2024 · 0 comments
Open

Support MODULE.bazel in FindRepoBuildFiles() #1287

mering opened this issue Aug 22, 2024 · 0 comments

Comments

@mering
Copy link
Contributor

mering commented Aug 22, 2024

Currently, it only parses WORKSPACE:

ws := filepath.Join(root, workspaceFile)

This is used for example by edit.InterpretLabel():

buildtools/edit/edit.go

Lines 41 to 113 in 19c62d9

// InterpretLabelForWorkspaceLocation returns the name of the BUILD file to
// edit, the full package name, and the rule. It takes a workspace-rooted
// directory to use.
func InterpretLabelForWorkspaceLocation(root, target string) (buildFile, repo, pkg, rule string) {
label := labels.Parse(target)
repo = label.Repository
pkg = label.Package
rule = label.Target
rootDir, relativePath := wspace.FindWorkspaceRoot(root)
if repo != "" {
files, err := wspace.FindRepoBuildFiles(rootDir)
if err == nil {
if buildFile, ok := files[repo]; ok {
return buildFile, repo, pkg, rule
}
}
// TODO(rodrigoq): report error for other repos
}
defaultBuildFileName := "BUILD"
if strings.HasPrefix(target, "//") {
pkgPath := filepath.Join(rootDir, filepath.FromSlash(pkg))
if wspace.IsRegularFile(pkgPath) {
// allow operation on other files like WORKSPACE
buildFile = pkgPath
pkg = path.Dir(pkg)
return
}
for _, buildFileName := range BuildFileNames {
buildFile = filepath.Join(pkgPath, buildFileName)
if wspace.IsRegularFile(buildFile) {
return
}
}
buildFile = filepath.Join(pkgPath, defaultBuildFileName)
return
}
if wspace.IsRegularFile(filepath.FromSlash(pkg)) {
// allow operation on other files like WORKSPACE
buildFile = pkg
pkg = filepath.Join(relativePath, filepath.FromSlash(path.Dir(pkg)))
return
}
found := false
for _, buildFileName := range BuildFileNames {
buildFile = filepath.Join(pkg, buildFileName)
if wspace.IsRegularFile(buildFile) {
found = true
break
}
}
if !found {
buildFile = filepath.Join(pkg, defaultBuildFileName)
}
pkg = filepath.Join(relativePath, filepath.FromSlash(pkg))
return
}
// InterpretLabel returns the name of the BUILD file to edit, the full
// package name, and the rule. It uses the pwd for resolving workspace file paths.
func InterpretLabel(target string) (buildFile string, pkg string, rule string) {
buildFile, _, pkg, rule = InterpretLabelForWorkspaceLocation("", target)
return buildFile, pkg, rule
}
// InterpretLabelWithRepo returns the name of the BUILD file to edit, repo name,
// the full package name, and the rule. It uses the pwd for resolving workspace
// file paths.
func InterpretLabelWithRepo(target string) (buildFile string, repo string, pkg string, rule string) {
return InterpretLabelForWorkspaceLocation("", target)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant