How to check makefile for dependencies?

Is there a way to check the absence of dependencies that arise when compiling a project with several tasks (-jN where N> 1)?

I often come across packages, mostly open source, where the build process works fine while I use -j1 or -jN, where N is a relatively low value, like 4 or 8, but if I used higher values, like 48, a little unusual, he begins to fail due to lack of dependencies.

I tried to create a bash script for myself, which, taking into account the goal, calculated all the dependencies and tried to explicitly build each of these dependencies with -j1, to verify that none of them contain dependencies on their own. It looks like it works with a small / medium package, but does not fit more importantly, for example, uClibc.

I am sharing my script here, as some people can understand what I mean by reading the code. I also hope that a more reliable solution exists and can be transferred back.

#!/bin/bash TARGETS=$* echo "TARGETS=$TARGETS" for target in $TARGETS do MAKE="make" RULE=`make -j1 -n -p | grep "^$target:"` if [ -z "$RULE" ]; then continue fi NEWTARGETS=${RULE#* } if [ -z "$NEWTARGETS" ]; then continue fi if [ "${NEWTARGETS}" = "${RULE}" ]; then # leaf target, we do not want to test. continue fi echo "RULE=$RULE" # echo "NEWTARGETS=$NEWTARGETS" $0 $NEWTARGETS if [ $? -ne 0 ]; then exit 1 fi echo "Testing target $target" make clean && make -j1 $target if [ $? -ne 0 ]; then echo "Make parallel will fail with target $target" exit 1 fi done 
+5
source share
1 answer

I don’t know any open source solutions, but this is exactly the problem that ElectricAccelerator , a high-performance GNU make implementation, was created for the solution. It will build in parallel and dynamically detect and fix missing dependencies, so that the output of the assembly will be the same as if it were executed sequentially. It can create an annotated build log that contains information about missing dependencies. For example, this simple makefile has an undeclared relationship between abc and def :

 all: abc def abc: echo PASS > abc def: cat abc 

Run this using emake instead of gmake and include --emake-annodetail=history and the resulting annotation file includes the following:

 <job id="Jf42015c0" thread="f4bfeb40" start="5" end="6" type="rule" name="def" file="Makefile" line="6" neededby="Jf42015f8"> <command line="7"> <argv>cat abc</argv> <output>cat abc </output> <output src="prog">PASS </output> </command> <depList> <dep writejob="Jf4201588" file="/tmp/foo/abc"/> </depList> <timing invoked="0.356803" completed="0.362634" node="chester-1"/> </job> 

In particular, the <depList> section shows that this Jf42015c0 job (in other words, def ) depends on the Jf4201588 job because the latter modified the /tmp/foo/abc file.

You can give it a try for free with the ElectricAccelerator Huddle .

(Disclaimer: I am the architect of ElectricAccelerator)

+1
source

Source: https://habr.com/ru/post/1203241/


All Articles