Commit f5acecaa authored by wahikihiki's avatar wahikihiki Committed by Kyle Edwards
Browse files

cmExportCommand: Port to cmArgumentParser

parent e6b6bb06
......@@ -2,10 +2,13 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExportCommand.h"
#include "cm_static_string_view.hxx"
#include "cmsys/RegularExpression.hxx"
#include <map>
#include <sstream>
#include <utility>
#include "cmArgumentParser.h"
#include "cmExportBuildAndroidMKGenerator.h"
#include "cmExportBuildFileGenerator.h"
#include "cmExportSetMap.h"
......@@ -18,6 +21,7 @@
#include "cmSystemTools.h"
#include "cmTarget.h"
class cmExportSet;
class cmExecutionStatus;
#if defined(__HAIKU__)
......@@ -25,19 +29,6 @@ class cmExecutionStatus;
# include <StorageDefs.h>
#endif
cmExportCommand::cmExportCommand()
: Targets(&Helper, "TARGETS")
, Append(&Helper, "APPEND", &ArgumentGroup)
, ExportSetName(&Helper, "EXPORT", &ArgumentGroup)
, Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
, Filename(&Helper, "FILE", &ArgumentGroup)
, ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup)
, AndroidMKFile(&Helper, "ANDROID_MK")
{
this->ExportSet = nullptr;
}
// cmExportCommand
bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
......@@ -49,45 +40,62 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
if (args[0] == "PACKAGE") {
return this->HandlePackage(args);
}
struct Arguments
{
std::string ExportSetName;
std::vector<std::string> Targets;
std::string Namespace;
std::string Filename;
std::string AndroidMKFile;
bool Append = false;
bool ExportOld = false;
};
auto parser = cmArgumentParser<Arguments>{}
.Bind("NAMESPACE"_s, &Arguments::Namespace)
.Bind("FILE"_s, &Arguments::Filename);
if (args[0] == "EXPORT") {
this->ExportSetName.Follows(nullptr);
this->ArgumentGroup.Follows(&this->ExportSetName);
parser.Bind("EXPORT"_s, &Arguments::ExportSetName);
} else {
this->Targets.Follows(nullptr);
this->ArgumentGroup.Follows(&this->Targets);
parser.Bind("TARGETS"_s, &Arguments::Targets);
parser.Bind("ANDROID_MK"_s, &Arguments::AndroidMKFile);
parser.Bind("APPEND"_s, &Arguments::Append);
parser.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, &Arguments::ExportOld);
}
std::vector<std::string> unknownArgs;
this->Helper.Parse(&args, &unknownArgs);
Arguments const arguments = parser.Parse(args, &unknownArgs);
if (!unknownArgs.empty()) {
this->SetError("Unknown arguments.");
this->SetError("Unknown argument: \"" + unknownArgs.front() + "\".");
return false;
}
std::string fname;
bool android = false;
if (this->AndroidMKFile.WasFound()) {
fname = this->AndroidMKFile.GetString();
if (!arguments.AndroidMKFile.empty()) {
fname = arguments.AndroidMKFile;
android = true;
}
if (!this->Filename.WasFound() && fname.empty()) {
if (arguments.Filename.empty() && fname.empty()) {
if (args[0] != "EXPORT") {
this->SetError("FILE <filename> option missing.");
return false;
}
fname = this->ExportSetName.GetString() + ".cmake";
fname = arguments.ExportSetName + ".cmake";
} else if (fname.empty()) {
// Make sure the file has a .cmake extension.
if (cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString()) !=
if (cmSystemTools::GetFilenameLastExtension(arguments.Filename) !=
".cmake") {
std::ostringstream e;
e << "FILE option given filename \"" << this->Filename.GetString()
e << "FILE option given filename \"" << arguments.Filename
<< "\" which does not have an extension of \".cmake\".\n";
this->SetError(e.str());
return false;
}
fname = this->Filename.GetString();
fname = arguments.Filename;
}
// Get the file to write.
......@@ -109,33 +117,19 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
cmExportSet* ExportSet = nullptr;
if (args[0] == "EXPORT") {
if (this->Append.IsEnabled()) {
std::ostringstream e;
e << "EXPORT signature does not recognise the APPEND option.";
this->SetError(e.str());
return false;
}
if (this->ExportOld.IsEnabled()) {
std::ostringstream e;
e << "EXPORT signature does not recognise the "
"EXPORT_LINK_INTERFACE_LIBRARIES option.";
this->SetError(e.str());
return false;
}
cmExportSetMap& setMap = gg->GetExportSets();
std::string setName = this->ExportSetName.GetString();
if (setMap.find(setName) == setMap.end()) {
auto const it = setMap.find(arguments.ExportSetName);
if (it == setMap.end()) {
std::ostringstream e;
e << "Export set \"" << setName << "\" not found.";
e << "Export set \"" << arguments.ExportSetName << "\" not found.";
this->SetError(e.str());
return false;
}
this->ExportSet = setMap[setName];
} else if (this->Targets.WasFound()) {
for (std::string const& currentTarget : this->Targets.GetVector()) {
ExportSet = it->second;
} else if (!arguments.Targets.empty()) {
for (std::string const& currentTarget : arguments.Targets) {
if (this->Makefile->IsAlias(currentTarget)) {
std::ostringstream e;
e << "given ALIAS target \"" << currentTarget
......@@ -159,7 +153,7 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
}
targets.push_back(currentTarget);
}
if (this->Append.IsEnabled()) {
if (arguments.Append) {
if (cmExportBuildFileGenerator* ebfg =
gg->GetExportedTargetsFile(fname)) {
ebfg->AppendTargets(targets);
......@@ -179,15 +173,15 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
ebfg = new cmExportBuildFileGenerator;
}
ebfg->SetExportFile(fname.c_str());
ebfg->SetNamespace(this->Namespace.GetCString());
ebfg->SetAppendMode(this->Append.IsEnabled());
if (this->ExportSet) {
ebfg->SetExportSet(this->ExportSet);
ebfg->SetNamespace(arguments.Namespace);
ebfg->SetAppendMode(arguments.Append);
if (ExportSet != nullptr) {
ebfg->SetExportSet(ExportSet);
} else {
ebfg->SetTargets(targets);
}
this->Makefile->AddExportBuildFileGenerator(ebfg);
ebfg->SetExportOld(this->ExportOld.IsEnabled());
ebfg->SetExportOld(arguments.ExportOld);
// Compute the set of configurations exported.
std::vector<std::string> configurationTypes;
......@@ -198,7 +192,7 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
for (std::string const& ct : configurationTypes) {
ebfg->AddConfiguration(ct);
}
if (this->ExportSet) {
if (ExportSet != nullptr) {
gg->AddBuildExportExportSet(ebfg);
} else {
gg->AddBuildExportSet(ebfg);
......
......@@ -9,21 +9,12 @@
#include <vector>
#include "cmCommand.h"
#include "cmCommandArgumentsHelper.h"
class cmExecutionStatus;
class cmExportSet;
/** \class cmExportLibraryDependenciesCommand
* \brief Add a test to the lists of tests to run.
*
* cmExportLibraryDependenciesCommand adds a test to the list of tests to run
*
*/
class cmExportCommand : public cmCommand
{
public:
cmExportCommand();
/**
* This is a virtual constructor for the command.
*/
......@@ -37,21 +28,6 @@ public:
cmExecutionStatus& status) override;
private:
cmCommandArgumentsHelper Helper;
cmCommandArgumentGroup ArgumentGroup;
cmCAStringVector Targets;
cmCAEnabler Append;
cmCAString ExportSetName;
cmCAString Namespace;
cmCAString Filename;
cmCAEnabler ExportOld;
cmCAString AndroidMKFile;
cmExportSet* ExportSet;
friend class cmExportBuildFileGenerator;
std::string ErrorMessage;
bool HandlePackage(std::vector<std::string> const& args);
void StorePackageRegistryWin(std::string const& package, const char* content,
const char* hash);
......
CMake Error at AppendExport.cmake:[0-9]+ \(export\):
export EXPORT signature does not recognise the APPEND option.
export Unknown argument: "APPEND".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
CMake Error at OldIface.cmake:[0-9]+ \(export\):
export EXPORT signature does not recognise the
EXPORT_LINK_INTERFACE_LIBRARIES option.
export Unknown argument: "EXPORT_LINK_INTERFACE_LIBRARIES".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
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