mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Detailed documentation for path resolution in imports, including remappings, base path and standard input
This commit is contained in:
+24
-14
@@ -2,7 +2,7 @@
|
||||
Using the Compiler
|
||||
******************
|
||||
|
||||
.. index:: ! commandline compiler, compiler;commandline, ! solc, ! linker
|
||||
.. index:: ! commandline compiler, compiler;commandline, ! solc
|
||||
|
||||
.. _commandline-compiler:
|
||||
|
||||
@@ -33,11 +33,13 @@ This parameter has effects on the following (this might change in the future):
|
||||
- the size of the binary search in the function dispatch routine
|
||||
- the way constants like large numbers or strings are stored
|
||||
|
||||
Path Remapping
|
||||
--------------
|
||||
.. index:: allowed paths, --allow-paths, base path, --base-path
|
||||
|
||||
Base Path and Import Remapping
|
||||
------------------------------
|
||||
|
||||
The commandline compiler will automatically read imported files from the filesystem, but
|
||||
it is also possible to provide path redirects using ``prefix=path`` in the following way:
|
||||
it is also possible to provide :ref:`path redirects <import-remapping>` using ``prefix=path`` in the following way:
|
||||
|
||||
::
|
||||
|
||||
@@ -49,19 +51,24 @@ This essentially instructs the compiler to search for anything starting with
|
||||
the remapping targets and outside of the directories where explicitly specified source
|
||||
files reside, so things like ``import "/etc/passwd";`` only work if you add ``/=/`` as a remapping.
|
||||
|
||||
An empty remapping prefix is not allowed.
|
||||
|
||||
If there are multiple matches due to remappings, the one with the longest common prefix is selected.
|
||||
|
||||
When accessing the filesystem to search for imports, all paths are treated as if they were fully qualified paths.
|
||||
This behaviour can be customized by adding the command line option ``--base-path`` with a path to be prepended
|
||||
before each filesystem access for imports is performed. Furthermore, the part added via ``--base-path``
|
||||
will not appear in the contract metadata.
|
||||
|
||||
For security reasons the compiler has restrictions what directories it can access. Paths (and their subdirectories) of source files specified on the commandline and paths defined by remappings are allowed for import statements, but everything else is rejected. Additional paths (and their subdirectories) can be allowed via the ``--allow-paths /sample/path,/another/sample/path`` switch.
|
||||
When accessing the filesystem to search for imports, :ref:`paths that do not start with ./
|
||||
or ../ <relative-imports>` are treated as relative to the directory specified using
|
||||
``--base-path`` option (or the current working directory if base path is not specified).
|
||||
Furthermore, the part added via ``--base-path`` will not appear in the contract metadata.
|
||||
|
||||
For security reasons the compiler has restrictions on what directories it can access.
|
||||
Directories of source files specified on the command line and target paths of
|
||||
remappings are automatically allowed to be accessed by the file reader, but everything
|
||||
else is rejected by default.
|
||||
Additional paths (and their subdirectories) can be allowed via the
|
||||
``--allow-paths /sample/path,/another/sample/path`` switch.
|
||||
Everything inside the path specified via ``--base-path`` is always allowed.
|
||||
|
||||
The above is only a simplification of how the compiler handles import paths.
|
||||
For a detailed explanation with examples and discussion of corner cases please refer to the section on
|
||||
:ref:`path resolution <path-resolution>`.
|
||||
|
||||
.. index:: ! linker, ! --link, ! --libraries
|
||||
.. _library-linking:
|
||||
|
||||
Library Linking
|
||||
@@ -79,6 +86,8 @@ Either add ``--libraries "file.sol:Math=0x12345678901234567890123456789012345678
|
||||
.. 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.
|
||||
|
||||
.. index:: --standard-json, --base-path
|
||||
|
||||
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.
|
||||
|
||||
@@ -166,6 +175,7 @@ at each version. Backward compatibility is not guaranteed between each version.
|
||||
the optimizer.
|
||||
|
||||
|
||||
.. index:: ! standard JSON, ! --standard-json
|
||||
.. _compiler-api:
|
||||
|
||||
Compiler Input and Output JSON Description
|
||||
|
||||
Reference in New Issue
Block a user