[test] How to execute shell commands

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[test] How to execute shell commands

Boost - Dev mailing list
As an extension to my previous question:
Does the boost test framework provide an integrated mechanism to get the binary directory (the directory where the
currently running test executable is placed) and/or the source directory (where the jam-file resides that defined the
test)?

Best

Mike


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [test] How to execute shell commands

Boost - Dev mailing list
On 28.09.18 13:31, Mike Dev via Boost wrote:
> As an extension to my previous question:
> Does the boost test framework provide an integrated mechanism to get the binary directory (the directory where the
> currently running test executable is placed) and/or the source directory (where the jam-file resides that defined the
> test)?

Nope, but you can pass them on the command line. PR to boost.test welcome!

R.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

[test] How to execute shell commands

Boost - Dev mailing list
OK, what I got from the documentation is that I can do something like

notfile run_cmake_self_test : @echo ;
actions echo
{
    mkdir __build__
    cd __build__
    cmake ..
    cmake --build .
}

but
1) this will create __build__ in whatever directory b2 is called from and
   require the test cmake file to be in the parent directory of the current
2) mkdir will fail if the directory already esists and the flags necessary
   to circumvent that are different on powershell (--force) and bash (-p)

To fix 1) I'd need a way to get the current build directory (that is where
I want to create the __build__ directory) and the director of the current
jam file (which is where the CMakeLists.txt file resides).
That would result in something like this:

notfile run_cmake_self_test : @echo ;
actions echo
{
    mkdir $(b2-build-dir)/__build__
    cd $(b2-build-dir)/__build__
    cmake $(b2-source-dir)
    cmake --build .
}

For 2 it would be nice, if b2 had a platform agnostic way to create a directory
if it doesn't already exist so that I can just write

"<create $(b2-build-dir)/__build__ if neccesarry>"
 
notfile run_cmake_self_test : @echo ;
actions echo
{
    cd $(b2-build-dir)/__build__
    cmake $(b2-source-dir)
    cmake --build .
}

Could someone tell me how to achieve those two goals?

Best

Mike


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [test] How to execute shell commands

Boost - Dev mailing list
AMDG

On 10/17/2018 04:34 AM, Mike Dev via Boost wrote:

> OK, what I got from the documentation is that I can do something like
>
> notfile run_cmake_self_test : @echo ;
> actions echo
> {
>     mkdir __build__
>     cd __build__
>     cmake ..
>     cmake --build .
> }
>
> but
> 1) this will create __build__ in whatever directory b2 is called from and
>    require the test cmake file to be in the parent directory of the current
> 2) mkdir will fail if the directory already esists and the flags necessary
>    to circumvent that are different on powershell (--force) and bash (-p)
>

I would recommend using a make target (warning untested):

make CMakeCache.txt : CMakeLists.txt : @echo ;
always CMakeCache.txt ;

actions echo
{
    cmake -S "$(>:D)" -B $(<:D)
    cmake --build "$(<:D)"
}

Note 1: The directory will be created automatically.
Note 2: Avoiding cd simplifies the path handling a lot.
Note 3: This could probably be split into two separate actions.

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [test] How to execute shell commands

Boost - Dev mailing list
> -----Original Message-----
> From: Boost <[hidden email]> On Behalf Of Steven Watanabe via Boost
> Sent: Wednesday, October 17, 2018 7:19 PM
>
> I would recommend using a make target (warning untested):
>
> make CMakeCache.txt : CMakeLists.txt : @echo ;
> always CMakeCache.txt ;
>
> actions echo
> {
>     cmake -S "$(>:D)" -B $(<:D)
>     cmake --build "$(<:D)"
> }
>
> Note 1: The directory will be created automatically.
> Note 2: Avoiding cd simplifies the path handling a lot.
> Note 3: This could probably be split into two separate actions.

Thanks you very much, that got me mostly there.
In cmake versions older than 3.13 this apparently has to be

actions echo
{
    cmake -H"$(>:D)" -B$(<:D)
    cmake --build "$(<:D)"
}

(no space between B and the path and -H instead of -S).

Now I only need a way to properly hook this up, so it gets only re-run, if one of the cmake files change.

Best

Mike




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost