2 .. include:: ../../rst_prolog.rst
9 The **environ** command generates the environment files used
10 to run and compile your application (as SALOME_ is an example).
13 these files are **not** required,
14 sat sets the environment itself, when compiling.
15 And so does the salome launcher.
17 These files are useful when someone wants to check the environment.
18 They could be used in debug mode to set the environment for *gdb*.
20 The configuration part at the end of this page explains how
21 to specify the environment used by sat (at build or run time),
22 and saved in some files by *sat environ* command.
26 * Create the shell environment files of the application: ::
28 sat environ <application>
30 * Create the environment files of the application for a given shell.
31 Options are bash, bat (for windows), tcl, cfg (the configuration format used by SALOME): ::
33 sat environ <application> --shell [bash|bat|cfg|tcl|all]
35 * Use a different prefix for the files (default is 'env'):
39 # This will create file <prefix>_launch.sh, <prefix>_build.sh
40 sat environ <application> --prefix <prefix>
42 * Use a different target directory for the files:
46 # This will create file env_launch.sh, env_build.sh
47 # in the directory corresponding to <path>
48 sat environ <application> --target <path>
50 * Generate the environment files only with the given products:
54 # This will create the environment files only for the given products
55 # and their prerequisites.
56 # It is useful when you want to visualise which environment uses
57 # sat to compile a given product.
58 sat environ <application> --product <product1>,<product2>, ...
60 * Generate tcl modules for use with *environment-modules* package.
64 sat environ <application> --shell tcl
66 Use this command to generate tcl modules associated to a module base.
67 The production of a module base is triggered when the flag *base* in the application pyconf is set to a value not equal to *yes*.
74 # trigger the production of a environment module base which name is salome9
78 In this example, the module base will be produced in *BASE/apps/salome9*, and the tcl modules associated in the directory tcl *BASE/apps/modulefiles/salome9*.
79 Later, it will be possible to enable these modules with the shell command *module use --append .../SAT/BASE/modulefiles*.
84 The specification of the environment can be done through several mechanisms.
86 1. For salome products (the products with the property ``is_SALOME_module`` as ``yes``) the environment is set automatically by sat, in respect with SALOME requirements.
88 2. For other products, the environment is set with the use of the environ section within the pyconf file of the product. The user has two possibilities, either set directly the environment within the section, or specify a python script which will be used to set the environment programmatically.
90 Within the section, the user can define environment variables. He can also modify PATH variables, by appending or prepending directories.
91 In the following example, we prepend *<install_dir>/lib* to ``LD_LIBRARY_PATH`` (note the *left first* underscore), append *<install_dir>/lib* to ``PYTHONPATH`` (note the *right last* underscore), and set ``LAPACK_ROOT_DIR`` to *<install_dir>*:
97 _LD_LIBRARY_PATH : $install_dir + $VARS.sep + "lib"
98 PYTHONPATH_ : $install_dir + $VARS.sep + "lib"
99 LAPACK_ROOT_DIR : $install_dir
102 It is possible to distinguish the build environment from the launch environment: use a subsection called *build* or *launch*. In the example below, ``LD_LIBRARY_PATH`` and ``PYTHONPATH`` are only modified at run time, not at compile time:
110 LAPACK_ROOT_DIR : $install_dir
114 LAPACK_ROOT_DIR : $install_dir
115 _LD_LIBRARY_PATH : $install_dir + $VARS.sep + "lib"
116 PYTHONPATH_ : $install_dir + $VARS.sep + "lib"
120 3. The last possibility is to set the environment with a python script. The script should be provided in the *products/env_scripts* directory of the sat project, and its name is specified in the environment section with the key ``environ.env_script``:
122 .. code-block:: python
126 env_script : 'lapack.py'
129 Please note that the two modes are complementary and are both taken into account.
130 Most of the time, the first mode is sufficient.
132 The second mode can be used when the environment has to be set programmatically.
133 The developer implements a handle (as a python method)
134 which is called by sat to set the environment.
137 .. code-block:: python
140 #!/usr/bin/env python
141 #-*- coding:utf-8 -*-
146 def set_env(env, prereq_dir, version):
147 env.set("TRUST_ROOT_DIR",prereq_dir)
148 env.prepend('PATH', os.path.join(prereq_dir, 'bin'))
149 env.prepend('PATH', os.path.join(prereq_dir, 'include'))
150 env.prepend('LD_LIBRARY_PATH', os.path.join(prereq_dir, 'lib'))
153 sat defines four handles:
155 * **set_env(env, prereq_dir, version)** : used at build and run time.
156 * **set_env_launch(env, prereq_dir, version)** : used only at run time (if defined!)
157 * **set_env_build(env, prereq_dir, version)** : used only at build time (if defined!)
158 * **set_native_env(env)** : used only for native products, at build and run time.