mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-20 22:20:50 -06:00
cmInstallFilesCommand: Port away from FinalPass
This commit is contained in:
committed by
Regina Pfeifer
parent
6a1a3763ee
commit
7bc88b9165
@@ -2,7 +2,6 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmInstallFilesCommand.h"
|
#include "cmInstallFilesCommand.h"
|
||||||
|
|
||||||
#include "cmAlgorithms.h"
|
|
||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmInstallFilesGenerator.h"
|
#include "cmInstallFilesGenerator.h"
|
||||||
@@ -13,7 +12,13 @@
|
|||||||
|
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
|
|
||||||
// cmExecutableCommand
|
static std::string FindInstallSource(cmMakefile& makefile, const char* name);
|
||||||
|
static void CreateInstallGenerator(cmMakefile& makefile,
|
||||||
|
std::string const& dest,
|
||||||
|
std::vector<std::string> const& files);
|
||||||
|
static void FinalAction(cmMakefile& makefile, std::string const& dest,
|
||||||
|
std::vector<std::string> const& args);
|
||||||
|
|
||||||
bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
|
bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus&)
|
cmExecutionStatus&)
|
||||||
{
|
{
|
||||||
@@ -25,18 +30,20 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
// Enable the install target.
|
// Enable the install target.
|
||||||
this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
|
this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
|
||||||
|
|
||||||
this->Destination = args[0];
|
std::string const& dest = args[0];
|
||||||
|
|
||||||
if ((args.size() > 1) && (args[1] == "FILES")) {
|
if ((args.size() > 1) && (args[1] == "FILES")) {
|
||||||
this->IsFilesForm = true;
|
std::vector<std::string> files;
|
||||||
for (std::string const& arg : cmMakeRange(args).advance(2)) {
|
for (std::string const& arg : cmMakeRange(args).advance(2)) {
|
||||||
// Find the source location for each file listed.
|
// Find the source location for each file listed.
|
||||||
this->Files.push_back(this->FindInstallSource(arg.c_str()));
|
files.push_back(FindInstallSource(*this->Makefile, arg.c_str()));
|
||||||
}
|
}
|
||||||
this->CreateInstallGenerator();
|
CreateInstallGenerator(*this->Makefile, dest, files);
|
||||||
} else {
|
} else {
|
||||||
this->IsFilesForm = false;
|
std::vector<std::string> finalArgs(args.begin() + 1, args.end());
|
||||||
cmAppend(this->FinalArgs, args.begin() + 1, args.end());
|
this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) {
|
||||||
|
FinalAction(makefile, dest, finalArgs);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
|
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
|
||||||
@@ -45,23 +52,20 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmInstallFilesCommand::FinalPass()
|
static void FinalAction(cmMakefile& makefile, std::string const& dest,
|
||||||
|
std::vector<std::string> const& args)
|
||||||
{
|
{
|
||||||
// No final pass for "FILES" form of arguments.
|
|
||||||
if (this->IsFilesForm) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string testf;
|
std::string testf;
|
||||||
std::string const& ext = this->FinalArgs[0];
|
std::string const& ext = args[0];
|
||||||
|
std::vector<std::string> installFiles;
|
||||||
|
|
||||||
// two different options
|
// two different options
|
||||||
if (this->FinalArgs.size() > 1) {
|
if (args.size() > 1) {
|
||||||
// now put the files into the list
|
// now put the files into the list
|
||||||
std::vector<std::string>::iterator s = this->FinalArgs.begin();
|
std::vector<std::string>::const_iterator s = args.begin();
|
||||||
++s;
|
++s;
|
||||||
// for each argument, get the files
|
// for each argument, get the files
|
||||||
for (; s != this->FinalArgs.end(); ++s) {
|
for (; s != args.end(); ++s) {
|
||||||
// replace any variables
|
// replace any variables
|
||||||
std::string const& temps = *s;
|
std::string const& temps = *s;
|
||||||
if (!cmSystemTools::GetFilenamePath(temps).empty()) {
|
if (!cmSystemTools::GetFilenamePath(temps).empty()) {
|
||||||
@@ -72,30 +76,31 @@ void cmInstallFilesCommand::FinalPass()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add to the result
|
// add to the result
|
||||||
this->Files.push_back(this->FindInstallSource(testf.c_str()));
|
installFiles.push_back(FindInstallSource(makefile, testf.c_str()));
|
||||||
}
|
}
|
||||||
} else // reg exp list
|
} else // reg exp list
|
||||||
{
|
{
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
std::string const& regex = this->FinalArgs[0];
|
std::string const& regex = args[0];
|
||||||
cmSystemTools::Glob(this->Makefile->GetCurrentSourceDirectory(), regex,
|
cmSystemTools::Glob(makefile.GetCurrentSourceDirectory(), regex, files);
|
||||||
files);
|
|
||||||
|
|
||||||
std::vector<std::string>::iterator s = files.begin();
|
std::vector<std::string>::iterator s = files.begin();
|
||||||
// for each argument, get the files
|
// for each argument, get the files
|
||||||
for (; s != files.end(); ++s) {
|
for (; s != files.end(); ++s) {
|
||||||
this->Files.push_back(this->FindInstallSource(s->c_str()));
|
installFiles.push_back(FindInstallSource(makefile, s->c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->CreateInstallGenerator();
|
CreateInstallGenerator(makefile, dest, installFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmInstallFilesCommand::CreateInstallGenerator() const
|
static void CreateInstallGenerator(cmMakefile& makefile,
|
||||||
|
std::string const& dest,
|
||||||
|
std::vector<std::string> const& files)
|
||||||
{
|
{
|
||||||
// Construct the destination. This command always installs under
|
// Construct the destination. This command always installs under
|
||||||
// the prefix. We skip the leading slash given by the user.
|
// the prefix. We skip the leading slash given by the user.
|
||||||
std::string destination = this->Destination.substr(1);
|
std::string destination = dest.substr(1);
|
||||||
cmSystemTools::ConvertToUnixSlashes(destination);
|
cmSystemTools::ConvertToUnixSlashes(destination);
|
||||||
if (destination.empty()) {
|
if (destination.empty()) {
|
||||||
destination = ".";
|
destination = ".";
|
||||||
@@ -106,12 +111,12 @@ void cmInstallFilesCommand::CreateInstallGenerator() const
|
|||||||
const char* no_rename = "";
|
const char* no_rename = "";
|
||||||
bool no_exclude_from_all = false;
|
bool no_exclude_from_all = false;
|
||||||
std::string no_component =
|
std::string no_component =
|
||||||
this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
|
makefile.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
|
||||||
std::vector<std::string> no_configurations;
|
std::vector<std::string> no_configurations;
|
||||||
cmInstallGenerator::MessageLevel message =
|
cmInstallGenerator::MessageLevel message =
|
||||||
cmInstallGenerator::SelectMessageLevel(this->Makefile);
|
cmInstallGenerator::SelectMessageLevel(&makefile);
|
||||||
this->Makefile->AddInstallGenerator(new cmInstallFilesGenerator(
|
makefile.AddInstallGenerator(new cmInstallFilesGenerator(
|
||||||
this->Files, destination.c_str(), false, no_permissions, no_configurations,
|
files, destination.c_str(), false, no_permissions, no_configurations,
|
||||||
no_component.c_str(), message, no_exclude_from_all, no_rename));
|
no_component.c_str(), message, no_exclude_from_all, no_rename));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +126,7 @@ void cmInstallFilesCommand::CreateInstallGenerator() const
|
|||||||
* present in the build tree. If a full path is given, it is just
|
* present in the build tree. If a full path is given, it is just
|
||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
|
static std::string FindInstallSource(cmMakefile& makefile, const char* name)
|
||||||
{
|
{
|
||||||
if (cmSystemTools::FileIsFullPath(name) ||
|
if (cmSystemTools::FileIsFullPath(name) ||
|
||||||
cmGeneratorExpression::Find(name) == 0) {
|
cmGeneratorExpression::Find(name) == 0) {
|
||||||
@@ -130,10 +135,10 @@ std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is a relative path.
|
// This is a relative path.
|
||||||
std::string tb = this->Makefile->GetCurrentBinaryDirectory();
|
std::string tb = makefile.GetCurrentBinaryDirectory();
|
||||||
tb += "/";
|
tb += "/";
|
||||||
tb += name;
|
tb += name;
|
||||||
std::string ts = this->Makefile->GetCurrentSourceDirectory();
|
std::string ts = makefile.GetCurrentSourceDirectory();
|
||||||
ts += "/";
|
ts += "/";
|
||||||
ts += name;
|
ts += name;
|
||||||
|
|
||||||
|
|||||||
@@ -37,25 +37,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool InitialPass(std::vector<std::string> const& args,
|
bool InitialPass(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus& status) override;
|
cmExecutionStatus& status) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* This is called at the end after all the information
|
|
||||||
* specified by the command is accumulated. Most commands do
|
|
||||||
* not implement this method. At this point, reading and
|
|
||||||
* writing to the cache can be done.
|
|
||||||
*/
|
|
||||||
void FinalPass() override;
|
|
||||||
bool HasFinalPass() const override { return !this->IsFilesForm; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void CreateInstallGenerator() const;
|
|
||||||
std::string FindInstallSource(const char* name) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<std::string> FinalArgs;
|
|
||||||
bool IsFilesForm = false;
|
|
||||||
std::string Destination;
|
|
||||||
std::vector<std::string> Files;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user