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

Sample .bazelignore wildcard pr using isPackageIgnored #13807

Closed
wants to merge 7 commits into from

Conversation

David-Lam
Copy link

A sample pr with recommended implementation from maintainer in pr:#13756.

reset changes

implemented lazy wildcard matching

changed to use custom globbing function because UnixGlob Builder take a long time for some reason

clean up code

added logs and comment

fixed comment and log

clean up code

remove Eventhandler because it will throw error

changed Symlink and use concurrent hash set

added early stop
@google-cla google-cla bot added the cla: yes label Aug 5, 2021
@ThomasCJY
Copy link
Contributor

@janakdr any comment on this change? According to #13756 (comment) this change will fail the test cases

Copy link
Contributor

@janakdr janakdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of places where IgnoredPackagePrefixesValue#getPatterns is called. Why didn't this PR change all of them? In particular, the one in GlobFunction seems highly relevant to a test case concerning globs.

}

@Override
public int hashCode() {
return patterns.hashCode();
return ignoredPrefixes.hashCode() ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably want to incorporate the wildcardPatterns as well into the hash code?

@@ -54,19 +71,33 @@ public static SkyKey key(RepositoryName repository) {
}

public ImmutableSet<PathFragment> getPatterns() {
return patterns;
return ignoredPrefixes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this method needed for now that #isPathFragmentIgnored is available? It seems very likely that all callers have to be updated. One way to approach this would be to not change any end-to-end behavior first, but just to replace all usages of #getPatterns with usages of #isPathFragmentIgnored. Then in a follow-up you can change the implementation of #isPathFragmentIgnored, which will be a 1- or 2-file change, and add the tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! Any advice on changing the place that doesn't perform the check immediately but pass the set of ignored directory PathFragment to others? For example, in TargetPatternFunction, it passes the set to TargetPattern. Then TargetPattern use the set to produce an IgnoredPathFragmentsInScopeOrFilteringIgnorer (through getAllIgnoredSubdirectoriesToExclude) and pass to TargetPatternResolver, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass a predicate instead of the set. The predicate can be the method reference ::isPathFragmentIgnored. Is there any place that actually needs to iterate over the set, versus checking for membership?

Copy link
Author

@David-Lam David-Lam Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some places. Examples:
Line 174 in EnvironmentBackedRecursivePackageProvider.java & Line 46 in RecursivePkgValueRootPackageExtractor.java

ImmutableSet<PathFragment> filteredIgnoredSubdirectories =
        ImmutableSet.copyOf(
            Iterables.filter(ignoredSubdirectories, path -> path.startsWith(directory)));

Copy link
Author

@David-Lam David-Lam Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestion @janakdr ? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. It looks like this feature would require a fair amount of work to the rest of Bazel to actually work as intended, but I'm open to it. In particular, the fancy "filtering" code you pointed to would no longer work trivially. I think you could make it work by enriching the Predicate you're providing to have a method #restrictedTo(PathFragment fragment). That method would filter the prefixes, and leave the regexes unchanged, since it would be fairly hard to test them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @janakdr! I am stuck on modifing this function:

public IgnoredPathFragmentsInScopeOrFilteringIgnorer getAllIgnoredSubdirectoriesToExclude(
    InterruptibleSupplier<ImmutableSet<PathFragment>> ignoredPackagePrefixes)
    throws InterruptedException {
  ImmutableSet.Builder<PathFragment> ignoredPathsBuilder =
      ImmutableSet.builderWithExpectedSize(0);
  for (PathFragment ignoredPackagePrefix : ignoredPackagePrefixes.get()) {
    if (this.containedIn(ignoredPackagePrefix)) {
      return new IgnoredPathFragmentsInScopeOrFilteringIgnorer.FilteringIgnorer(
          ignoredPackagePrefix);
    }
    PackageIdentifier pkgIdForIgnoredDirectorPrefix =
        PackageIdentifier.create(this.getDirectory().getRepository(), ignoredPackagePrefix);
    if (this.containsAllTransitiveSubdirectories(pkgIdForIgnoredDirectorPrefix)) {
      ignoredPathsBuilder.add(ignoredPackagePrefix);
    }
  }
  return IgnoredPathFragmentsInScopeOrFilteringIgnorer.IgnoredPathFragments.of(
      ignoredPathsBuilder.build());
}

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java#L630-L648.
Any help will be great! Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you can do the filtering of the ignored paths as before, and just propagate any regexes along unchanged (since it would be very difficult to see if a regex could apply to a subdirectory). You'd probably want to have special cases for the "totally ignored," "empty ignored paths and empty regexes," and "non-empty ignored paths and empty regexes." You might want to reverse the logic, so the "filterer" takes in a target pattern and has to produce a new filterer, rather than putting the target pattern in charge, but I could see either way.

@devjgm
Copy link

devjgm commented Jan 13, 2022

Any update on this PR? Some of us are really looking forward to glob support in .bazelignore files :-)

@sgowroji sgowroji added team-Core Skyframe, bazel query, BEP, options parsing, bazelrc awaiting-review PR is awaiting review from an assigned reviewer labels Apr 22, 2022
@nate-thirdwave
Copy link

Nudging this. It seems like it's ready to go?

@ThomasCJY
Copy link
Contributor

@janakdr @David-Lam any advice on how we can move forward here?

@janakdr janakdr requested review from haxorz and janakdr and removed request for janakdr October 14, 2022 22:01
@janakdr
Copy link
Contributor

janakdr commented Oct 14, 2022

I totally failed to remove myself from the reviewers list, but at least I managed to add @haxorz. I'm no longer working on Bazel, so @haxorz will decide what to do with this PR. My understanding of the current status is that I suggested some changes to @David-Lam and they haven't been applied yet. I would lean towards closing this PR and waiting for @David-Lam to update it and re-request.

@haxorz
Copy link
Contributor

haxorz commented Oct 14, 2022

My understanding of the current status is that I suggested some changes to @David-Lam and they haven't been applied yet.

That was my understanding too when I checked this PR in April (in my sweep of all pending PRs).

I also flagged this PR and the general feature request to @sventiffe back then. Sven, I'd be happy to chat about this!

@keertk
Copy link
Member

keertk commented Dec 15, 2022

Hi there! Thank you for contributing to the Bazel repository. We appreciate your time and effort. We're doing a clean up of old PRs and will be closing this one since it seems to have stalled. Please feel free to reopen/let us know if you’re still interested in pursuing this or if you'd like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

@keertk keertk closed this Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer cla: yes team-Core Skyframe, bazel query, BEP, options parsing, bazelrc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants