[build2] Listing available targets

Boris Kolpackov boris at codesynthesis.com
Thu Jul 4 06:44:36 UTC 2019

Per Edin <per.edin at sequence-point.se> writes:

> Is it possible to list available targets in the current directory
> similar to what is usually output when you run "make help"?

Not at the moment. But we could do this fairly easily, I think
(but see below).

> I sometimes find it difficult to figure out what to type to just
> compile a single .cxx-file.

This might be problematic. If you have something like this in your

exe{foo}: cxx{foo}

There is actually no obje{foo} target until a rule for building
exe{foo} is matched which synthesizes the 'obje{foo}: cxx{foo}'

To have obje{foo} listed by such a hypothetical [meta-]operation,
you would have to spell your dependencies explicitly, which would
be a pain:

exe{foo}: obje{foo}
obje{foo}: cxx{foo}

We could do the rule match before listing the targets but of the
top of my head I can see a couple of issues with this approach:

1. If we match the default target, then you may not see targets
   that are not built by default, for example:

   ./: exe{foo}: cxx{foo}
   lib{bar}: cxx{bar}

   This will give you the following list (notice missing obje{bar}):


   I don't think matching a rule for every declared target would
   be a good idea (see #2, but there are other issues).

2. This can be potentially slow since during rule matching we
   extract dependency information which involves preprocessing,
   auto-generated header generation, etc.

BTW, this approach (i.e, matching a rule and then printing the
targets) feels pretty similar to the dry-run mode (--dry-run|-n).
Maybe if there were a way to display output targets, it would be
close enough?

> Also, trying to build a single unit test like `b exe{foo.test}` fails
> with "unknown target", although `b` does print that target when
> building everything ("ld exe{foo.test}"). Being able to list targets
> would probably fix this problem too, unless it's a bug.

I am pretty sure it's this bug:


More information about the users mailing list