GHS: Update project layout to accommodate gbuild inconsistencies

-- Do not use reference projects, use build hierarchy instead.
   gbuild has three parallel levels:
   * low -- Parallelizes compiling source files within a single project (.gpj)
     file when safe to do so.
   * medium -- Parallelizes processing files within a single linked output when
     safe to do so.
   * high [default] -- Parallelizes processing files whenever safe to do so,
     including linking task.

   Testing showed that for some combinations of gbuild / MULTI there are issues
   with building a project that uses references to target project files along with
   using {nobuild} option.

   Sometimes the archiving of a library and linking of an executable were
   happening in parallel and the build would fail when linking because the
   archive wasn't complete.

   This behavior was also inconsistent when running the build from MULTI and
   from the command line with gbuild. In some cases MULTI did not parallelize
   archiving and linking, but gbuild performed these actions in parallel.

   The parallel build issue was not seen when using a build hierarchy where the
   project listed the project files normally instead of using a reference link.

   The other option was to add the -parallel_level=medium to the command line
   when using "cmake --build" but this wouldn't fix the issue if gbuild itself
   was used to and the user might not be aware of the extra option used by cmake.
This commit is contained in:
Fred Baksik 2019-04-08 09:55:35 -04:00
parent 5d2e1404bd
commit 83c47ef5b8
4 changed files with 35 additions and 135 deletions

