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

Directories from glob are not marked as is_directory #12954

Open
UebelAndre opened this issue Feb 3, 2021 · 5 comments
Open

Directories from glob are not marked as is_directory #12954

UebelAndre opened this issue Feb 3, 2021 · 5 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: bug

Comments

@UebelAndre
Copy link
Contributor

Description of the problem / feature request:

Directories included from glob using exclude_directories = 0 do not correctly return True for File.is_directory.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Running bazel build ... with the following files will reproduce this issue.

BUILD.bazel

load("//:rule.bzl", "my_rule")

filegroup(
    name = "srcs",
    srcs = glob(
        ["**/**"],
        exclude_directories = 0,
    ),
)

my_rule(
    name = "my_rule",
    data = ":srcs",
)

rule.bzl

def _rule_impl(ctx):
    for file in ctx.files.data:
        if file.is_source:
            print("{} is source".format(file))
        else:
            print("{} is directory".format(file))

my_rule = rule(
    implementation = _rule_impl,
    attrs = {
        "data": attr.label(
            allow_files = True,
            default = "//:srcs",
        )
    }
)

dir/file.txt

# This is a file in a directory

WORKSPACE.bazel

workspace(name = "is_directory_test")

What operating system are you running Bazel on?

MacOS/Linux

What's the output of bazel info release?

release 4.0.0

Any other information, logs, or outputs that you want to share?

Note that <source file dir> is source from the output below is incorrect. It's a directory. <source file dir> is directory (or something to this effect, hitting the else condition in rule.bzl) should have been printed.

bazel build ...
INFO: Invocation ID: c54083cd-e13a-4092-91a5-90c4e4aef70c
DEBUG: /Users/user/Code/test/is_directory/rule.bzl:4:18: <source file BUILD.bazel> is source
DEBUG: /Users/user/Code/test/is_directory/rule.bzl:4:18: <source file WORKSPACE.bazel> is source
DEBUG: /Users/user/Code/test/is_directory/rule.bzl:4:18: <source file dir> is source
DEBUG: /Users/user/Code/test/is_directory/rule.bzl:4:18: <source file dir/file.txt> is source
DEBUG: /Users/user/Code/test/is_directory/rule.bzl:4:18: <source file rule.bzl> is source
INFO: Analyzed 2 targets (1 packages loaded, 7 targets configured).
INFO: Found 2 targets...
INFO: Elapsed time: 0.257s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
@oquenchil oquenchil added team-Rules-Server Issues for serverside rules included with Bazel P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: bug labels Feb 4, 2021
@aiuto
Copy link
Contributor

aiuto commented May 12, 2021

I got bit by this today too. It is not just from glob, it happens with explicit paths to directories as well.
Here a a reproduction. https://github.com/aiuto/samples/tree/main/bazel_issue_12954

Is there any chance of bumping this up from P4?

@aiuto aiuto changed the title Directories from glob are not marked as directories Directories from glob are not marked as is_directory May 13, 2021
@pauldraper
Copy link
Contributor

pauldraper commented Mar 15, 2022

This directory expansion in args as well.

Currently, if you want to use a directory, it has to come as the output of a rule.

@pauldraper
Copy link
Contributor

I got bit by this today too. It is not just from glob, it happens with explicit paths to directories as well.

Correct. glob() simply returns a list of strings, with which you can pass as files, strings, execute conditional logic, etc.

The correct title of this issue is "Source directories are not marked as is_directory"

I know that source directories aren't really supported in Bazel. I was using them for efficient processing of hundreds of npm dependencies. There isn't really a great alternative.

Copy link

github-actions bot commented Jul 4, 2024

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jul 4, 2024
@pauldraper
Copy link
Contributor

Comment

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: bug
Projects
None yet
Development

No branches or pull requests

4 participants