Skip to content

cargo_build_script uses CARGO_MANIFEST_DIR ending in "/" #3247

@ashi009

Description

@ashi009

Populating CARGO_MANIFEST_DIR in cargo_build_script will not clean the path like in rust.bzl and rustc.bzl.

# Both ctx.label.workspace_root and ctx.label.package are relative paths
# and either can be empty strings. Avoid trailing/double slashes in the path.
components = "${{pwd}}/{}/{}".format(ctx.label.workspace_root, ctx.label.package).split("/")
env["CARGO_MANIFEST_DIR"] = "/".join([c for c in components if c])

components = "{}/{}".format(ctx.label.workspace_root, ctx.label.package).split("/")
env["CARGO_MANIFEST_DIR"] = "/".join([c for c in components if c])

if not incompatible_runfiles_cargo_manifest_dir:
script_data.append(ctx.attr.script[DefaultInfo].default_runfiles.files)
manifest_dir = "{}.runfiles/{}/{}".format(script.path, workspace_name, ctx.label.package)
else:
runfiles_dir, runfiles_inputs, runfiles_args = _create_runfiles_dir(
ctx = ctx,
script = ctx.attr.script,
retain_list = ctx.attr._cargo_manifest_dir_filename_suffixes_to_retain[BuildSettingInfo].value,
)
manifest_dir = "{}/{}/{}".format(runfiles_dir.path, workspace_name, ctx.label.package)
extra_args.append(runfiles_args)
extra_inputs.append(runfiles_inputs)
extra_output = [runfiles_dir]

I think the paths.normalize should be used in all these cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions