[CLI] Allow "=" as separator between library name and address in --libraries commandline option.

This commit is contained in:
Hui Yu 2021-01-02 17:24:26 +08:00
parent a75b87c80e
commit c669ee251a
13 changed files with 55 additions and 29 deletions

View File

@ -19,6 +19,8 @@ Compiler Features:
* Standard JSON: New option ``modelCheckerSettings.targets`` allows specifying which targets should be checked. The valid options are ``all``, ``constantCondition``,
``underflow``, ``overflow``, ``divByZero``, ``balance``, ``assert``, ``popEmptyArray``, where the default is ``all``. Multiple targets can be chosen at the same time,
separated by a comma without spaces: ``underflow,overflow,assert``.
* Command Line Interface: Allow "=" as separator between library name and address in ``--libraries`` commandline option.
* Command Line Interface: Only accept the library address that is prefixed with "0x" in ``--libraries`` commandline option.
Bugfixes:
* Code Generator: Fix length check when decoding malformed error data in catch clause.

View File

@ -74,7 +74,10 @@ identify which libraries the placeholders represent. Note that the fully qualifi
is the path of its source file and the library name separated by ``:``.
You can use ``solc`` as a linker meaning that it will insert the library addresses for you at those points:
Either add ``--libraries "file.sol:Math:0x1234567890123456789012345678901234567890 file.sol:Heap:0xabCD567890123456789012345678901234567890"`` to your command to provide an address for each library (use commas or spaces as separators) or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``.
Either add ``--libraries "file.sol:Math=0x1234567890123456789012345678901234567890 file.sol:Heap=0xabCD567890123456789012345678901234567890"`` to your command to provide an address for each library (use commas or spaces as separators) or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``.
.. note::
Starting Solidity 0.8.1 accepts ``=`` as separator between library and address, and ``:`` as a separator is deprecated. It will be removed in the future. Currently ``--libraries "file.sol:Math:0x1234567890123456789012345678901234567890 file.sol:Heap:0xabCD567890123456789012345678901234567890"`` will work too.
If ``solc`` is called with the option ``--standard-json``, it will expect a JSON input (as explained below) on the standard input, and return a JSON output on the standard output. This is the recommended interface for more complex and especially automated uses. The process will always terminate in a "success" state and report any errors via the JSON output.
The option ``--base-path`` is also processed in standard-json mode.

View File

@ -946,7 +946,7 @@ is equivalent to
let a := 0x1234567890123456789012345678901234567890
when the linker is invoked with ``--libraries "file.sol:Math:0x1234567890123456789012345678901234567890``
when the linker is invoked with ``--libraries "file.sol:Math=0x1234567890123456789012345678901234567890``
option.
See :ref:`Using the Commandline Compiler <commandline-compiler>` for details about the Solidity linker.

View File

@ -666,16 +666,29 @@ bool CommandLineInterface::parseLibraryOption(string const& _input)
for (string const& lib: libraries)
if (!lib.empty())
{
//search for last colon in string as our binaries output placeholders in the form of file:Name
//so we need to search for the second `:` in the string
auto colon = lib.rfind(':');
if (colon == string::npos)
//search for equal sign or last colon in string as our binaries output placeholders in the form of file=Name or file:Name
//so we need to search for `=` or `:` in the string
auto separator = lib.rfind('=');
bool isSeparatorEqualSign = true;
if (separator == string::npos)
{
serr() << "Colon separator missing in library address specifier \"" << lib << "\"" << endl;
return false;
separator = lib.rfind(':');
if (separator == string::npos)
{
serr() << "Equal sign separator missing in library address specifier \"" << lib << "\"" << endl;
return false;
}
else
isSeparatorEqualSign = false; // separator is colon
}
else
if (lib.rfind('=') != lib.find('='))
{
serr() << "Only one equal sign \"=\" is allowed in the address string \"" << lib << "\"." << endl;
return false;
}
string libName(lib.begin(), lib.begin() + static_cast<ptrdiff_t>(colon));
string libName(lib.begin(), lib.begin() + static_cast<ptrdiff_t>(separator));
boost::trim(libName);
if (m_libraries.count(libName))
{
@ -683,17 +696,25 @@ bool CommandLineInterface::parseLibraryOption(string const& _input)
return false;
}
string addrString(lib.begin() + static_cast<ptrdiff_t>(colon) + 1, lib.end());
string addrString(lib.begin() + static_cast<ptrdiff_t>(separator) + 1, lib.end());
boost::trim(addrString);
if (addrString.substr(0, 2) == "0x")
addrString = addrString.substr(2);
if (addrString.empty())
{
serr() << "Empty address provided for library \"" << libName << "\":" << endl;
serr() << "Note that there should not be any whitespace after the colon." << endl;
serr() << "Empty address provided for library \"" << libName << "\"." << endl;
serr() << "Note that there should not be any whitespace after the " << (isSeparatorEqualSign ? "equal sign" : "colon") << "." << endl;
return false;
}
else if (addrString.length() != 40)
if (addrString.substr(0, 2) == "0x")
addrString = addrString.substr(2);
else
{
serr() << "The address " << addrString << " is not prefixed with \"0x\"." << endl;
serr() << "Note that the address must be prefixed with \"0x\"." << endl;
return false;
}
if (addrString.length() != 40)
{
serr() << "Invalid length for address for library \"" << libName << "\": " << addrString.length() << " instead of 40 characters." << endl;
return false;
@ -924,8 +945,8 @@ General Information)").c_str(),
g_argLibraries.c_str(),
po::value<vector<string>>()->value_name("libs"),
"Direct string or file containing library addresses. Syntax: "
"<libraryName>:<address> [, or whitespace] ...\n"
"Address is interpreted as a hex string optionally prefixed by 0x."
"<libraryName>=<address> [, or whitespace] ...\n"
"Address is interpreted as a hex string prefixed by 0x."
)
;
desc.add(linkerModeOptions);

View File

@ -354,11 +354,11 @@ rm -rf "$SOLTMPDIR"
echo "Done."
printTask "Testing library checksum..."
echo '' | "$SOLC" - --link --libraries a:0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null
! echo '' | "$SOLC" - --link --libraries a:0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null
echo '' | "$SOLC" - --link --libraries a=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null
! echo '' | "$SOLC" - --link --libraries a=0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null
printTask "Testing long library names..."
echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname:0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null
echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null
printTask "Testing linking itself..."
SOLTMPDIR=$(mktemp -d)
@ -372,7 +372,7 @@ SOLTMPDIR=$(mktemp -d)
# But not in library file.
grep -q -v '[/_]' L.bin
# Now link
"$SOLC" --link --libraries x.sol:L:0x90f20564390eAe531E810af625A22f51385Cd222 C.bin
"$SOLC" --link --libraries x.sol:L=0x90f20564390eAe531E810af625A22f51385Cd222 C.bin
# Now the placeholder and explanation should be gone.
grep -q -v '[/_]' C.bin
)

View File

@ -1 +1 @@
--bin --bin-runtime --libraries linking_solidity/input.sol:L:0x1234567890123456789012345678901234567890
--bin --bin-runtime --libraries linking_solidity/input.sol:L=0x1234567890123456789012345678901234567890

View File

@ -1 +1 @@
--bin --bin-runtime --libraries linking_solidity_unresolved_references/input.sol:L1:0x1234567890123456789012345678901234567890
--bin --bin-runtime --libraries linking_solidity_unresolved_references/input.sol:L1=0x1234567890123456789012345678901234567890

View File

@ -1 +1 @@
--strict-assembly --libraries contract/test.sol:L:0x1234567890123456789012345678901234567890
--strict-assembly --libraries contract/test.sol:L=0x1234567890123456789012345678901234567890

View File

@ -1 +1 @@
--strict-assembly --libraries library.sol:L:0x1234567890123456789012345678901234567890,library.sol:L:0x0987654321098765432109876543210987654321
--strict-assembly --libraries library.sol:L=0x1234567890123456789012345678901234567890,library.sol:L=0x0987654321098765432109876543210987654321

View File

@ -1 +1 @@
--strict-assembly --libraries L:0x1234567890123456789012345678901234567890
--strict-assembly --libraries L=0x1234567890123456789012345678901234567890

View File

@ -1 +1 @@
--strict-assembly --libraries library1.sol:L:0x1111111111111111111111111111111111111111,library2.sol:L:0x2222222222222222222222222222222222222222
--strict-assembly --libraries library1.sol:L=0x1111111111111111111111111111111111111111,library2.sol:L=0x2222222222222222222222222222222222222222

View File

@ -1 +1 @@
--strict-assembly --libraries library1.sol:L:0x1234567890123456789012345678901234567890
--strict-assembly --libraries library1.sol:L=0x1234567890123456789012345678901234567890

View File

@ -1 +1 @@
--strict-assembly --libraries contract/test.sol:L1:0x1234567890123456789012345678901234567890
--strict-assembly --libraries contract/test.sol:L1=0x1234567890123456789012345678901234567890