Skip to content

Commit

Permalink
Added support for "no-parallel-build" option
Browse files Browse the repository at this point in the history
This commit adds support for forcing a buildfile to be built in
non-parallel by introducing a new options list and a special toggle
option named "no-parallel-build".

To force a buildfile to be built in non-parallel, simply add to
buildfile:

options=no-parallel-build

This is reported to be useful for eg. kernel module builds which must
avoid to be built at the same time because they operate in the same
kernel build workspace.

In the future, more options might be supported in the options list.
  • Loading branch information
lundmar committed Aug 21, 2014
1 parent 3beb650 commit 0340e64
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
7 changes: 7 additions & 0 deletions man/buildgear-buildfile.man5
Expand Up @@ -48,6 +48,13 @@ List of sources needed in the build procedure. Sources can be remote (protocols
List of Buildgear builds that is needed by the build. These builds will be added to the sysroot before building of the selected build is started. Both compile-time and run-time dependencies can be specified. If the build dependency is in the native branch, the name of the build must be given as \fInative/<build name>\fR.
.RE

.TP
.B options
.RS
List of special options. Currently only the \fBno-parallel-build\fR option is supported which forces a particular build to be built in non-parallel.
.RE


.SH FUNCTIONS

.TP
Expand Down
12 changes: 10 additions & 2 deletions src/buildfile.cc
Expand Up @@ -48,6 +48,7 @@ CBuildFile::CBuildFile(string filename)
CBuildFile::description = "";
CBuildFile::url = "";
CBuildFile::license = "";
CBuildFile::options.no_parallel_build = false;
}

string CBuildFile::GetLocation()
Expand Down Expand Up @@ -116,6 +117,7 @@ void CBuildFile::Parse(void)
; echo release=$release \
; echo source=${source[@]} \
; echo depends=${depends[@]} \
; echo options=${options[@]} \
; typeset -F build &> /dev/null && echo build_function=yes || echo build_function=no \
; typeset -F check &> /dev/null && echo check_function=yes || echo check_function=no'";

Expand Down Expand Up @@ -206,10 +208,16 @@ void CBuildFile::Parse(void)
source = value;
if (key == KEY_DEPENDS)
depends = value;
if (key == "build_function")
if (key == KEY_BUILD_FUNCTION)
build_function = value;
if (key == "check_function")
if (key == KEY_CHECK_FUNCTION)
check_function = value;
if (key == KEY_OPTIONS_)
{
// Parse options field
if (value.find("no-parallel-build") < value.length())
options.no_parallel_build = true;
}
}
pclose(fp);

Expand Down
37 changes: 31 additions & 6 deletions src/buildmanager.cc
Expand Up @@ -501,7 +501,7 @@ void CBuildManager::Build(list<CBuildFile*> *buildfiles)
if (sem_init(&build_semaphore, 0,
stoi(Config.bg_config[CONFIG_KEY_PARALLEL_BUILDS])) == -1)
{
cerr << "Error: Semaphore init failed" << endl;
cerr << "Error: Build semaphore init failed" << endl;
exit(EXIT_FAILURE);
}

Expand All @@ -514,14 +514,27 @@ void CBuildManager::Build(list<CBuildFile*> *buildfiles)
while (it != buildfiles->end())
{
int thread_count=0;
list<CBuildFile*> no_parallel_buildfiles;
list<CBuildFile*>::iterator itr;

// Start building threads of same depth in parallel
while ( ((*it)->depth == current_depth) && (it != buildfiles->end())
&& !BuildManager.build_error)
{
// Start building threads of same depth in parallel
CBuildThread *bt = new CBuildThread(*it);
builder.push_back(bt);
builder[thread_count]->Start();
thread_count++;
// Only build buildfiles in parallel which are not marked with the
// "no-parallel-build" option
if ((*it)->options.no_parallel_build == false)
{
CBuildThread *bt = new CBuildThread(*it);
builder.push_back(bt);
builder[thread_count]->Start();
thread_count++;
}
else
{
// Add for later sequential build deployment
no_parallel_buildfiles.push_back(*it);
}
it++;
}

Expand All @@ -535,6 +548,18 @@ void CBuildManager::Build(list<CBuildFile*> *buildfiles)
builder.pop_back();
}

// Build "no-parallel-build" marked builds sequentially
for (itr = no_parallel_buildfiles.begin(); itr != no_parallel_buildfiles.end(); itr++)
{
CBuildThread *bt = new CBuildThread(*itr);
(bt)->Start();
(bt)->Join();
if (BuildManager.build_error)
break;
}

no_parallel_buildfiles.clear();

if (BuildManager.build_error)
break;

Expand Down
6 changes: 6 additions & 0 deletions src/include/buildgear/buildfile.h
Expand Up @@ -44,6 +44,12 @@ class CBuildFile : public CUtility
string release;
string source;
string depends;

struct
{
bool no_parallel_build;
} options;

string missing_depends;
string type;
string build_function;
Expand Down
3 changes: 3 additions & 0 deletions src/include/buildgear/config.h
Expand Up @@ -130,6 +130,9 @@ class CConfig : public CUtility
#define KEY_RELEASE "release"
#define KEY_SOURCE "source"
#define KEY_DEPENDS "depends"
#define KEY_OPTIONS_ "options"
#define KEY_BUILD_FUNCTION "build_function"
#define KEY_CHECK_FUNCTION "check_function"
#define KEY_CONFIG_RETURN "config_return"
#define KEY_BUILD_RETURN "build_return"

Expand Down

0 comments on commit 0340e64

Please sign in to comment.