Commit 7bc88b91 authored by Daniel Pfeifer's avatar Daniel Pfeifer Committed by wahikihiki

cmInstallFilesCommand: Port away from FinalPass

parent 6a1a3763
......@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallFilesCommand.h"
#include "cmAlgorithms.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmInstallFilesGenerator.h"
......@@ -13,7 +12,13 @@
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,
cmExecutionStatus&)
{
......@@ -25,18 +30,20 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
// Enable the install target.
this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
this->Destination = args[0];
std::string const& dest = args[0];
if ((args.size() > 1) && (args[1] == "FILES")) {
this->IsFilesForm = true;
std::vector<std::string> files;
for (std::string const& arg : cmMakeRange(args).advance(2)) {
// 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 {
this->IsFilesForm = false;
cmAppend(this->FinalArgs, args.begin() + 1, args.end());
std::vector<std::string> finalArgs(args.begin() + 1, args.end());
this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) {
FinalAction(makefile, dest, finalArgs);
});
}
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
......@@ -45,23 +52,20 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
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 const& ext = this->FinalArgs[0];
std::string const& ext = args[0];
std::vector<std::string> installFiles;
// two different options
if (this->FinalArgs.size() > 1) {
if (args.size() > 1) {
// 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;
// for each argument, get the files
for (; s != this->FinalArgs.end(); ++s) {
for (; s != args.end(); ++s) {
// replace any variables
std::string const& temps = *s;
if (!cmSystemTools::GetFilenamePath(temps).empty()) {
......@@ -72,30 +76,31 @@ void cmInstallFilesCommand::FinalPass()
}
// 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
{
std::vector<std::string> files;
std::string const& regex = this->FinalArgs[0];
cmSystemTools::Glob(this->Makefile->GetCurrentSourceDirectory(), regex,
files);
std::string const& regex = args[0];
cmSystemTools::Glob(makefile.GetCurrentSourceDirectory(), regex, files);
std::vector<std::string>::iterator s = files.begin();
// for each argument, get the files
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
// 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);
if (destination.empty()) {
destination = ".";
......@@ -106,12 +111,12 @@ void cmInstallFilesCommand::CreateInstallGenerator() const
const char* no_rename = "";
bool no_exclude_from_all = false;
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;
cmInstallGenerator::MessageLevel message =
cmInstallGenerator::SelectMessageLevel(this->Makefile);
this->Makefile->AddInstallGenerator(new cmInstallFilesGenerator(
this->Files, destination.c_str(), false, no_permissions, no_configurations,
cmInstallGenerator::SelectMessageLevel(&makefile);
makefile.AddInstallGenerator(new cmInstallFilesGenerator(
files, destination.c_str(), false, no_permissions, no_configurations,
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
* returned.
*/
std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
static std::string FindInstallSource(cmMakefile& makefile, const char* name)
{
if (cmSystemTools::FileIsFullPath(name) ||
cmGeneratorExpression::Find(name) == 0) {
......@@ -130,10 +135,10 @@ std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
}
// This is a relative path.
std::string tb = this->Makefile->GetCurrentBinaryDirectory();
std::string tb = makefile.GetCurrentBinaryDirectory();
tb += "/";
tb += name;
std::string ts = this->Makefile->GetCurrentSourceDirectory();
std::string ts = makefile.GetCurrentSourceDirectory();
ts += "/";
ts += name;
......
......@@ -37,25 +37,6 @@ public:
*/
bool InitialPass(std::vector<std::string> const& args,
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment