Skip to content

mtree_spec generates items containing .. #7

@maxitg

Description

@maxitg

Description

Starting with version 2.9.0, mtree_spec creates items containing .. when used with rules_python on a py_binary with dependencies.

Given that it involves __init__.py files, it might have something to do with bazel-contrib/bazel-lib#939.

Steps to Reproduce

  1. Set up a minimal project:

    MODULE.bazel

    module(name = "test-module")
    
    bazel_dep(name = "aspect_bazel_lib", version = "2.9.0")  # https://github.com/aspect-build/bazel-lib
    bazel_dep(name = "rules_python", version = "1.1.0")  # https://github.com/bazelbuild/rules_python
    
    python = use_extension("@rules_python//python/extensions:python.bzl", "python")
    python.toolchain(
        python_version = "3.13.1",
    )
    
    pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
    pip.parse(
        hub_name = "pypi",
        python_version = "3.13.1",
        requirements_lock = "//:requirements_lock.txt",
    )
    use_repo(pip, "pypi")

    BUILD.bazel

    load("@rules_python//python:pip.bzl", "compile_pip_requirements")
    
    compile_pip_requirements(
        name = "requirements",
        src = "requirements.in",
        requirements_txt = "requirements_lock.txt",
    )

    requirements.in

    psutil
    

    test/BUILD.bazel

    load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar")
    load("@rules_python//python:defs.bzl", "py_binary")
    
    py_binary(
        name = "test_bin",
        srcs = ["test_bin.py"],
        deps = ["@pypi//psutil:pkg"],
    )
    
    mtree_spec(
        name = "test_bin_mtree",
        srcs = [":test_bin"],
    )
    
    tar(
        name = "tar",
        srcs = [":test_bin"],
        mtree = ":test_bin_mtree",
    )

    test/test_bin.py

    #!/usr/bin/env python
    
    import psutil
    
    print(psutil.Process().exe())
  2. Build:

    bazel --version # bazel 8.1.1
    : > requirements_lock.txt && bazel run //:requirements.update
    bazel build //test:tar

Expectation

Paths with .. are never generated in the mtree and tar can unpack the //test:tar target.

Actual Outcome

$ cat bazel-bin/test/test_bin_mtree.spec | grep '\.\.' | grep psutil
test/test_bin.runfiles/_main/../rules_python++pip+pypi_313_psutil/__init__.py uid=0 gid=0 time=1672560000 mode=0755 type=file

$ cd bazel-bin/test 
$ tar xvf tar.tar 
test/
test/test_bin
test/test_bin.py
test/test_bin.runfiles/
tar: Removing leading `test/test_bin.runfiles/_main/../' from member names
tar: test/test_bin.runfiles/_main/../rules_python++pip+pypi_313_psutil/__init__.py: Member name contains '..'
tar: test/test_bin.runfiles/_main/../__init__.py: Member name contains '..'
...
tar: Exiting with failure status due to previous errors
$ echo $?
2

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