]> SALOME platform Git repositories - tools/sat.git/blob - doc/src/commands/environ.rst
Salome HOME
ad52dc7f548a915ea0f14d6d812c1eac7dd8cc01
[tools/sat.git] / doc / src / commands / environ.rst
1
2 .. include:: ../../rst_prolog.rst
3
4 Command environ
5 ****************
6
7 Description
8 ===========
9 The **environ** command generates the environment files used 
10 to run and compile your application (as SALOME_ is an example).
11
12 .. note :: 
13    these files are **not** required, 
14    salomeTool set the environment himself, when compiling.
15    And so does the salome launcher.
16
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*.
19
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.
23
24 Usage
25 =====
26 * Create the shell environment files of the application: ::
27
28     sat environ <application>
29
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_): ::
32
33     sat environ <application> --shell [bash|bat|cfg|tcl|all]
34
35 * Use a different prefix for the files (default is 'env'):
36
37   .. code-block:: bash
38
39     # This will create file <prefix>_launch.sh, <prefix>_build.sh
40     sat environ <application> --prefix <prefix>
41
42 * Use a different target directory for the files:
43
44   .. code-block:: bash
45
46     # This will create file env_launch.sh, env_build.sh
47     # in the directory corresponding to <path>
48     sat environ <application> --target <path>
49
50 * Generate the environment files only with the given products:
51
52   .. code-block:: bash
53
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>, ...
59
60 * Generate tcl modules for use with *environment-modules* package. 
61
62   .. code-block:: bash
63
64     sat environ <application> --shell tcl
65
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*.
68
69   .. code-block:: bash
70
71     APPLICATION :
72     {
73         ...
74         # trigger the production of a environment module base which name is salome9
75         base : 'salome9'
76     }
77
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*.
80
81 Configuration
82 =============
83
84 The specification of the environment can be done through several mechanisms.
85
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.
87
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 wil be used to set the environment programmatically.
89
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>*:
92
93 .. code-block:: bash
94
95     environ :
96     {
97       _LD_LIBRARY_PATH : $install_dir + $VARS.sep + "lib"
98       PYTHONPATH_ : $install_dir + $VARS.sep + "lib"
99       LAPACK_ROOT_DIR : $install_dir
100     }
101
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:
103
104 .. code-block:: bash
105
106     environ :
107     {
108       build :
109       {
110         LAPACK_ROOT_DIR : $install_dir
111       }
112       launch :
113       {
114         LAPACK_ROOT_DIR : $install_dir
115         _LD_LIBRARY_PATH : $install_dir + $VARS.sep + "lib"
116         PYTHONPATH_ : $install_dir + $VARS.sep + "lib"
117       }
118     }
119
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``:
121
122 .. code-block:: python
123
124     environ :
125     {
126       env_script : 'lapack.py'  
127     }
128
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.
131
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.
135 Here is an example:
136
137 .. code-block:: python
138
139
140     #!/usr/bin/env python
141     #-*- coding:utf-8 -*-
142
143     import os.path
144     import platform
145
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'))
151         return
152
153 SalomeTools defines four handles:
154
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.
159