mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +08:00
cmCommand refactor: cmOutputRequiredFilesCommand
This commit is contained in:
@@ -317,8 +317,7 @@ void GetProjectCommands(cmState* state)
|
|||||||
"load_command", cmLoadCommandCommand, cmPolicies::CMP0031,
|
"load_command", cmLoadCommandCommand, cmPolicies::CMP0031,
|
||||||
"The load_command command should not be called; see CMP0031.");
|
"The load_command command should not be called; see CMP0031.");
|
||||||
state->AddDisallowedCommand(
|
state->AddDisallowedCommand(
|
||||||
"output_required_files", cm::make_unique<cmOutputRequiredFilesCommand>(),
|
"output_required_files", cmOutputRequiredFilesCommand, cmPolicies::CMP0032,
|
||||||
cmPolicies::CMP0032,
|
|
||||||
"The output_required_files command should not be called; see CMP0032.");
|
"The output_required_files command should not be called; see CMP0032.");
|
||||||
state->AddDisallowedCommand(
|
state->AddDisallowedCommand(
|
||||||
"subdir_depends", cm::make_unique<cmSubdirDependsCommand>(),
|
"subdir_depends", cm::make_unique<cmSubdirDependsCommand>(),
|
||||||
|
@@ -5,9 +5,12 @@
|
|||||||
#include "cmsys/FStream.hxx"
|
#include "cmsys/FStream.hxx"
|
||||||
#include "cmsys/RegularExpression.hxx"
|
#include "cmsys/RegularExpression.hxx"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <stdio.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "cmAlgorithms.h"
|
#include "cmAlgorithms.h"
|
||||||
|
#include "cmExecutionStatus.h"
|
||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmSourceFile.h"
|
#include "cmSourceFile.h"
|
||||||
@@ -15,8 +18,7 @@
|
|||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
|
|
||||||
class cmExecutionStatus;
|
namespace {
|
||||||
|
|
||||||
/** \class cmDependInformation
|
/** \class cmDependInformation
|
||||||
* \brief Store dependency information for a single source file.
|
* \brief Store dependency information for a single source file.
|
||||||
*
|
*
|
||||||
@@ -453,43 +455,47 @@ protected:
|
|||||||
DirectoryToFileToPathMapType DirectoryToFileToPathMap;
|
DirectoryToFileToPathMapType DirectoryToFileToPathMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ListDependencies(cmDependInformation const* info, FILE* fout,
|
||||||
|
std::set<cmDependInformation const*>* visited);
|
||||||
|
}
|
||||||
|
|
||||||
// cmOutputRequiredFilesCommand
|
// cmOutputRequiredFilesCommand
|
||||||
bool cmOutputRequiredFilesCommand::InitialPass(
|
bool cmOutputRequiredFilesCommand(std::vector<std::string> const& args,
|
||||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
if (args.size() != 2) {
|
if (args.size() != 2) {
|
||||||
this->SetError("called with incorrect number of arguments");
|
status.SetError("called with incorrect number of arguments");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// store the arg for final pass
|
// store the arg for final pass
|
||||||
this->File = args[0];
|
const std::string& file = args[0];
|
||||||
this->OutputFile = args[1];
|
const std::string& outputFile = args[1];
|
||||||
|
|
||||||
// compute the list of files
|
// compute the list of files
|
||||||
cmLBDepend md;
|
cmLBDepend md;
|
||||||
md.SetMakefile(this->Makefile);
|
md.SetMakefile(&status.GetMakefile());
|
||||||
md.AddSearchPath(this->Makefile->GetCurrentSourceDirectory());
|
md.AddSearchPath(status.GetMakefile().GetCurrentSourceDirectory());
|
||||||
// find the depends for a file
|
// find the depends for a file
|
||||||
const cmDependInformation* info = md.FindDependencies(this->File.c_str());
|
const cmDependInformation* info = md.FindDependencies(file.c_str());
|
||||||
if (info) {
|
if (info) {
|
||||||
// write them out
|
// write them out
|
||||||
FILE* fout = cmsys::SystemTools::Fopen(this->OutputFile, "w");
|
FILE* fout = cmsys::SystemTools::Fopen(outputFile, "w");
|
||||||
if (!fout) {
|
if (!fout) {
|
||||||
this->SetError(cmStrCat("Can not open output file: ", this->OutputFile));
|
status.SetError(cmStrCat("Can not open output file: ", outputFile));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::set<cmDependInformation const*> visited;
|
std::set<cmDependInformation const*> visited;
|
||||||
this->ListDependencies(info, fout, &visited);
|
ListDependencies(info, fout, &visited);
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmOutputRequiredFilesCommand::ListDependencies(
|
namespace {
|
||||||
cmDependInformation const* info, FILE* fout,
|
void ListDependencies(cmDependInformation const* info, FILE* fout,
|
||||||
std::set<cmDependInformation const*>* visited)
|
std::set<cmDependInformation const*>* visited)
|
||||||
{
|
{
|
||||||
// add info to the visited set
|
// add info to the visited set
|
||||||
visited->insert(info);
|
visited->insert(info);
|
||||||
@@ -504,7 +510,8 @@ void cmOutputRequiredFilesCommand::ListDependencies(
|
|||||||
fprintf(fout, "%s\n", d->FullPath.c_str());
|
fprintf(fout, "%s\n", d->FullPath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->ListDependencies(d, fout, visited);
|
ListDependencies(d, fout, visited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -5,34 +5,12 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "cm_memory.hxx"
|
|
||||||
|
|
||||||
#include "cmCommand.h"
|
|
||||||
|
|
||||||
class cmDependInformation;
|
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
|
|
||||||
class cmOutputRequiredFilesCommand : public cmCommand
|
bool cmOutputRequiredFilesCommand(std::vector<std::string> const& args,
|
||||||
{
|
cmExecutionStatus& status);
|
||||||
public:
|
|
||||||
std::unique_ptr<cmCommand> Clone() override
|
|
||||||
{
|
|
||||||
return cm::make_unique<cmOutputRequiredFilesCommand>();
|
|
||||||
}
|
|
||||||
bool InitialPass(std::vector<std::string> const& args,
|
|
||||||
cmExecutionStatus& status) override;
|
|
||||||
|
|
||||||
void ListDependencies(cmDependInformation const* info, FILE* fout,
|
|
||||||
std::set<cmDependInformation const*>* visited);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string File;
|
|
||||||
std::string OutputFile;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user