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

Support for excluding targets from wildcard selection #1550

Closed
lefou opened this issue Nov 6, 2021 · 3 comments · Fixed by #2997
Closed

Support for excluding targets from wildcard selection #1550

lefou opened this issue Nov 6, 2021 · 3 comments · Fixed by #2997
Milestone

Comments

@lefou
Copy link
Member

lefou commented Nov 6, 2021

Selecting many targets with wildcard and the braces syntax is very convenient, but if there is need to exclude some targets from the expansion, one needs to enumerate all targets separately (or find clever smaller selection pattern).

As a dual of + to select multiple targets (e.g. mill foo.compile + bar.compile) it would be convenient if we could also support a - to de-select some targets, e.g. to match all compile targets, but not bar.compile we could then write: mill __.compile - bar.compile.

@lefou lefou changed the title Support - to exclude targets from wildcard selection Support - to exclude targets from wildcard selection (RFC) Nov 8, 2021
@lefou lefou added the feedback wanted Additional feedback or testing is apreciated label Nov 8, 2021
@lihaoyi
Copy link
Member

lihaoyi commented Nov 16, 2021

Sounds like a great idea. Seems like we're gradually growing our own version of the Bazel Query syntax 😛 https://docs.bazel.build/versions/main/query-how-to.html

@lefou
Copy link
Member Author

lefou commented Feb 26, 2023

A small update. I started to experiment with it more than once, but this one isn't as easy as the + selector. The issue is, that in case there are wildcards involved, the wildcards are only resolved after we processed the +. To properly handle a -, we need to process it after we resolved all wildcards to tasks and their args. This means, we also handle resolution of commands specially, as they currently can only be resolved if their args are valid, which is probably not what we want if we want to exclude some. (E.g. an command on ten modules which requires tree parameters, but we want to exclude it for two modules.)

@lefou
Copy link
Member Author

lefou commented Feb 2, 2024

With #2997, we are now able to select / deselect by module type, so the initially given fictive example

> mill __.compile - bar.compile

could be now achieved with

bash> mill __:^bar.compile

I think, this is good enough, and we can close this issue after #2997 is merged.

@lefou lefou removed the feedback wanted Additional feedback or testing is apreciated label Feb 2, 2024
@lefou lefou changed the title Support - to exclude targets from wildcard selection (RFC) Support for excluding targets from wildcard selection Feb 2, 2024
lefou added a commit that referenced this issue Feb 4, 2024
This PR add support for new selector pattern `_:Type`.

In addition to `_` and `__`, which select arbitrary segments, the
`_:MyType` and `__:MyType` patterns can select modules of the specified
type.

The type is matched by it's name and optionally by it's enclosing types
and packages, separated by a `.` sign. Since this is also used to
separate target path segments, a type selector segment containing a `.`
needs to be enclosed in parenthesis. A full qualified type can be
enforced with the `_root_` package.

Example: Find all test jars

```sh
> mill resolve __:TestModule.jar
> mill resolve "(__:scalalib.TestModule).jar"
> mill resolve "(__:mill.scalalib.TestModule).jar"
> mill resolve "(__:_root_.mill.scalalib.TestModule).jar"
```

If a `^` or `!` is preceding the type pattern, it only matches segments
not an instance of that specified type. Please note that in some shells
like `bash`, you need to mask the `!` character.

Example: Find all jars not in test modules

```sh
> mill resolve __:^TestModule.jar
```

You can also provide more than one type pattern, separated with `:`. 

Example: Find all `JavaModule`s which are not `ScalaModule`s or
`TestModule`s:

```sh
> mill resolve "__:JavaModule:^ScalaModule:^TestModule.jar"
```

Remarks:

* Kudos to @lihaoyi who refactored the resolver in
#2511 and made this PR possible.
I tried to implement it multiple times before, and ever got bitten by
the old gnarly resolver code.
* It's currently not possible to match task/target types. It might be
possible, but due to `Task` being a parametrized type, it might not be
as easy to implement and use.

Fix #1550

Pull request: #2997
@lefou lefou added this to the 0.11.7 milestone Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants