sematic
sematic copied to clipboard
CLI should switch cwd to source dir when ran by Bazel
CLI commands sometimes perform file operations. When ran by Bazel, the cwd is changed to the bazel runtime dir, so relative file paths don't work as intended, and we end up with special treatment like:
# make sure the file is created in the workspace, and not in the bazel runtime dir
if not os.path.isabs(file):
workspace = os.getenv("BUILD_WORKSPACE_DIRECTORY")
if workspace is not None:
file = os.path.join(workspace, file)
Always make the CLI switch the cwd to the Bazel root source dir when execute by Bazel, and test that all CLI commands still work as expected.