mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow running Eldarica from the command line
This commit is contained in:
@@ -33,6 +33,8 @@ set(sources
|
||||
StringUtils.h
|
||||
SwarmHash.cpp
|
||||
SwarmHash.h
|
||||
TemporaryDirectory.cpp
|
||||
TemporaryDirectory.h
|
||||
UTF8.cpp
|
||||
UTF8.h
|
||||
vector_ref.h
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
|
||||
#include <libsolutil/TemporaryDirectory.h>
|
||||
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <regex>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::util;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
TemporaryDirectory::TemporaryDirectory(std::string const& _prefix):
|
||||
m_path(fs::temp_directory_path() / fs::unique_path(_prefix + "-%%%%-%%%%-%%%%-%%%%"))
|
||||
{
|
||||
// Prefix should just be a file name and not contain anything that would make us step out of /tmp.
|
||||
solAssert(fs::path(_prefix) == fs::path(_prefix).stem(), "");
|
||||
|
||||
fs::create_directory(m_path);
|
||||
}
|
||||
|
||||
TemporaryDirectory::TemporaryDirectory(
|
||||
vector<boost::filesystem::path> const& _subdirectories,
|
||||
string const& _prefix
|
||||
):
|
||||
TemporaryDirectory(_prefix)
|
||||
{
|
||||
for (boost::filesystem::path const& subdirectory: _subdirectories)
|
||||
{
|
||||
solAssert(!subdirectory.is_absolute() && subdirectory.root_path() != "/", "");
|
||||
solAssert(
|
||||
m_path.lexically_relative(subdirectory).empty() ||
|
||||
*m_path.lexically_relative(subdirectory).begin() != "..",
|
||||
""
|
||||
);
|
||||
boost::filesystem::create_directories(m_path / subdirectory);
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryDirectory::~TemporaryDirectory()
|
||||
{
|
||||
// A few paranoid sanity checks just to be extra sure we're not deleting someone's homework.
|
||||
solAssert(m_path.string().find(fs::temp_directory_path().string()) == 0, "");
|
||||
solAssert(!fs::equivalent(m_path, fs::temp_directory_path()), "");
|
||||
solAssert(!fs::equivalent(m_path, m_path.root_path()), "");
|
||||
solAssert(!m_path.empty(), "");
|
||||
|
||||
boost::system::error_code errorCode;
|
||||
uintmax_t numRemoved = fs::remove_all(m_path, errorCode);
|
||||
if (errorCode.value() != boost::system::errc::success)
|
||||
{
|
||||
cerr << "Failed to completely remove temporary directory '" << m_path << "'. ";
|
||||
cerr << "Only " << numRemoved << " files were actually removed." << endl;
|
||||
cerr << "Reason: " << errorCode.message() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryWorkingDirectory::TemporaryWorkingDirectory(fs::path const& _newDirectory):
|
||||
m_originalWorkingDirectory(fs::current_path())
|
||||
{
|
||||
fs::current_path(_newDirectory);
|
||||
}
|
||||
|
||||
TemporaryWorkingDirectory::~TemporaryWorkingDirectory()
|
||||
{
|
||||
fs::current_path(m_originalWorkingDirectory);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
/**
|
||||
* Utilities for creating temporary directories and temporarily changing the working directory
|
||||
* for use in tests.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace solidity::util
|
||||
{
|
||||
|
||||
/**
|
||||
* An object that creates a unique temporary directory and automatically deletes it and its
|
||||
* content upon being destroyed.
|
||||
*
|
||||
* The directory is guaranteed to be newly created and empty. Directory names are generated
|
||||
* randomly. If a directory with the same name already exists (very unlikely but possible) the
|
||||
* object won't reuse it and will fail with an exception instead.
|
||||
*/
|
||||
class TemporaryDirectory
|
||||
{
|
||||
public:
|
||||
TemporaryDirectory(std::string const& _prefix = "solidity");
|
||||
TemporaryDirectory(
|
||||
std::vector<boost::filesystem::path> const& _subdirectories,
|
||||
std::string const& _prefix = "solidity"
|
||||
);
|
||||
~TemporaryDirectory();
|
||||
|
||||
boost::filesystem::path const& path() const { return m_path; }
|
||||
operator boost::filesystem::path() const { return m_path; }
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_path;
|
||||
};
|
||||
|
||||
/**
|
||||
* An object that changes current working directory and restores it upon destruction.
|
||||
*/
|
||||
class TemporaryWorkingDirectory
|
||||
{
|
||||
public:
|
||||
TemporaryWorkingDirectory(boost::filesystem::path const& _newDirectory);
|
||||
~TemporaryWorkingDirectory();
|
||||
|
||||
boost::filesystem::path const& originalWorkingDirectory() const { return m_originalWorkingDirectory; }
|
||||
operator boost::filesystem::path() const { return boost::filesystem::current_path(); }
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_originalWorkingDirectory;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user