mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.6k stars 1.63k forks source link

Feature proposal: Add filter and filter out methods for Generated List #4943

Open jml1795 opened 5 years ago

jml1795 commented 5 years ago

Proposal: It is often useful to filter on a list to retrieve a subset, either by removing all items matching a regex (filter_out) or by keeping only those items that match a regex (filter). This ticket is to discuss the addition of two functions to meson, specifically to the GeneratedListHolder class (as returned by the generator.process() method). Potentially, this would look like:

class GeneratedListHolder(...):
    # ...
    def filter(self, args, kwargs):
        l = GeneratedListHolder()
        # filter from self.held_object.get_outputs()
        return l
    def filter_out(self, args, kwargs):
        l = GeneratedListHolder()
        # filter_out of self.held_object.get_outputs()
        return l

Use Case: When generating C++ source code, we often produce both a .hpp and .cpp file. The return of generator.process(...) is the complete set of code generated and there does not appear to be a mechanism to partition the resulting set into headers vs. cpp's, for example. This becomes particularly important when the generated headers need to be installed using install_headers(...). From what I can tell there is not a work around to installing generated headers when they are contained in a GeneratedListHolder instance holding more than just headers.

The same problem exists when any subset (e.g. private headers) are to be installed vs all headers. Full filtering (vs get_hpps() and get_cpps() methods for example) allow the user to decide exactly what they want installed with the addition of two functions.

I made a test case demonstrating the problem on my fork

I am willing to implement this, but want to make sure this is something that is acceptable to the maintainers first. The main questions I have are: 1) Is this feature acceptable? 2) Should the filter methods be methods in the generated list holder class or free functions? 3) Any suggestions on naming etc?

nioncode commented 5 years ago

I like the idea. Ideally, this should work for string lists as well.

jml1795 commented 5 years ago

@nioncode I thought that at first as well but couldn't [quickly] come up with a compelling use case (since we don't do file globbing). Do you have an example? It should be trivial to implement in the string-list case if there is actually a good case for it.

nioncode commented 5 years ago

I don't know one right now, but I'm sure I've seen this request pop up in various issues before.

phillipjohnston commented 5 years ago

Here's a use case, but for a list of files (could also be string objects, passed into file() later)

I have a build system which supports multiple architectures. There is a massive set of files which apply generally to all architectures. Each individual architecture has its own list of functions which need to be excluded.

Without filtering, I need to maintain a large number of "generic_files_but_not_for_XXX" lists, which is difficult to maintain and error prone.

An easier to maintain route would be to maintain the master list of generic files, and filter based on architecture/platform/machine to remove unsupported files.