Commit e0a84904 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmState: Split auxiliary classes into separate files

Port dependents to the new locations as needed.

Leave behind a cmState.h include in cmListFileCache to reduce noise. It
is removed in a following commit.
parent a91eaf38
......@@ -360,6 +360,10 @@ set(SRCS
cmSourceGroup.h
cmState.cxx
cmState.h
cmStateDirectory.cxx
cmStateDirectory.h
cmStateSnapshot.cxx
cmStateSnapshot.h
cmStateTypes.h
cmSystemTools.cxx
cmSystemTools.h
......
......@@ -17,6 +17,7 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
......
......@@ -7,6 +7,7 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmOutputConverter.h"
#include "cmStateDirectory.h"
#include "cmSystemTools.h"
#include <assert.h>
......
......@@ -6,7 +6,8 @@
#include <cmConfigure.h>
#include "cmExportSetMap.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetDepend.h"
......
......@@ -12,6 +12,8 @@
#include "cmMakefile.h"
#include "cmMakefileTargetGenerator.h"
#include "cmOutputConverter.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetDepend.h"
......
......@@ -5,6 +5,7 @@
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
#include "cmOutputConverter.h"
#include "cmStateDirectory.h"
cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
cmStateDirectory stateDir)
......
......@@ -4,7 +4,7 @@
#ifndef cmLinkLineComputer_h
#define cmLinkLineComputer_h
#include "cmState.h"
#include "cmStateDirectory.h"
class cmComputeLinkInformation;
class cmOutputConverter;
......
......@@ -10,6 +10,7 @@
#include <vector>
#include "cmState.h"
#include "cmStateSnapshot.h"
/** \class cmListFileCache
* \brief A class to cache list file contents.
......
......@@ -16,6 +16,8 @@
#include "cmMakefile.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTestGenerator.h"
......
......@@ -16,6 +16,8 @@
#include "cmOutputConverter.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
......
......@@ -17,6 +17,8 @@
#include "cmListFileCache.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTest.h"
......
......@@ -9,7 +9,7 @@
#include "cmListFileCache.h"
#include "cmNewLineStyle.h"
#include "cmPolicies.h"
#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmTarget.h"
#include "cmTargetLinkLibraryType.h"
#include "cmake.h"
......
......@@ -3,6 +3,8 @@
#include "cmOutputConverter.h"
#include "cmAlgorithms.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmSystemTools.h"
#include <algorithm>
......
......@@ -5,7 +5,7 @@
#include <cmConfigure.h> // IWYU pragma: keep
#include "cmState.h"
#include "cmStateSnapshot.h"
#include <string>
#include <vector>
......
......@@ -7,6 +7,8 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmOutputConverter.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cm_auto_ptr.hxx"
......
This diff is collapsed.
......@@ -8,7 +8,6 @@
#include "cmAlgorithms.h"
#include "cmDefinitions.h"
#include "cmLinkedTree.h"
#include "cmPolicies.h"
#include "cmProperty.h"
#include "cmPropertyDefinitionMap.h"
#include "cmPropertyMap.h"
......@@ -186,138 +185,4 @@ private:
bool MSYSShell;
};
class cmStateSnapshot
{
public:
cmStateSnapshot(cmState* state = CM_NULLPTR);
cmStateSnapshot(cmState* state, cmStateDetail::PositionType position);
const char* GetDefinition(std::string const& name) const;
bool IsInitialized(std::string const& name) const;
void SetDefinition(std::string const& name, std::string const& value);
void RemoveDefinition(std::string const& name);
std::vector<std::string> UnusedKeys() const;
std::vector<std::string> ClosureKeys() const;
bool RaiseScope(std::string const& var, const char* varDef);
void SetListFile(std::string const& listfile);
std::string GetExecutionListFile() const;
std::vector<cmStateSnapshot> GetChildren();
bool IsValid() const;
cmStateSnapshot GetBuildsystemDirectoryParent() const;
cmStateSnapshot GetCallStackParent() const;
cmStateSnapshot GetCallStackBottom() const;
cmStateEnums::SnapshotType GetType() const;
void SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id) const;
bool HasDefinedPolicyCMP0011();
void PushPolicy(cmPolicies::PolicyMap entry, bool weak);
bool PopPolicy();
bool CanPopPolicyScope();
cmState* GetState() const;
cmStateDirectory GetDirectory() const;
void SetProjectName(std::string const& name);
std::string GetProjectName() const;
void InitializeFromParent_ForSubdirsCommand();
struct StrictWeakOrder
{
bool operator()(const cmStateSnapshot& lhs,
const cmStateSnapshot& rhs) const;
};
void SetDirectoryDefinitions();
void SetDefaultDefinitions();
private:
friend bool operator==(const cmStateSnapshot& lhs,
const cmStateSnapshot& rhs);
friend bool operator!=(const cmStateSnapshot& lhs,
const cmStateSnapshot& rhs);
friend class cmState;
friend class cmStateDirectory;
friend struct StrictWeakOrder;
void InitializeFromParent();
cmState* State;
cmStateDetail::PositionType Position;
};
class cmStateDirectory
{
cmStateDirectory(
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator iter,
cmStateSnapshot const& snapshot);
public:
const char* GetCurrentSource() const;
void SetCurrentSource(std::string const& dir);
const char* GetCurrentBinary() const;
void SetCurrentBinary(std::string const& dir);
const char* GetRelativePathTopSource() const;
const char* GetRelativePathTopBinary() const;
void SetRelativePathTopSource(const char* dir);
void SetRelativePathTopBinary(const char* dir);
cmStringRange GetIncludeDirectoriesEntries() const;
cmBacktraceRange GetIncludeDirectoriesEntryBacktraces() const;
void AppendIncludeDirectoriesEntry(std::string const& vec,
cmListFileBacktrace const& lfbt);
void PrependIncludeDirectoriesEntry(std::string const& vec,
cmListFileBacktrace const& lfbt);
void SetIncludeDirectories(std::string const& vec,
cmListFileBacktrace const& lfbt);
void ClearIncludeDirectories();
cmStringRange GetCompileDefinitionsEntries() const;
cmBacktraceRange GetCompileDefinitionsEntryBacktraces() const;
void AppendCompileDefinitionsEntry(std::string const& vec,
cmListFileBacktrace const& lfbt);
void SetCompileDefinitions(std::string const& vec,
cmListFileBacktrace const& lfbt);
void ClearCompileDefinitions();
cmStringRange GetCompileOptionsEntries() const;
cmBacktraceRange GetCompileOptionsEntryBacktraces() const;
void AppendCompileOptionsEntry(std::string const& vec,
cmListFileBacktrace const& lfbt);
void SetCompileOptions(std::string const& vec,
cmListFileBacktrace const& lfbt);
void ClearCompileOptions();
void SetProperty(const std::string& prop, const char* value,
cmListFileBacktrace const& lfbt);
void AppendProperty(const std::string& prop, const char* value,
bool asString, cmListFileBacktrace const& lfbt);
const char* GetProperty(const std::string& prop) const;
const char* GetProperty(const std::string& prop, bool chain) const;
bool GetPropertyAsBool(const std::string& prop) const;
std::vector<std::string> GetPropertyKeys() const;
void AddNormalTargetName(std::string const& name);
private:
void ComputeRelativePathTopSource();
void ComputeRelativePathTopBinary();
private:
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator
DirectoryState;
cmStateSnapshot Snapshot_;
friend class cmStateSnapshot;
};
bool operator==(const cmStateSnapshot& lhs, const cmStateSnapshot& rhs);
bool operator!=(const cmStateSnapshot& lhs, const cmStateSnapshot& rhs);
#endif
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmStateDirectory.h"
#include "cmState.h"
#include "cmStatePrivate.h"
#include "cmSystemTools.h"
static std::string const kBINARY_DIR = "BINARY_DIR";
static std::string const kBUILDSYSTEM_TARGETS = "BUILDSYSTEM_TARGETS";
static std::string const kSOURCE_DIR = "SOURCE_DIR";
static std::string const kSUBDIRECTORIES = "SUBDIRECTORIES";
void cmStateDirectory::ComputeRelativePathTopSource()
{
// Relative path conversion inside the source tree is not used to
// construct relative paths passed to build tools so it is safe to use
// even when the source is a network path.
cmStateSnapshot snapshot = this->Snapshot_;
std::vector<cmStateSnapshot> snapshots;
snapshots.push_back(snapshot);
while (true) {
snapshot = snapshot.GetBuildsystemDirectoryParent();
if (snapshot.IsValid()) {
snapshots.push_back(snapshot);
} else {
break;
}
}
std::string result = snapshots.front().GetDirectory().GetCurrentSource();
for (std::vector<cmStateSnapshot>::const_iterator it = snapshots.begin() + 1;
it != snapshots.end(); ++it) {
std::string currentSource = it->GetDirectory().GetCurrentSource();
if (cmSystemTools::IsSubDirectory(result, currentSource)) {
result = currentSource;
}
}
this->DirectoryState->RelativePathTopSource = result;
}
void cmStateDirectory::ComputeRelativePathTopBinary()
{
cmStateSnapshot snapshot = this->Snapshot_;
std::vector<cmStateSnapshot> snapshots;
snapshots.push_back(snapshot);
while (true) {
snapshot = snapshot.GetBuildsystemDirectoryParent();
if (snapshot.IsValid()) {
snapshots.push_back(snapshot);
} else {
break;
}
}
std::string result = snapshots.front().GetDirectory().GetCurrentBinary();
for (std::vector<cmStateSnapshot>::const_iterator it = snapshots.begin() + 1;
it != snapshots.end(); ++it) {
std::string currentBinary = it->GetDirectory().GetCurrentBinary();
if (cmSystemTools::IsSubDirectory(result, currentBinary)) {
result = currentBinary;
}
}
// The current working directory on Windows cannot be a network
// path. Therefore relative paths cannot work when the binary tree
// is a network path.
if (result.size() < 2 || result.substr(0, 2) != "//") {
this->DirectoryState->RelativePathTopBinary = result;
} else {
this->DirectoryState->RelativePathTopBinary = "";
}
}
const char* cmStateDirectory::GetCurrentSource() const
{
return this->DirectoryState->Location.c_str();
}
void cmStateDirectory::SetCurrentSource(std::string const& dir)
{
std::string& loc = this->DirectoryState->Location;
loc = dir;
cmSystemTools::ConvertToUnixSlashes(loc);
loc = cmSystemTools::CollapseFullPath(loc);
this->ComputeRelativePathTopSource();
this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc);
}
const char* cmStateDirectory::GetCurrentBinary() const
{
return this->DirectoryState->OutputLocation.c_str();
}
void cmStateDirectory::SetCurrentBinary(std::string const& dir)
{
std::string& loc = this->DirectoryState->OutputLocation;
loc = dir;
cmSystemTools::ConvertToUnixSlashes(loc);
loc = cmSystemTools::CollapseFullPath(loc);
this->ComputeRelativePathTopBinary();
this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc);
}
const char* cmStateDirectory::GetRelativePathTopSource() const
{
return this->DirectoryState->RelativePathTopSource.c_str();
}
const char* cmStateDirectory::GetRelativePathTopBinary() const
{
return this->DirectoryState->RelativePathTopBinary.c_str();
}
void cmStateDirectory::SetRelativePathTopSource(const char* dir)
{
this->DirectoryState->RelativePathTopSource = dir;
}
void cmStateDirectory::SetRelativePathTopBinary(const char* dir)
{
this->DirectoryState->RelativePathTopBinary = dir;
}
cmStateDirectory::cmStateDirectory(
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator iter,
const cmStateSnapshot& snapshot)
: DirectoryState(iter)
, Snapshot_(snapshot)
{
}
template <typename T, typename U>
cmStringRange GetPropertyContent(T const& content, U contentEndPosition)
{
std::vector<std::string>::const_iterator end =
content.begin() + contentEndPosition;
std::vector<std::string>::const_reverse_iterator rbegin =
cmMakeReverseIterator(end);
rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
return cmMakeRange(rbegin.base(), end);
}
template <typename T, typename U, typename V>
cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces,
V contentEndPosition)
{
std::vector<std::string>::const_iterator entryEnd =
content.begin() + contentEndPosition;
std::vector<std::string>::const_reverse_iterator rbegin =
cmMakeReverseIterator(entryEnd);
rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
std::vector<cmListFileBacktrace>::const_iterator it =
backtraces.begin() + std::distance(content.begin(), rbegin.base());
std::vector<cmListFileBacktrace>::const_iterator end = backtraces.end();
return cmMakeRange(it, end);
}
template <typename T, typename U, typename V>
void AppendEntry(T& content, U& backtraces, V& endContentPosition,
const std::string& value, const cmListFileBacktrace& lfbt)
{
if (value.empty()) {
return;
}
assert(endContentPosition == content.size());
content.push_back(value);
backtraces.push_back(lfbt);
endContentPosition = content.size();
}
template <typename T, typename U, typename V>
void SetContent(T& content, U& backtraces, V& endContentPosition,
const std::string& vec, const cmListFileBacktrace& lfbt)
{
assert(endContentPosition == content.size());
content.resize(content.size() + 2);
backtraces.resize(backtraces.size() + 2);
content.back() = vec;
backtraces.back() = lfbt;
endContentPosition = content.size();
}
template <typename T, typename U, typename V>
void ClearContent(T& content, U& backtraces, V& endContentPosition)
{
assert(endContentPosition == content.size());
content.resize(content.size() + 1);
backtraces.resize(backtraces.size() + 1);
endContentPosition = content.size();
}
cmStringRange cmStateDirectory::GetIncludeDirectoriesEntries() const
{
return GetPropertyContent(
this->DirectoryState->IncludeDirectories,
this->Snapshot_.Position->IncludeDirectoryPosition);
}
cmBacktraceRange cmStateDirectory::GetIncludeDirectoriesEntryBacktraces() const
{
return GetPropertyBacktraces(
this->DirectoryState->IncludeDirectories,
this->DirectoryState->IncludeDirectoryBacktraces,
this->Snapshot_.Position->IncludeDirectoryPosition);
}
void cmStateDirectory::AppendIncludeDirectoriesEntry(
const std::string& vec, const cmListFileBacktrace& lfbt)
{
AppendEntry(this->DirectoryState->IncludeDirectories,
this->DirectoryState->IncludeDirectoryBacktraces,
this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt);
}
void cmStateDirectory::PrependIncludeDirectoriesEntry(
const std::string& vec, const cmListFileBacktrace& lfbt)
{
std::vector<std::string>::iterator entryEnd =
this->DirectoryState->IncludeDirectories.begin() +
this->Snapshot_.Position->IncludeDirectoryPosition;
std::vector<std::string>::reverse_iterator rend =
this->DirectoryState->IncludeDirectories.rend();
std::vector<std::string>::reverse_iterator rbegin =
cmMakeReverseIterator(entryEnd);
rbegin = std::find(rbegin, rend, cmPropertySentinal);
std::vector<std::string>::iterator entryIt = rbegin.base();
std::vector<std::string>::iterator entryBegin =
this->DirectoryState->IncludeDirectories.begin();
std::vector<cmListFileBacktrace>::iterator btIt =
this->DirectoryState->IncludeDirectoryBacktraces.begin() +
std::distance(entryBegin, entryIt);
this->DirectoryState->IncludeDirectories.insert(entryIt, vec);
this->DirectoryState->IncludeDirectoryBacktraces.insert(btIt, lfbt);
this->Snapshot_.Position->IncludeDirectoryPosition =
this->DirectoryState->IncludeDirectories.size();
}
void cmStateDirectory::SetIncludeDirectories(const std::string& vec,
const cmListFileBacktrace& lfbt)
{
SetContent(this->DirectoryState->IncludeDirectories,
this->DirectoryState->IncludeDirectoryBacktraces,
this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt);
}
void cmStateDirectory::ClearIncludeDirectories()
{
ClearContent(this->DirectoryState->IncludeDirectories,
this->DirectoryState->IncludeDirectoryBacktraces,
this->Snapshot_.Position->IncludeDirectoryPosition);
}
cmStringRange cmStateDirectory::GetCompileDefinitionsEntries() const
{
return GetPropertyContent(
this->DirectoryState->CompileDefinitions,
this->Snapshot_.Position->CompileDefinitionsPosition);
}
cmBacktraceRange cmStateDirectory::GetCompileDefinitionsEntryBacktraces() const
{
return GetPropertyBacktraces(
this->DirectoryState->CompileDefinitions,
this->DirectoryState->CompileDefinitionsBacktraces,
this->Snapshot_.Position->CompileDefinitionsPosition);
}
void cmStateDirectory::AppendCompileDefinitionsEntry(
const std::string& vec, const cmListFileBacktrace& lfbt)
{
AppendEntry(this->DirectoryState->CompileDefinitions,
this->DirectoryState->CompileDefinitionsBacktraces,
this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt);
}
void cmStateDirectory::SetCompileDefinitions(const std::string& vec,
const cmListFileBacktrace& lfbt)
{
SetContent(this->DirectoryState->CompileDefinitions,
this->DirectoryState->CompileDefinitionsBacktraces,
this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt);
}
void cmStateDirectory::ClearCompileDefinitions()
{
ClearContent(this->DirectoryState->CompileDefinitions,
this->DirectoryState->CompileDefinitionsBacktraces,
this->Snapshot_.Position->CompileDefinitionsPosition);
}
cmStringRange cmStateDirectory::GetCompileOptionsEntries() const
{
return GetPropertyContent(this