Closed mrquincle closed 3 years ago
Tried suggestion 1 and 2, both show the same behaviour.
I get the same behaviour if i run ./log-client.py | grep ""
. So maybe it has nothing to do with cmake.
In that case you pipe it into grep. This might do something similar indeed to cmake. You can check with strace. I think grep uses by default block buffering while you want it to do line buffering. For grep you can use the flag --line-buffered
for this.
Then we also have python itself, if might also detect if it is actually sending output to tty vs another process. In that case you'll have to use something like fflush
or indicate in a different way that you don't want to buffer: https://stackoverflow.com/questions/107705/disable-output-buffering
That all being said, I think my suggestion 3 will very likely just run in the same shell without pipe redirections. I would predict that that solution works. You can test it first by hardcoding the UART_DEVICE
value.
This solution uses cmake
scripts to do this.
COMMAND bash -c "cmake ${DEFAULT_TOOL_PARAM} ${UART_CONFIG_PARAM} -P ${DEFAULT_MODULES_PATH}/get_config.cmake 2>&1 | xargs -I uart ${WORKSPACE_DIR}/scripts/log-client.py -d uart"
Given that we are using python anyway for binary logging, we can just as well consider this a dependency. Then the above command cmake ${DEFAULT_TOOL_PARAM} ${UART_CONFIG_PARAM} -P ${DEFAULT_MODULES_PATH}/get_config.cmake
can be replaced by something like ${WORKSPACE_DIR}/scripts/get-config.py UART_DEVICE)
It is slightly cleaner perhaps, but not by much. The benefit of the current approach is that it just uses the cmake scripts again, just at runtime now.
As described by @vliedel when connecting with a phone and writing a value, the result is shown several seconds later if it is displayed through a process that is started through
EXECUTE_PROCESS
.Check for example the https://github.com/crownstone/bluenet/blob/master/source/conf/cmake/modules/uart_tool.cmake file.
It starts a script
log-client.py
:Note how it does not capture the result or output variables, these should be mapped to stdout. As you might or might not know, those commands
COMMAND
are executed concurrently as a pipeline, with the standard output of each process piped to the standard input of the next. A single standard error pipe is used for all processes. Here we have only a singleCOMMAND
so it should be immediately piped to stdout, however, there's apparently a buffer.For completeness, the above is called like this:
Suggestion 1
We might try to run it explicitly as a bash script, but I would be surprised if this would fix the delay. There's still some pipe buffer issues, but now with the shell involved, I guess. Worth a try though.
Suggestion 2
It might be the case that the older, deprecated
exec_program
command is doing something less fancy. Worth a try too.Suggestion 3
If this all isn't working, we will have to back to finding a way in which we can pass runtime variables directly into our COMMAND lines in our custom targets:
Something like this. Here we feed the COMMAND an argument by executing a script
get_config.sh
which outputs the value forUART_DEVICE
. Of course, this is not cross-platform, but tsja. It can be be also a python script of course. Anyway, this will allow us to set our variables at runtime as well and very likely it is running directly in the shell where make or ninja is called, not wrapped by cmake.