.. _Environment Variables:

Environment Variables
=====================


To **define** an environment variable you can use the following syntax:

.. code-block::

  +dvt_setenv+<NAME>[=VALUE]

.. rubric:: Examples

.. code-block::
    :emphasize-text: +dvt_init_from_simlog

    +dvt_setenv+UVM_HOME=/uvm/uvm-1.1

    +dvt_setenv+SPECMAN_PATH=$SPECMAN_PATH:/path/to/my/vips

To **use** the value of an environment variable called ENV_VAR you can use any of the following notations:

-  UNIX: $ENV_VAR or ${ENV_VAR}
-  Windows: %ENV_VAR%
-  Makefile: $(ENV_VAR)
-  TCL: $::env(ENV_VAR) or $env(ENV_VAR)

Environment variables, either from the parent shell or explicitly defined, can be used to specify:

-  top files
-  directives that take a path as an argument, for example ``+incdir+``
-  value for defines

When an environment variable is not defined, but it is used, the behavior is as follows:

-  for the value of a define directive, the define value is left as-is
-  for top files and directives that take a path as an argument, an error is signaled and such top files and directives are ignored
-  when used inside the value of an environment variable, it is expanded to the empty string

Environment variables are visible to the DVT parsers, for example when used in the e language **import** statements.

Environment variables are propagated to the external tools launched from DVT, for example by using Run Configurations or External Builders.

When an environment variable is used inside a build file, only the ``+dvt_setenv+`` directives above the usage line are taken into account.

.. rubric:: Implementation note

The Dot '.' segment in a path denotes the current directory, which is solved when the path is used, for example to specify a top file or incdir.
It is not solved when defining an environment variable.
See the example below:

.. code-block::
    :emphasize-text: +dvt_init_from_simlog

    -------- In default.build --------
    +dvt_setenv+MYVAR=.   // $MYVAR has the value '.' until used to specify a path
    $MYVAR/top1.e         // Equivalent with $DVT_PROJECT_LOC/top1.e
    -F other/file.f

    -------- In other/file.f --------
                          // $MYVAR is used here to specify a path, '.' shall be solved to $DVT_PROJECT_LOC/other/
    $MYVAR/top2.e         // Equivalent with $DVT_PROJECT_LOC/other/top2.e

.. list-table:: Predefined environment variables
   :widths: 30 70

   * -  **Variable**
     -  **Value**
   * -  DVT_PROJECT_LOC
     -  Absolute path of the project directory.
   * -  DVT_PROJECT_PARENT_LOC
     -  Absolute path of the project's parent directory.
