[build2] What does these means? exe{*} lib{*}

Klaim - Joël Lamotte mjklaim at gmail.com
Mon Sep 17 22:35:08 UTC 2018


I've been highly confused recently because of a variety of weird build
errors and I realized only a few hours ago that I was using the
globing syntax in non-file targets like lib{*} or exe{*} and thought
it should have worked because it felt natural after reading the doc.
I didn't remember that they were not allowed... or more exactly the
doc didn't specify that they were not supposed to work at all with
other targets, just that it's supposed to work with file targets.
There was no errors specific to the target names from build2 on
build-time but I did get super weird behaviours (see below for
examples).
I am therefore surprised to not get an explicit error report when doing lib{*}.

Note that my thinking when using these was that I was trying to get
all the libs or exes that have been declared in the current directory
scope, whatever their names.
It might be wrong (looks like it is) but when defining libraries or
exes based on files (as in the examples below), it seemed useful to
get most libraries except one or two and apply something to them.

After re-checking the documentation I realized that I might have been
mislead by this in the new manual doc:
""""
The next couple of lines use target/pattern-specific variables to
treat all unit test executables as tests that should not be installed:

exe{*.test}: test = true
exe{*.test}: install = false
""""
This looks a lot like what I was naturally thinking, and it seems to
work while all my other attempts does not seem to work  (see examples
below).


Questions:

 0. Is this all a bug with name globing of non-file targets?
 1. Would it make sense to make globing syntax an error for targets
that are not file targets?
 2.a. If no, then what is the intended meaning of lib{*} and exe{*}?
 2.b. The current behavior of lib{*} seems to be that it is globing
all files in the source directory (see output below). Is that what was
intended?

A Joël Lamotte

--------------------------------
For example to generate GTest's set of sample programs, I do something
(working) similar to:

    # Each sample starts with a *_unittest.cc file.
      for sample: cxx{*_unittest}
      {
        sample_name = $name($sample)
        exe{$sample_name}: {cxx}{$sample_prefix}

        ./ : exe{$sample_name} # Make sure this sample will be built.
      }
      exe{sample1_unittest}: ../liba{gtest_main}
      exe{sample2_unittest}: ../liba{gtest_main}
      exe{sample3_unittest}: ../liba{gtest_main}
      exe{sample4_unittest}: ../liba{gtest_main}
      exe{sample5_unittest}: ../liba{gtest_main}
      exe{sample6_unittest}: ../liba{gtest_main}
      exe{sample7_unittest}: ../liba{gtest_main}
      exe{sample8_unittest}: ../liba{gtest_main}
      exe{sample9_unittest sample10_unittest}    : ../lib{gtest}

This is because I need the 8 first  samples to link with gtest_main,
but 2 last samples must link with gtest only.
Compare to my initial attempt (wrong, or incorrect behavior):

    ./ : exe{*} # Make sure all samples will be built.

    # Each sample starts with a *_unittest.cc file.
      for sample: cxx{*_unittest}
      {
        sample_name = $name($sample)
        exe{$sample_name}: {cxx}{$sample_prefix}
      }
      exe{* -sample9_unittest sample10_unittest}: ../liba{gtest_main}
      exe{sample9_unittest sample10_unittest}    : ../lib{gtest}

Which is obviously shorter.
This resulted in
- no executable even built until I replaced the first line by
explicitely doing it in the loop per target
- linking errors because the gtest_main was never linked to the
libraries which names were globed.
(the linking errors have been fixed once these issues AND
bin.whole=true have been set, thanks to Boris)

Note that these bits of code are in a sub scope and in a
`if`statement, so the globing, in my mind, would have been only for
targets generated from the loop.
The following line didn't work either (noting linking with
gtest_main), even if it looks a lot like the test example from the
documentation:

    exe{sample* -sample9_unittest -sample10_unittest}:
../liba{gtest_main} # DO NOT WORK

There might be other ways to do the same that I didn't realize, feel
free to fill me in.

-------------------------------------------
Example using a fresh project using:
>bdep new globfail
>cd globfail
>ls

Output:
PS E:\Projects\build2-libs\globfail\globfail> ls
    Directory: E:\Projects\build2-libs\globfail\globfail
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2018-09-17     23:22             79 .gitignore
-a----       2018-09-17     23:40            407 buildfile
-a----       2018-09-17     23:22            226 globfail.cxx
-a----       2018-09-17     23:25            226 source2.cxx
-a----       2018-09-17     23:25            226 source3.cxx
-a----       2018-09-17     23:25            226 source4.cxx
-a----       2018-09-17     23:22            105 testscript

buildfile contains:
#######
./ : exe{*} lib{*} # Build everything!

for source: cxx{*}
{
    source_name = $name($source)
    exe{$source_name} : cxx{globfail}
    info "EXE : " $name(exe{$source_name}) " from : $source_name"
}

for source: cxx{*}
{
    source_name = $name($source)
    lib{$source_name} : cxx{globfail}
    info "LIB : " $name(lib{$source_name}) " from : $source_name"
}


cxx.poptions =+ "-I$out_root" "-I$src_root"
#######
Output of:
> b

PS E:\Projects\build2-libs\globfail\globfail> b
buildfile:7:5: info: EXE :  globfail  from : globfail
buildfile:7:5: info: EXE :  source2  from : source2
buildfile:7:5: info: EXE :  source3  from : source3
buildfile:7:5: info: EXE :  source4  from : source4
buildfile:14:5: info: LIB :  globfail  from : globfail
buildfile:14:5: info: LIB :  source2  from : source2
buildfile:14:5: info: LIB :  source3  from : source3
buildfile:14:5: info: LIB :  source4  from : source4
error: no rule to update
..\..\build-failexeglob\globfail\globfail\liba{buildfile}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{buildfile}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\libs{buildfile}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{buildfile}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\liba{globfail.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{globfail.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\libs{testscript}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{testscript}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\liba{source2.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{source2.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\libs{source2.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{source2.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\liba{source3.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{source3.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\libs{source4.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{source4.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\libs{globfail.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{globfail.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\libs{source3.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{source3.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\liba{testscript}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{testscript}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
error: no rule to update
..\..\build-failexeglob\globfail\globfail\liba{source4.cxx}
  info: re-run with --verbose 4 for more information
  info: while applying rule bin.lib to update
..\..\build-failexeglob\globfail\globfail\lib{source4.cxx}
  info: while applying rule alias to update
..\..\build-failexeglob\globfail\dir{globfail\}
info: failed to update ..\..\build-failexeglob\globfail\dir{globfail\}


PS E:\Projects\build2-libs\globfail\globfail> b --version
build2 0.9.0-a.0.1221ea0c71ed
libbutl 0.9.0-a.0.b7f00311c5db
host x86_64-microsoft-win32-msvc14.1
Copyright (c) 2014-2018 Code Synthesis Ltd
This is free software released under the MIT license.



More information about the users mailing list