AnsweredAssumed Answered

How to assure pre-build action finishes before proceeding?

Question asked by Robert Poor on Sep 18, 2018
Latest reply on Sep 18, 2018 by Robert Poor

I'm using the Pre-build steps and Post-build-steps feature of KDS 3.2. (Yes, I will switch to MCUXpresso as soon as I can figure out how to create a Bootloader Configuration Area in MCUXpresso.)

 

I have observed that the build process proceeds asynchronously: it doesn't wait for the pre-build script to complete before moving on.  In my case, that causes an error, since the pre-build step creates a file that is required by other parts of the build.

 

Question: is there a way to make the pre-build step synchronous, that is, cause the build process to wait until the pre-build step completes?

 

To demonstrate the problem, here are two simple scripts, pre-build.sh and post-build.sh.  pre-build creates a file, post-build prints out its size.  Note that pre-build.sh imposes an artificial ten second delay to expose the problem.

 

file: pre-build.sh

#/bin/sh
/bin/echo === pre start ===
rm -f woof.txt
sleep 10
/bin/echo woof > woof.txt
/bin/echo -n pre `date "+%H:%M:%S"` " "
ls -l woof.txt
/bin/echo === pre end ===

file: post-build.sh

#/bin/sh
/bin/echo === post start ===
/bin/echo -n post `date "+%H:%M:%S"` " "
ls -l woof.txt
/bin/echo === post end ===

The result of running:

**** Incremental Build of configuration Debug for project myproj ****
make -j7 pre-build main-build
./pre-script.sh
Building file: ../source/probe.c
=== pre start ===
Invoking: Cross ARM C Compiler
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -O0 ...
Finished building: ../source/probe.c

Building target: myproj.elf
Invoking: Cross ARM C++ Linker
arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -O0 ...
Finished building target: myproj.elf

make --no-print-directory post-build
./post-script.sh
=== post start ===
ls: woof.txt: No such file or directory
post 18:16:45 === post end ===

Invoking: Cross ARM GNU Create Flash Image
arm-none-eabi-objcopy -O srec "myproj.elf" "myproj.srec"
Invoking: Cross ARM GNU Print Size
arm-none-eabi-size --format=berkeley "myproj.elf"
text data bss dec hex filename
35124 1516 3216 39856 9bb0 myproj.elf
Finished building: myproj.siz
Finished building: myproj.srec

pre 18:16:55 -rw-r--r-- 1 r staff 5 Sep 18 18:16 woof.txt
=== pre end ===

18:16:55 Build Finished (took 10s.162ms)

Note that pre-build created the file long after post-build (unsuccessfully) tried to access it.

Outcomes