help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Question] How can i stop build immediately in build fail?


From: David Boyce
Subject: Re: [Question] How can i stop build immediately in build fail?
Date: Fri, 11 Jan 2013 17:57:28 -0800

It may be a reasonable feature request but it also may not be that
hard to implement with existing functionality. Here's one approach:

% cat makefile
SHELL := $(abspath shx)

.PHONY: job
job: job1 job2

.PHONY: job1
job1:
        sleep 3
        exit 1

.PHONY: job2
job2:
        while echo ok; do sleep 1; done

% cat shx
#!/usr/bin/env python

import optparse
import os
import subprocess
import sys

if '__main__' == __name__:
    parser = optparse.OptionParser()
    parser.add_option('-c', '--command', type='string',
                      help='Command to execute')
    (opts, args) = parser.parse_args(sys.argv[1:])

    rc = subprocess.call(opts.command, shell=True)
    if rc != 0:
        print 'stopping make!'
        os.killpg(0, 15)
    sys.exit(rc)

% make -j2
sleep 3
while echo ok; do sleep 1; done
ok
ok
ok
ok
exit 1
stopping make!
make: *** [job2] Terminated
make: *** [job1] Terminated
Terminated

I implemented the replacement shell in Python but it could use any
language. You just need to kill the process group once the first
recipe fails.

-David Boyce

On Fri, Jan 11, 2013 at 9:38 AM, Oleksandr Gavenko <address@hidden> wrote:
> On 2013-01-10, jungsoo.son wrote:
>
>> I always run 'make' with -j8. In this case, when there are a fail it is too
>> hard to check the fail.
>>
>> I want to kill the all sub-make process immediately when the error occurred.
>>
>> How can i stop build immediately in build fail?
>>
>
> I make such example:
>
> .PHONY: job
> job: job1 job2
>
> .PHONY: job1
> job1:
>         sleep 3
>         exit 1
>
> .PHONY: job2
> job2:
>         while echo ok; do sleep 1; done
>
> Ir you run like:
>
>   $ make -j2
>
> you get:
>
>   sleep 3
>   while echo ok; do sleep 1; done
>   ok
>   ok
>   ok
>   exit 1
>   make: *** [job1] Error 1
>   make: *** Waiting for unfinished jobs....
>   ok
>   ok
>   ...
>
> Seems to be reasonable have an option to kill jobs after some timeout if one
> job fail (or make receive signal) and enabling .DELETE_ON_ERROR in this
> case...
>
> --
> Best regards!
>
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make



reply via email to

[Prev in Thread] Current Thread [Next in Thread]