From b2a72ec72d609547d2278701a56237822c0dcc92 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Sat, 5 Jan 2019 11:01:22 -0500 Subject: GHS: Cleanup unused file handling functions and file output updates -- File handling cleanup -- Rename some functions to clarify what they do -- Update to source file path conversion; only perform conversion when using windows --- Source/cmGhsMultiGpj.cxx | 5 +- Source/cmGhsMultiGpj.h | 4 +- Source/cmGhsMultiTargetGenerator.cxx | 153 ++++------------------------------ Source/cmGhsMultiTargetGenerator.h | 40 +-------- Source/cmGlobalGhsMultiGenerator.cxx | 156 +++-------------------------------- Source/cmGlobalGhsMultiGenerator.h | 42 +--------- 6 files changed, 35 insertions(+), 365 deletions(-) diff --git a/Source/cmGhsMultiGpj.cxx b/Source/cmGhsMultiGpj.cxx index c0f37ba..c1f0742 100644 --- a/Source/cmGhsMultiGpj.cxx +++ b/Source/cmGhsMultiGpj.cxx @@ -29,10 +29,9 @@ const char* GhsMultiGpj::GetGpjTag(Types const gpjType) return tag; } -void GhsMultiGpj::WriteGpjTag(Types const gpjType, - cmGeneratedFileStream* const filestream) +void GhsMultiGpj::WriteGpjTag(Types const gpjType, std::ostream& fout) { char const* tag; tag = GhsMultiGpj::GetGpjTag(gpjType); - *filestream << tag << std::endl; + fout << tag << std::endl; } diff --git a/Source/cmGhsMultiGpj.h b/Source/cmGhsMultiGpj.h index 014f6b6..6d59225 100644 --- a/Source/cmGhsMultiGpj.h +++ b/Source/cmGhsMultiGpj.h @@ -4,6 +4,7 @@ #define cmGhsMultiGpj_h #include "cmConfigure.h" // IWYU pragma: keep +#include class cmGeneratedFileStream; @@ -20,8 +21,7 @@ public: SUBPROJECT }; - static void WriteGpjTag(Types const gpjType, - cmGeneratedFileStream* filestream); + static void WriteGpjTag(Types const gpjType, std::ostream& fout); static const char* GetGpjTag(Types const gpjType); }; diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index a58e59a..305e494 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -24,19 +24,6 @@ cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target) , DynamicDownload(false) , Name(target->GetName()) { - this->RelBuildFilePath = this->GetRelBuildFilePath(target); - - this->RelOutputFileName = this->RelBuildFilePath + target->GetName() + ".a"; - - this->RelBuildFileName = this->RelBuildFilePath; - this->RelBuildFileName += this->GetBuildFileName(target); - - std::string absPathToRoot = this->GetAbsPathToRoot(target); - absPathToRoot = this->AddSlashIfNeededToPath(absPathToRoot); - this->AbsBuildFilePath = absPathToRoot + this->RelBuildFilePath; - this->AbsBuildFileName = absPathToRoot + this->RelBuildFileName; - this->AbsOutputFileName = absPathToRoot + this->RelOutputFileName; - // Store the configuration name that is being used if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) { // Use the build type given by the user. @@ -49,64 +36,6 @@ cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target) cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator() { - cmDeleteAll(this->FolderBuildStreams); -} - -std::string cmGhsMultiTargetGenerator::GetRelBuildFilePath( - const cmGeneratorTarget* target) -{ - std::string output = target->GetEffectiveFolderName(); - cmSystemTools::ConvertToUnixSlashes(output); - if (!output.empty()) { - output += "/"; - } - output += target->GetName() + "/"; - return output; -} - -std::string cmGhsMultiTargetGenerator::GetAbsPathToRoot( - const cmGeneratorTarget* target) -{ - return target->GetLocalGenerator()->GetBinaryDirectory(); -} - -std::string cmGhsMultiTargetGenerator::GetAbsBuildFilePath( - const cmGeneratorTarget* target) -{ - std::string output; - output = cmGhsMultiTargetGenerator::GetAbsPathToRoot(target); - output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output); - output += cmGhsMultiTargetGenerator::GetRelBuildFilePath(target); - return output; -} - -std::string cmGhsMultiTargetGenerator::GetRelBuildFileName( - const cmGeneratorTarget* target) -{ - std::string output; - output = cmGhsMultiTargetGenerator::GetRelBuildFilePath(target); - output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output); - output += cmGhsMultiTargetGenerator::GetBuildFileName(target); - return output; -} - -std::string cmGhsMultiTargetGenerator::GetBuildFileName( - const cmGeneratorTarget* target) -{ - std::string output; - output = target->GetName(); - output += cmGlobalGhsMultiGenerator::FILE_EXTENSION; - return output; -} - -std::string cmGhsMultiTargetGenerator::AddSlashIfNeededToPath( - std::string const& input) -{ - std::string output(input); - if (!cmHasLiteralSuffix(output, "/")) { - output += "/"; - } - return output; } void cmGhsMultiTargetGenerator::Generate() @@ -190,7 +119,8 @@ void cmGhsMultiTargetGenerator::GenerateTarget() cmGeneratedFileStream fout(fname.c_str()); fout.SetCopyIfDifferent(true); - cmGlobalGhsMultiGenerator::OpenBuildFileStream(&fout); + this->GetGlobalGenerator()->WriteFileHeader(fout); + GhsMultiGpj::WriteGpjTag(this->TagType, fout); std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); if (0 == config.length()) { @@ -203,9 +133,6 @@ void cmGhsMultiTargetGenerator::GenerateTarget() if (this->DynamicDownload) { fout << "#component integrity_dynamic_download" << std::endl; } - GhsMultiGpj::WriteGpjTag(this->TagType, &fout); - cmGlobalGhsMultiGenerator::WriteDisclaimer(&fout); - bool const notKernel = this->IsNotKernel(config, language); this->WriteTargetSpecifics(fout, config, notKernel); this->SetCompilerFlags(config, language, notKernel); @@ -614,11 +541,10 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) f->SetCopyIfDifferent(true); gfiles.push_back(f); fout = f; - cmGlobalGhsMultiGenerator::OpenBuildFileStream(f); - *fout << "[Subproject]" << std::endl; - cmGlobalGhsMultiGenerator::WriteDisclaimer(f); + this->GetGlobalGenerator()->WriteFileHeader(*f); + GhsMultiGpj::WriteGpjTag(GhsMultiGpj::SUBPROJECT, *f); fout_proj << lpath << " "; - fout_proj << "[Subproject]" << std::endl; + GhsMultiGpj::WriteGpjTag(GhsMultiGpj::SUBPROJECT, fout_proj); } if (useProjectFile) { @@ -631,21 +557,17 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) /* output rule for each source file */ for (const cmSourceFile* si : groupFiles[sg]) { - std::string fullSourcePath(si->GetFullPath()); - if (si->GetExtension() == "int" || si->GetExtension() == "bsp") { - *fout << fullSourcePath << std::endl; - } else { - // WORKAROUND: GHS MULTI needs the path to use backslashes without - // quotes - // to open files in search as of version 6.1.6 - cmsys::SystemTools::ReplaceString(fullSourcePath, "/", "\\"); - *fout << fullSourcePath << std::endl; - } + // Convert filename to native system + // WORKAROUND: GHS MULTI 6.1.4 and 6.1.6 are known to need backslash on + // windows when opening some files from the search window. + std::string fname(si->GetFullPath()); + cmSystemTools::ConvertToOutputSlashes(fname); + *fout << fname << std::endl; if ("ld" != si->GetExtension() && "int" != si->GetExtension() && "bsp" != si->GetExtension()) { - this->WriteObjectLangOverride(fout, si); + this->WriteObjectLangOverride(*fout, si); if (objectNames.end() != objectNames.find(si)) { *fout << " -o \"" << objectNames.find(si)->second << "\"" << std::endl; @@ -660,65 +582,18 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) } void cmGhsMultiTargetGenerator::WriteObjectLangOverride( - std::ostream* fout, const cmSourceFile* sourceFile) + std::ostream& fout, const cmSourceFile* sourceFile) { const char* rawLangProp = sourceFile->GetProperty("LANGUAGE"); if (NULL != rawLangProp) { std::string sourceLangProp(rawLangProp); std::string extension(sourceFile->GetExtension()); if ("CXX" == sourceLangProp && ("c" == extension || "C" == extension)) { - *fout << " -dotciscxx" << std::endl; + fout << " -dotciscxx" << std::endl; } } } -std::string cmGhsMultiTargetGenerator::GetOutputDirectory( - const std::string& config) const -{ - std::string outputDir(AbsBuildFilePath); - - const char* runtimeOutputProp = - this->GeneratorTarget->GetProperty("RUNTIME_OUTPUT_DIRECTORY"); - if (NULL != runtimeOutputProp) { - outputDir = runtimeOutputProp; - } - - std::string configCapped(cmSystemTools::UpperCase(config)); - const char* runtimeOutputSProp = this->GeneratorTarget->GetProperty( - "RUNTIME_OUTPUT_DIRECTORY_" + configCapped); - if (NULL != runtimeOutputSProp) { - outputDir = runtimeOutputSProp; - } - cmSystemTools::ConvertToUnixSlashes(outputDir); - - if (!outputDir.empty()) { - outputDir += "/"; - } - - return outputDir; -} - -std::string cmGhsMultiTargetGenerator::GetOutputFilename( - const std::string& config) const -{ - std::string outputFilename(this->GeneratorTarget->GetName()); - - const char* outputNameProp = - this->GeneratorTarget->GetProperty("OUTPUT_NAME"); - if (NULL != outputNameProp) { - outputFilename = outputNameProp; - } - - std::string configCapped(cmSystemTools::UpperCase(config)); - const char* outputNameSProp = - this->GeneratorTarget->GetProperty(configCapped + "_OUTPUT_NAME"); - if (NULL != outputNameSProp) { - outputFilename = outputNameSProp; - } - - return outputFilename; -} - std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory( cmLocalGhsMultiGenerator const* localGhsMultiGenerator, cmGeneratorTarget* const generatorTarget, cmSourceFile* const sourceFile) diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h index df1c683..358e1f4 100644 --- a/Source/cmGhsMultiTargetGenerator.h +++ b/Source/cmGhsMultiTargetGenerator.h @@ -26,36 +26,10 @@ public: bool IncludeThisTarget(); std::vector GetSources() const; - const char* GetAbsBuildFilePath() const - { - return this->AbsBuildFilePath.c_str(); - } - const char* GetRelBuildFileName() const - { - return this->RelBuildFileName.c_str(); - } - const char* GetAbsBuildFileName() const - { - return this->AbsBuildFileName.c_str(); - } - const char* GetAbsOutputFileName() const - { - return this->AbsOutputFileName.c_str(); - } - - static std::string GetRelBuildFilePath(const cmGeneratorTarget* target); - static std::string GetAbsPathToRoot(const cmGeneratorTarget* target); - static std::string GetAbsBuildFilePath(const cmGeneratorTarget* target); - static std::string GetRelBuildFileName(const cmGeneratorTarget* target); - static std::string GetBuildFileName(const cmGeneratorTarget* target); - static std::string AddSlashIfNeededToPath(std::string const& input); private: cmGlobalGhsMultiGenerator* GetGlobalGenerator() const; - cmGeneratedFileStream* GetFolderBuildStreams() - { - return this->FolderBuildStreams[""]; - }; + void GenerateTarget(); bool IsTargetGroup() const { return this->TargetGroup; } @@ -84,10 +58,9 @@ private: std::vector* objectSources, cmLocalGhsMultiGenerator* localGhsMultiGenerator, cmGeneratorTarget* generatorTarget); - static void WriteObjectLangOverride(std::ostream* fout, + static void WriteObjectLangOverride(std::ostream& fout, const cmSourceFile* sourceFile); - std::string GetOutputDirectory(const std::string& config) const; - std::string GetOutputFilename(const std::string& config) const; + static std::string ComputeLongestObjectDirectory( cmLocalGhsMultiGenerator const* localGhsMultiGenerator, cmGeneratorTarget* generatorTarget, cmSourceFile* const sourceFile); @@ -100,13 +73,6 @@ private: cmGeneratorTarget* GeneratorTarget; cmLocalGhsMultiGenerator* LocalGenerator; cmMakefile* Makefile; - std::string AbsBuildFilePath; - std::string RelBuildFilePath; - std::string AbsBuildFileName; - std::string RelBuildFileName; - std::string RelOutputFileName; - std::string AbsOutputFileName; - std::map FolderBuildStreams; bool TargetGroup; bool DynamicDownload; static std::string const DDOption; diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 7d1e594..452a610 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -25,7 +25,6 @@ cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm) cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator() { - cmDeleteAll(TargetFolderBuildStreams); } cmLocalGenerator* cmGlobalGhsMultiGenerator::CreateLocalGenerator( @@ -204,40 +203,28 @@ void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd, } } -void cmGlobalGhsMultiGenerator::OpenBuildFileStream( - std::string const& filepath, cmGeneratedFileStream** filestream) -{ - // Get a stream where to generate things. - if (NULL == *filestream) { - *filestream = new cmGeneratedFileStream(filepath.c_str()); - if (NULL != *filestream) { - OpenBuildFileStream(*filestream); - } - } -} - -void cmGlobalGhsMultiGenerator::OpenBuildFileStream( - cmGeneratedFileStream* filestream) -{ - *filestream << "#!gbuild" << std::endl; -} -/* temporary until all file handling is cleaned up */ -void cmGlobalGhsMultiGenerator::OpenBuildFileStream(std::ostream& fout) +void cmGlobalGhsMultiGenerator::WriteFileHeader(std::ostream& fout) { fout << "#!gbuild" << std::endl; + fout << "#" << std::endl + << "# CMAKE generated file: DO NOT EDIT!" << std::endl + << "# Generated by \"" << this->GetActualName() << "\"" + << " Generator, CMake Version " << cmVersion::GetMajorVersion() << "." + << cmVersion::GetMinorVersion() << std::endl + << "#" << std::endl + << std::endl; } void cmGlobalGhsMultiGenerator::WriteTopLevelProject( std::ostream& fout, cmLocalGenerator* root, std::vector& generators) { - OpenBuildFileStream(fout); + WriteFileHeader(fout); this->WriteMacros(fout); this->WriteHighLevelDirectives(fout); - // GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, &fout); - fout << "[Project]" << std::endl; - this->WriteDisclaimer(&fout); + GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fout); + fout << "# Top Level Project File" << std::endl; // Specify BSP option if supplied by user @@ -330,17 +317,6 @@ void cmGlobalGhsMultiGenerator::WriteSubProjects( } } -void cmGlobalGhsMultiGenerator::CloseBuildFileStream( - cmGeneratedFileStream** filestream) -{ - if (filestream) { - delete *filestream; - *filestream = NULL; - } else { - cmSystemTools::Error("Build file stream was not open."); - } -} - void cmGlobalGhsMultiGenerator::Generate() { // first do the superclass method @@ -465,116 +441,6 @@ void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives(std::ostream& fout) } } -void cmGlobalGhsMultiGenerator::WriteDisclaimer(std::ostream* os) -{ - (*os) << "#" << std::endl - << "# CMAKE generated file: DO NOT EDIT!" << std::endl - << "# Generated by \"" << GetActualName() << "\"" - << " Generator, CMake Version " << cmVersion::GetMajorVersion() << "." - << cmVersion::GetMinorVersion() << std::endl - << "#" << std::endl; -} - -void cmGlobalGhsMultiGenerator::AddFilesUpToPath( - cmGeneratedFileStream* mainBuildFile, - std::map* targetFolderBuildStreams, - char const* homeOutputDirectory, std::string const& path, - GhsMultiGpj::Types projType, std::string const& relPath) -{ - std::string workingPath(path); - cmSystemTools::ConvertToUnixSlashes(workingPath); - std::vector splitPath = cmSystemTools::SplitString(workingPath); - std::string workingRelPath(relPath); - cmSystemTools::ConvertToUnixSlashes(workingRelPath); - if (!workingRelPath.empty()) { - workingRelPath += "/"; - } - std::string pathUpTo; - for (std::vector::const_iterator splitPathI = splitPath.begin(); - splitPath.end() != splitPathI; ++splitPathI) { - pathUpTo += *splitPathI; - if (targetFolderBuildStreams->end() == - targetFolderBuildStreams->find(pathUpTo)) { - AddFilesUpToPathNewBuildFile( - mainBuildFile, targetFolderBuildStreams, homeOutputDirectory, pathUpTo, - splitPath.begin() == splitPathI, workingRelPath, projType); - } - AddFilesUpToPathAppendNextFile(targetFolderBuildStreams, pathUpTo, - splitPathI, splitPath.end(), projType); - pathUpTo += "/"; - } -} - -void cmGlobalGhsMultiGenerator::Open( - std::string const& mapKeyName, std::string const& fileName, - std::map* fileMap) -{ - if (fileMap->end() == fileMap->find(fileName)) { - cmGeneratedFileStream* temp(new cmGeneratedFileStream); - temp->open(fileName.c_str()); - (*fileMap)[mapKeyName] = temp; - } -} - -void cmGlobalGhsMultiGenerator::AddFilesUpToPathNewBuildFile( - cmGeneratedFileStream* mainBuildFile, - std::map* targetFolderBuildStreams, - char const* homeOutputDirectory, std::string const& pathUpTo, - bool const isFirst, std::string const& relPath, - GhsMultiGpj::Types const projType) -{ - // create folders up to file path - std::string absPath = std::string(homeOutputDirectory) + "/" + relPath; - std::string newPath = absPath + pathUpTo; - if (!cmSystemTools::FileExists(newPath.c_str())) { - cmSystemTools::MakeDirectory(newPath.c_str()); - } - - // Write out to filename for first time - std::string relFilename(GetFileNameFromPath(pathUpTo)); - std::string absFilename = absPath + relFilename; - Open(pathUpTo, absFilename, targetFolderBuildStreams); - OpenBuildFileStream((*targetFolderBuildStreams)[pathUpTo]); - GhsMultiGpj::WriteGpjTag(projType, (*targetFolderBuildStreams)[pathUpTo]); - WriteDisclaimer((*targetFolderBuildStreams)[pathUpTo]); - - // Add to main build file - if (isFirst) { - *mainBuildFile << relFilename << " "; - GhsMultiGpj::WriteGpjTag(projType, mainBuildFile); - } -} - -void cmGlobalGhsMultiGenerator::AddFilesUpToPathAppendNextFile( - std::map* targetFolderBuildStreams, - std::string const& pathUpTo, - std::vector::const_iterator splitPathI, - std::vector::const_iterator end, - GhsMultiGpj::Types const projType) -{ - std::vector::const_iterator splitPathNextI = splitPathI + 1; - if (end != splitPathNextI && - targetFolderBuildStreams->end() == - targetFolderBuildStreams->find(pathUpTo + "/" + *splitPathNextI)) { - std::string nextFilename(*splitPathNextI); - nextFilename = GetFileNameFromPath(nextFilename); - *(*targetFolderBuildStreams)[pathUpTo] << nextFilename << " "; - GhsMultiGpj::WriteGpjTag(projType, (*targetFolderBuildStreams)[pathUpTo]); - } -} - -std::string cmGlobalGhsMultiGenerator::GetFileNameFromPath( - std::string const& path) -{ - std::string output(path); - if (!path.empty()) { - cmSystemTools::ConvertToUnixSlashes(output); - std::vector splitPath = cmSystemTools::SplitString(output); - output += "/" + splitPath.back() + FILE_EXTENSION; - } - return output; -} - bool cmGlobalGhsMultiGenerator::IsTgtForBuild(const cmGeneratorTarget* tgt) { const std::string config = diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index d992f89..71c0b48 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -65,29 +65,8 @@ public: void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override; - cmGeneratedFileStream* GetBuildFileStream() - { - return this->TargetFolderBuildStreams[""]; - } - - static void OpenBuildFileStream(std::string const& filepath, - cmGeneratedFileStream** filestream); - static void OpenBuildFileStream(cmGeneratedFileStream* filestream); - void OpenBuildFileStream(std::ostream& fout); - static void CloseBuildFileStream(cmGeneratedFileStream** filestream); - /// Write the common disclaimer text at the top of each build file. - static void WriteDisclaimer(std::ostream* os); - std::vector GetLibDirs() { return this->LibDirs; } - - static void AddFilesUpToPath( - cmGeneratedFileStream* mainBuildFile, - std::map* targetFolderBuildStreams, - char const* homeOutputDirectory, std::string const& path, - GhsMultiGpj::Types projType, std::string const& relPath = ""); - static void Open(std::string const& mapKeyName, std::string const& fileName, - std::map* fileMap); - - static std::string trimQuotes(std::string const& str); + // Write the common disclaimer text at the top of each build file. + void WriteFileHeader(std::ostream& fout); // Target dependency sorting class TargetSet : public std::set @@ -132,24 +111,9 @@ private: void WriteSubProjects(std::ostream& fout, cmLocalGenerator* root, std::vector& generators); - static void AddFilesUpToPathNewBuildFile( - cmGeneratedFileStream* mainBuildFile, - std::map* targetFolderBuildStreams, - char const* homeOutputDirectory, std::string const& pathUpTo, bool isFirst, - std::string const& relPath, GhsMultiGpj::Types projType); - static void AddFilesUpToPathAppendNextFile( - std::map* targetFolderBuildStreams, - std::string const& pathUpTo, - std::vector::const_iterator splitPathI, - std::vector::const_iterator end, GhsMultiGpj::Types projType); - static std::string GetFileNameFromPath(std::string const& path); - bool IsTgtForBuild(const cmGeneratorTarget* tgt); - std::vector TargetSubProjects; - std::map TargetFolderBuildStreams; - - std::vector LibDirs; + std::string trimQuotes(std::string const& str); static const char* DEFAULT_BUILD_PROGRAM; static const char* DEFAULT_TOOLSET_ROOT; -- cgit v0.12