public static bool StartBuild(BuildKind kind)
{
if (!BuildStatus.currentBuild.HasValue)
{
lock(BuildStatus.Mutex)
{
BuildStatus.currentBuild = kind;
}
return true;
}
BuildKind currentBuildKind = BuildStatus.currentBuild.Value;
switch (currentBuildKind)
{
case BuildKind.Sync:
// Attempt to start a build during sync build indicate reentrancy
Debug.Fail("Message pumping during sync build");
return false;
case BuildKind.Async:
if (kind == BuildKind.Sync)
{
// if we need to do a sync build during async build, there is not much we can do:
// - the async build is user-invoked build
// - during that build UI thread is by design not blocked and messages are being pumped
// - therefore it is legitimate for other code to call Project System APIs and query for stuff
// In that case we just fail gracefully
return false;
}
else
{
// Somebody attempted to start a build while build is in progress, perhaps and Addin via
// the API. Inform them of an error in their ways.
throw new InvalidOperationException("Build is already in progress");
}
default:
Debug.Fail("Unreachable");
return false;
}
}