Skip to content

Buildifier cannot find .buildifier-tables.json when run from a subdirectory within the workspace. #1311

@dpleshakov

Description

@dpleshakov

Description:

Buildifier looks for .buildifier.json starting from the current directory and traversing up to the workspace root. However, the paths specified in .buildifier.json for Tables and AddTables are used "as-is," which can lead to issues when running buildifier from a subdirectory.

Example project structure:

root/
├── .buildifier.json
├── .buildifier-tables.json
├── foo/
│   └── BUILD.bazel
├── BUILD.bazel
└── WORKSPACE

.buildifier.json content:

{
  "AddTables": ".buildifier-tables.json"
}

Steps to reproduce:

  • If buildifier is run from the root directory (buildifier -r .), there is no issue.
  • If buildifier is run from the foo subdirectory (cd foo && buildifier), the following error occurs:
    buildifier: failed to parse .buildifier-tables.json for -add_tables: open .buildifier-tables.json: The system cannot find the file specified.
    
    In this case, buildifier successfully finds .buildifier.json, but cannot locate the .buildifier-tables.json file, even though it is in the same directory as .buildifier.json.

Examples:

I have created an example project to demonstrate the problem and validate a solution. You can find it here:

Expected behavior:

Buildifier should be able to find .buildifier-tables.json regardless of the directory from which it is run, or it should provide a way to resolve this issue without requiring a full path to the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions