Skip to content

Commit

Permalink
Merge pull request #96 from bleskodev/next
Browse files Browse the repository at this point in the history
Fix for issue #73 ('qibuild make used with -J does not have correct exit code')
  • Loading branch information
Vincent Barbaresi committed May 31, 2016
2 parents c2d58be + b0696b8 commit ee4b377
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
35 changes: 26 additions & 9 deletions python/qibuild/parallel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,21 @@ def build(self, *args, **kwargs):
self.pending_jobs.remove(job)

# check if any worker failed
for worker in self._workers:
if not worker.result.ok:
all_ok = False
self.failed_project = worker.result.failed_project
break
all_ok = not self._has_any_worker_failed()

# end (all done or error)
# Wait for the last job to finish processing if needed.
# running_jobs.empty() will return true when the last job
# is 'get' from the queue, so the loop will end too early
# to get the status of the last job.

# all jobs except the last were ok?
if all_ok:
# wait for the end of the last job
self.running_jobs.join()
# check the last job's result
all_ok = not self._has_any_worker_failed()

# say to all workers to stop
for worker in self._workers:
worker.stop()
Expand Down Expand Up @@ -151,11 +159,17 @@ def _find_job_by_name(self, name):

return None

def _has_any_worker_failed(self):
for worker in self._workers:
if worker.result.failed_project:
self.failed_project = worker.result.failed_project
return True

return False


class BuildResult(object):
def __init__(self):
self.ok = True
self.failed_project = None


Expand All @@ -175,7 +189,7 @@ def stop(self):
self._should_stop = True

def run(self):
while not self._should_stop and self.result.ok:
while not self._should_stop and not self.result.failed_project:
job = None
try:
job = self.queue.get(True, 1);
Expand All @@ -187,9 +201,12 @@ def run(self):
try:
ui.info(ui.green, "Worker #%i starts working on " % (self.index + 1), ui.reset, ui.bold, job.project.name)
job.execute(*self.args, **self.kwargs)
self.queue.task_done()
except qibuild.build.BuildFailed as failed_build:
# not an exceptional condition -> no need to display backtrace
self.result.failed_project = failed_build.project
except Exception, e:
self.result.ok = False
self.result.failed_project = job.project
ui.error(ui.red,
*ui.message_for_exception(e, "Python exception during build"))

self.queue.task_done()
11 changes: 11 additions & 0 deletions python/qibuild/test/projects/with_compile_error/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Copyright (c) 2012-2016 Aldebaran Robotics. All rights reserved.
## Use of this source code is governed by a BSD-style license that can be
## found in the COPYING file.
cmake_minimum_required(VERSION 2.8)
project(with_compile_error)

find_package(qibuild)
qi_sanitize_compile_flags()

qi_create_bin(foo "main.cpp")

10 changes: 10 additions & 0 deletions python/qibuild/test/projects/with_compile_error/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2012-2016 Aldebaran Robotics. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the COPYING file.
*/

int main()
{
return toto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<project name="with_compile_error" />
14 changes: 14 additions & 0 deletions python/qibuild/test/test_parallel_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import qibuild.parallel_builder
import qibuild.build

import pytest

class FakeProject(object):
build_log = list()
Expand Down Expand Up @@ -29,3 +32,14 @@ def test_simple():
build_log = FakeProject.build_log
assert is_before(build_log, "a", "c")
assert is_before(build_log, "b", "c")

def test_running_build_with_compilation_errors_fails(qibuild_action):
# Running `qibuild make -J1` on a c++ project with compilation
# errors should fail

qibuild_action.add_test_project("with_compile_error")
qibuild_action("configure", "with_compile_error")

# pylint: disable-msg=E1101
with pytest.raises(qibuild.build.BuildFailed):
qibuild_action("make", "-J1", "with_compile_error")

0 comments on commit ee4b377

Please sign in to comment.