mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Detect source unit name collisions between paths specified on the command line
This commit is contained in:
@@ -32,6 +32,7 @@ using solidity::frontend::ReadCallback;
|
||||
using solidity::langutil::InternalCompilerError;
|
||||
using solidity::util::errinfo_comment;
|
||||
using solidity::util::readFileAsString;
|
||||
using std::map;
|
||||
using std::reference_wrapper;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -176,6 +177,24 @@ string FileReader::cliPathToSourceUnitName(boost::filesystem::path const& _cliPa
|
||||
return normalizedPath.generic_string();
|
||||
}
|
||||
|
||||
map<string, FileReader::FileSystemPathSet> FileReader::detectSourceUnitNameCollisions(FileSystemPathSet const& _cliPaths)
|
||||
{
|
||||
map<string, FileReader::FileSystemPathSet> nameToPaths;
|
||||
for (boost::filesystem::path const& cliPath: _cliPaths)
|
||||
{
|
||||
string sourceUnitName = cliPathToSourceUnitName(cliPath);
|
||||
boost::filesystem::path normalizedPath = normalizeCLIPathForVFS(cliPath);
|
||||
nameToPaths[sourceUnitName].insert(normalizedPath);
|
||||
}
|
||||
|
||||
map<string, FileReader::FileSystemPathSet> collisions;
|
||||
for (auto&& [sourceUnitName, cliPaths]: nameToPaths)
|
||||
if (cliPaths.size() >= 2)
|
||||
collisions[sourceUnitName] = std::move(cliPaths);
|
||||
|
||||
return collisions;
|
||||
}
|
||||
|
||||
boost::filesystem::path FileReader::normalizeCLIPathForVFS(
|
||||
boost::filesystem::path const& _path,
|
||||
SymlinkResolution _symlinkResolution
|
||||
|
||||
@@ -96,6 +96,13 @@ public:
|
||||
/// making it relative to base path or one of the include directories.
|
||||
std::string cliPathToSourceUnitName(boost::filesystem::path const& _cliPath);
|
||||
|
||||
/// Checks if a set contains any paths that lead to different files but would receive identical
|
||||
/// source unit names. Files are considered the same if their paths are exactly the same after
|
||||
/// normalization (without following symlinks).
|
||||
/// @returns a map containing all the conflicting source unit names and the paths that would
|
||||
/// receive them. The returned paths are normalized.
|
||||
std::map<std::string, FileSystemPathSet> detectSourceUnitNameCollisions(FileSystemPathSet const& _cliPaths);
|
||||
|
||||
/// Normalizes a filesystem path to make it include all components up to the filesystem root,
|
||||
/// remove small, inconsequential differences that do not affect the meaning and make it look
|
||||
/// the same on all platforms (if possible).
|
||||
|
||||
Reference in New Issue
Block a user