ENH: Refactor install(DIRECTORY) argument parsing
We previously used several booleans with at most one set to true at a time to track argument parsing state. This refactors it to use one enumeration.
This commit is contained in:
parent
5a7ac0def1
commit
a79f8cd4c1
|
@ -850,15 +850,10 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
|
||||||
bool
|
bool
|
||||||
cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
{
|
{
|
||||||
bool doing_dirs = true;
|
enum Doing { DoingNone, DoingDirs, DoingDestination, DoingPattern,
|
||||||
bool doing_destination = false;
|
DoingRegex, DoingPermsFile, DoingPermsDir, DoingPermsMatch,
|
||||||
bool doing_pattern = false;
|
DoingConfigurations, DoingComponent };
|
||||||
bool doing_regex = false;
|
Doing doing = DoingDirs;
|
||||||
bool doing_permissions_file = false;
|
|
||||||
bool doing_permissions_dir = false;
|
|
||||||
bool doing_permissions_match = false;
|
|
||||||
bool doing_configurations = false;
|
|
||||||
bool doing_component = false;
|
|
||||||
bool in_match_mode = false;
|
bool in_match_mode = false;
|
||||||
std::vector<std::string> dirs;
|
std::vector<std::string> dirs;
|
||||||
const char* destination = 0;
|
const char* destination = 0;
|
||||||
|
@ -881,47 +876,24 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to setting the destination property.
|
// Switch to setting the destination property.
|
||||||
doing_dirs = false;
|
doing = DoingDestination;
|
||||||
doing_destination = true;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
}
|
}
|
||||||
else if(args[i] == "PATTERN")
|
else if(args[i] == "PATTERN")
|
||||||
{
|
{
|
||||||
// Switch to a new pattern match rule.
|
// Switch to a new pattern match rule.
|
||||||
doing_dirs = false;
|
doing = DoingPattern;
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = true;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_permissions_match = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
in_match_mode = true;
|
in_match_mode = true;
|
||||||
}
|
}
|
||||||
else if(args[i] == "REGEX")
|
else if(args[i] == "REGEX")
|
||||||
{
|
{
|
||||||
// Switch to a new regex match rule.
|
// Switch to a new regex match rule.
|
||||||
doing_dirs = false;
|
doing = DoingRegex;
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = true;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_permissions_match = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
in_match_mode = true;
|
in_match_mode = true;
|
||||||
}
|
}
|
||||||
else if(args[i] == "EXCLUDE")
|
else if(args[i] == "EXCLUDE")
|
||||||
{
|
{
|
||||||
// Add this property to the current match rule.
|
// Add this property to the current match rule.
|
||||||
if(!in_match_mode || doing_pattern || doing_regex)
|
if(!in_match_mode || doing == DoingPattern || doing == DoingRegex)
|
||||||
{
|
{
|
||||||
cmOStringStream e;
|
cmOStringStream e;
|
||||||
e << args[0] << " does not allow \""
|
e << args[0] << " does not allow \""
|
||||||
|
@ -930,7 +902,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
literal_args += " EXCLUDE";
|
literal_args += " EXCLUDE";
|
||||||
doing_permissions_match = false;
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(args[i] == "PERMISSIONS")
|
else if(args[i] == "PERMISSIONS")
|
||||||
{
|
{
|
||||||
|
@ -945,7 +917,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
|
|
||||||
// Switch to setting the current match permissions property.
|
// Switch to setting the current match permissions property.
|
||||||
literal_args += " PERMISSIONS";
|
literal_args += " PERMISSIONS";
|
||||||
doing_permissions_match = true;
|
doing = DoingPermsMatch;
|
||||||
}
|
}
|
||||||
else if(args[i] == "FILE_PERMISSIONS")
|
else if(args[i] == "FILE_PERMISSIONS")
|
||||||
{
|
{
|
||||||
|
@ -959,14 +931,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to setting the file permissions property.
|
// Switch to setting the file permissions property.
|
||||||
doing_dirs = false;
|
doing = DoingPermsFile;
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = true;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
}
|
}
|
||||||
else if(args[i] == "DIRECTORY_PERMISSIONS")
|
else if(args[i] == "DIRECTORY_PERMISSIONS")
|
||||||
{
|
{
|
||||||
|
@ -980,14 +945,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to setting the directory permissions property.
|
// Switch to setting the directory permissions property.
|
||||||
doing_dirs = false;
|
doing = DoingPermsDir;
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = true;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
}
|
}
|
||||||
else if(args[i] == "USE_SOURCE_PERMISSIONS")
|
else if(args[i] == "USE_SOURCE_PERMISSIONS")
|
||||||
{
|
{
|
||||||
|
@ -1001,15 +959,8 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this option literally.
|
// Add this option literally.
|
||||||
doing_dirs = false;
|
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
literal_args += " USE_SOURCE_PERMISSIONS";
|
literal_args += " USE_SOURCE_PERMISSIONS";
|
||||||
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(args[i] == "FILES_MATCHING")
|
else if(args[i] == "FILES_MATCHING")
|
||||||
{
|
{
|
||||||
|
@ -1023,16 +974,8 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this option literally.
|
// Add this option literally.
|
||||||
doing_dirs = false;
|
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_permissions_match = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = false;
|
|
||||||
literal_args += " FILES_MATCHING";
|
literal_args += " FILES_MATCHING";
|
||||||
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(args[i] == "CONFIGURATIONS")
|
else if(args[i] == "CONFIGURATIONS")
|
||||||
{
|
{
|
||||||
|
@ -1046,14 +989,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to setting the configurations property.
|
// Switch to setting the configurations property.
|
||||||
doing_dirs = false;
|
doing = DoingConfigurations;
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_configurations = true;
|
|
||||||
doing_component = false;
|
|
||||||
}
|
}
|
||||||
else if(args[i] == "COMPONENT")
|
else if(args[i] == "COMPONENT")
|
||||||
{
|
{
|
||||||
|
@ -1067,16 +1003,9 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to setting the component property.
|
// Switch to setting the component property.
|
||||||
doing_dirs = false;
|
doing = DoingComponent;
|
||||||
doing_destination = false;
|
|
||||||
doing_pattern = false;
|
|
||||||
doing_regex = false;
|
|
||||||
doing_permissions_file = false;
|
|
||||||
doing_permissions_dir = false;
|
|
||||||
doing_configurations = false;
|
|
||||||
doing_component = true;
|
|
||||||
}
|
}
|
||||||
else if(doing_dirs)
|
else if(doing == DoingDirs)
|
||||||
{
|
{
|
||||||
// Convert this directory to a full path.
|
// Convert this directory to a full path.
|
||||||
std::string dir = args[i];
|
std::string dir = args[i];
|
||||||
|
@ -1101,16 +1030,16 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
// Store the directory for installation.
|
// Store the directory for installation.
|
||||||
dirs.push_back(dir);
|
dirs.push_back(dir);
|
||||||
}
|
}
|
||||||
else if(doing_configurations)
|
else if(doing == DoingConfigurations)
|
||||||
{
|
{
|
||||||
configurations.push_back(args[i]);
|
configurations.push_back(args[i]);
|
||||||
}
|
}
|
||||||
else if(doing_destination)
|
else if(doing == DoingDestination)
|
||||||
{
|
{
|
||||||
destination = args[i].c_str();
|
destination = args[i].c_str();
|
||||||
doing_destination = false;
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(doing_pattern)
|
else if(doing == DoingPattern)
|
||||||
{
|
{
|
||||||
// Convert the pattern to a regular expression. Require a
|
// Convert the pattern to a regular expression. Require a
|
||||||
// leading slash and trailing end-of-string in the matched
|
// leading slash and trailing end-of-string in the matched
|
||||||
|
@ -1121,9 +1050,9 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
cmSystemTools::ReplaceString(regex, "\\", "\\\\");
|
cmSystemTools::ReplaceString(regex, "\\", "\\\\");
|
||||||
literal_args += regex;
|
literal_args += regex;
|
||||||
literal_args += "$\"";
|
literal_args += "$\"";
|
||||||
doing_pattern = false;
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(doing_regex)
|
else if(doing == DoingRegex)
|
||||||
{
|
{
|
||||||
literal_args += " REGEX \"";
|
literal_args += " REGEX \"";
|
||||||
// Match rules are case-insensitive on some platforms.
|
// Match rules are case-insensitive on some platforms.
|
||||||
|
@ -1135,14 +1064,14 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
cmSystemTools::ReplaceString(regex, "\\", "\\\\");
|
cmSystemTools::ReplaceString(regex, "\\", "\\\\");
|
||||||
literal_args += regex;
|
literal_args += regex;
|
||||||
literal_args += "\"";
|
literal_args += "\"";
|
||||||
doing_regex = false;
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(doing_component)
|
else if(doing == DoingComponent)
|
||||||
{
|
{
|
||||||
component = args[i];
|
component = args[i];
|
||||||
doing_component = false;
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
else if(doing_permissions_file)
|
else if(doing == DoingPermsFile)
|
||||||
{
|
{
|
||||||
// Check the requested permission.
|
// Check the requested permission.
|
||||||
if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
|
if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
|
||||||
|
@ -1154,7 +1083,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(doing_permissions_dir)
|
else if(doing == DoingPermsDir)
|
||||||
{
|
{
|
||||||
// Check the requested permission.
|
// Check the requested permission.
|
||||||
if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
|
if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
|
||||||
|
@ -1166,7 +1095,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(doing_permissions_match)
|
else if(doing == DoingPermsMatch)
|
||||||
{
|
{
|
||||||
// Check the requested permission.
|
// Check the requested permission.
|
||||||
if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
|
if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
|
||||||
|
|
Loading…
Reference in New Issue