@ -143,8 +143,6 @@ void cmGhsMultiTargetGenerator::GenerateTarget()
}
this->WriteSources(fout);
fout.Close();
this->WriteReferenceFile(fproj);
}
cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator()
@ -735,27 +733,6 @@ void cmGhsMultiTargetGenerator::WriteObjectLangOverride(
}
}
void cmGhsMultiTargetGenerator::WriteReferenceFile(std::string fproj)
{
// Open the target ref file in copy-if-different mode.
std::string fname = this->LocalGenerator->GetCurrentBinaryDirectory();
fname += "/";
fname += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
fname += "/";
fname += this->Name + "_REF" + cmGlobalGhsMultiGenerator::FILE_EXTENSION;
cmGeneratedFileStream fref(fname);
fref.SetCopyIfDifferent(true);
this->GetGlobalGenerator()->WriteFileHeader(fref);
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fref);
fref << " :reference=CMakeFiles/${PROJ_NAME}.project.gpj;" << fproj
<< std::endl;
fref.Close();
// Store location of the reference file
this->GeneratorTarget->Target->SetProperty("GHS_REFERENCE_PROJECT",
fname.c_str());
}
bool cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()
{
const char* p = this->GeneratorTarget->GetProperty("ghs_integrity_app");

@ -66,7 +66,6 @@ private:
void WriteSourceProperty(std::ostream& fout, const cmSourceFile* sf,
std::string const& propName,
std::string const& propFlag);
void WriteReferenceFile(std::string fproj);
static void WriteObjectLangOverride(std::ostream& fout,
const cmSourceFile* sourceFile);

@ -352,66 +352,24 @@ void cmGlobalGhsMultiGenerator::WriteTopLevelProject(std::ostream& fout,
}
fout << "\"" << this->OsDir << "\"" << std::endl;
}
this->WriteSubProjects(fout, root);
}
void cmGlobalGhsMultiGenerator::WriteSubProjects(std::ostream& fout,
cmLocalGenerator* root)
std::string& all_target)
{
fout << "CMakeFiles/" << root->GetProjectName() << this->GetAllTargetName()
<< "_REF" << FILE_EXTENSION << " [Reference]" << std::endl;
fout << "{nobuild} CMakeFiles/" << root->GetProjectName() << ".target"
<< FILE_EXTENSION << " [Project]" << std::endl;
fout << "{nobuild} CMakeFiles/" << root->GetProjectName() << ".project"
<< FILE_EXTENSION << " [Project]" << std::endl;
}
void cmGlobalGhsMultiGenerator::WriteProjectRefLine(
std::ostream& fout, cmGeneratorTarget const* target, cmLocalGenerator* root,
std::string& rootBinaryDir)
{
const char* projRef = target->GetProperty("GHS_REFERENCE_PROJECT");
if (projRef) {
std::string projFile = projRef;
projFile = root->MaybeConvertToRelativePath(rootBinaryDir, projFile);
fout << projFile << " [Reference]\n";
} else {
/* Should never happen */
std::string message = "The project file reference for target [" +
target->GetName() + "] is missing.\n";
cmSystemTools::Error(message);
fout << "{comment} " << target->GetName() << " [missing reference file]\n";
}
}
void cmGlobalGhsMultiGenerator::WriteProjects(cmLocalGenerator* root)
{
std::string fname = root->GetCurrentBinaryDirectory();
fname += "/CMakeFiles/";
fname += root->GetProjectName();
fname += ".project";
fname += FILE_EXTENSION;
cmGeneratedFileStream pf(fname);
pf.SetCopyIfDifferent(true);
this->WriteFileHeader(pf);
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, pf);
std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
rootBinaryDir += "/CMakeFiles";
fout << "CMakeFiles/" << all_target << " [Project]" << std::endl;
// All known targets
for (cmGeneratorTarget const* target : this->ProjectTargets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::MODULE_LIBRARY ||
target->GetType() == cmStateEnums::SHARED_LIBRARY ||
(target->GetType() == cmStateEnums::GLOBAL_TARGET &&
target->GetName() != this->GetInstallTargetName())) {
target->GetName() != GetInstallTargetName())) {
continue;
}
this->WriteProjectLine(pf, target, root, rootBinaryDir);
fout << "CMakeFiles/" << target->GetName() + ".tgt" + FILE_EXTENSION
<< " [Project]" << std::endl;
}
pf.Close();
}
void cmGlobalGhsMultiGenerator::WriteProjectLine(
@ -446,25 +404,10 @@ void cmGlobalGhsMultiGenerator::WriteProjectLine(
void cmGlobalGhsMultiGenerator::WriteTargets(cmLocalGenerator* root)
{
std::string fname = root->GetCurrentBinaryDirectory();
fname += "/CMakeFiles/";
fname += root->GetProjectName();
fname += ".target";
fname += FILE_EXTENSION;
cmGeneratedFileStream tf(fname);
tf.SetCopyIfDifferent(true);
WriteFileHeader(tf);
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, tf);
std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
rootBinaryDir += "/CMakeFiles";
// ALL target
tf << root->GetProjectName() + "." + this->GetAllTargetName() +
FILE_EXTENSION
<< " [Project]" << std::endl;
// All other targets
// All known targets
for (cmGeneratorTarget const* target : this->ProjectTargets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::MODULE_LIBRARY ||
@ -475,8 +418,8 @@ void cmGlobalGhsMultiGenerator::WriteTargets(cmLocalGenerator* root)
}
// create target build file
fname = root->GetCurrentBinaryDirectory() + "/CMakeFiles/" +
target->GetName() + FILE_EXTENSION;
std::string name = target->GetName() + ".tgt" + FILE_EXTENSION;
std::string fname = rootBinaryDir + "/" + name;
cmGeneratedFileStream fbld(fname);
fbld.SetCopyIfDifferent(true);
this->WriteFileHeader(fbld);
@ -488,24 +431,24 @@ void cmGlobalGhsMultiGenerator::WriteTargets(cmLocalGenerator* root)
cmSystemTools::Error(message);
} else {
for (auto& tgt : build) {
this->WriteProjectRefLine(fbld, tgt, root, rootBinaryDir);
WriteProjectLine(fbld, tgt, root, rootBinaryDir);
}
}
fbld.Close();
tf << target->GetName() << FILE_EXTENSION << " [Project]" << std::endl;
}
tf.Close();
}
void cmGlobalGhsMultiGenerator::WriteAllTarget(
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators,
std::string& all_target)
{
this->ProjectTargets.clear();
// create target build file
std::string fname = root->GetCurrentBinaryDirectory() + "/CMakeFiles/" +
root->GetProjectName() + "." + this->GetAllTargetName() + FILE_EXTENSION;
all_target = root->GetProjectName() + "." + this->GetAllTargetName() +
".tgt" + FILE_EXTENSION;
std::string fname =
root->GetCurrentBinaryDirectory() + "/CMakeFiles/" + all_target;
cmGeneratedFileStream fbld(fname);
fbld.SetCopyIfDifferent(true);
this->WriteFileHeader(fbld);
@ -513,12 +456,6 @@ void cmGlobalGhsMultiGenerator::WriteAllTarget(
// Collect all targets under this root generator and the transitive
// closure of their dependencies.
/* NOTE: GetTargetSets() returns the set in a different order
* every time it is run even though nothing has changed. To avoid
* creating a different build order sort the targets by name so that
* the inputs of calculating build order are the same (otherwise the
* build order will be different every time).
*/
TargetDependSet projectTargets;
TargetDependSet originalTargets;
this->GetTargetSets(projectTargets, originalTargets, root, generators);
@ -551,22 +488,10 @@ void cmGlobalGhsMultiGenerator::WriteAllTarget(
target->GetType() == cmStateEnums::SHARED_LIBRARY) {
continue;
}
this->WriteProjectRefLine(fbld, target, root, rootBinaryDir);
this->WriteProjectLine(fbld, target, root, rootBinaryDir);
}
}
fbld.Close();
// Open the target ref file in copy-if-different mode.
std::string frn = root->GetCurrentBinaryDirectory() + "/CMakeFiles/" +
root->GetProjectName() + this->GetAllTargetName() + "_REF" +
FILE_EXTENSION;
cmGeneratedFileStream fref(frn);
fref.SetCopyIfDifferent(true);
this->WriteFileHeader(fref);
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fref);
fref << " :reference=CMakeFiles/${PROJ_NAME}.target.gpj;" << fname
<< std::endl;
fref.Close();
}
void cmGlobalGhsMultiGenerator::Generate()
@ -604,6 +529,7 @@ void cmGlobalGhsMultiGenerator::OutputTopLevelProject(
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
{
std::string fname;
std::string all_target;
if (generators.empty()) {
return;
@ -622,11 +548,12 @@ void cmGlobalGhsMultiGenerator::OutputTopLevelProject(
cmGeneratedFileStream top(fname);
top.SetCopyIfDifferent(true);
this->WriteTopLevelProject(top, root);
top.Close();
this->WriteAllTarget(root, generators);
this->WriteAllTarget(root, generators, all_target);
this->WriteTargets(root);
this->WriteProjects(root);
this->WriteSubProjects(top, all_target);
top.Close();
}
std::vector<cmGlobalGenerator::GeneratedMakeCommand>
@ -655,10 +582,12 @@ cmGlobalGhsMultiGenerator::GenerateBuildCommand(
/* determine which top-project file to use */
std::string proj = projectName + ".top" + FILE_EXTENSION;
std::string target = projectName + ".target" + FILE_EXTENSION;
std::vector<std::string> files;
cmSystemTools::Glob(projectDir, ".*\\.top\\.gpj", files);
if (!files.empty()) {
/* if multiple top-projects are found in build directory
* then prefer projectName top-project.
*/
auto p = std::find(files.begin(), files.end(), proj);
if (p == files.end()) {
proj = files.at(0);
@ -671,21 +600,18 @@ cmGlobalGhsMultiGenerator::GenerateBuildCommand(
targetNames.end()) {
makeCommand.Add("-clean");
} else {
bool print_within = true;
for (const auto& tname : targetNames) {
if (!tname.empty()) {
if (print_within) {
makeCommand.Add("-within", target);
print_within = false;
}
if (tname.compare(tname.size() - 4, 4, ".gpj") == 0) {
makeCommand.Add(tname);
} else {
makeCommand.Add(tname + ".gpj");
}
makeCommand.Add(tname + ".tgt.gpj");
}
}
}
} else {
/* transform name to default build */;
std::string all = proj;
all.replace(all.end() - 7, all.end(),
std::string(this->GetAllTargetName()) + ".tgt.gpj");
makeCommand.Add(all);
}
return { makeCommand };
}

@ -98,17 +98,15 @@ private:
void WriteTopLevelProject(std::ostream& fout, cmLocalGenerator* root);
void WriteMacros(std::ostream& fout, cmLocalGenerator* root);
void WriteHighLevelDirectives(cmLocalGenerator* root, std::ostream& fout);
void WriteSubProjects(std::ostream& fout, cmLocalGenerator* root);
void WriteSubProjects(std::ostream& fout, std::string& all_target);
void WriteTargets(cmLocalGenerator* root);
void WriteProjects(cmLocalGenerator* root);
void WriteProjectLine(std::ostream& fout, cmGeneratorTarget const* target,
cmLocalGenerator* root, std::string& rootBinaryDir);
void WriteProjectRefLine(std::ostream& fout, cmGeneratorTarget const* target,
cmLocalGenerator* root, std::string& rootBinaryDir);
void WriteCustomRuleBOD(std::ostream& fout);
void WriteCustomTargetBOD(std::ostream& fout);
void WriteAllTarget(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
std::vector<cmLocalGenerator*>& generators,
std::string& all_target);
std::string TrimQuotes(std::string const& str);