Salome HOME
26467471bf445602c95cc3d44f9e06d8d1e49566
[tools/sat.git] / doc / src / commands / environ.rst
1
2 Command environ
3 ****************
4
5 Description
6 ===========
7 The **environ** command generates the environment files used to run and compile SALOME.
8 Please note that these files are not required any more, 
9 salomeTool set the environment himself, when compiling.
10 And so does the salome launcher.
11 These files are useful when someone wants to check the environment.
12 They could be used in debug mode to set the environment for gdb.
13 The configuration part at the end of this page explains how 
14 to specify the environment which will be used by sat (at build or run time), 
15 and which is written in files by sat environ command.
16
17 Usage
18 =====
19 * Create the (sh) environment files of the application: ::
20
21     sat environ <application>
22
23 * Create the environment files of the application for a given shell. 
24   Options are bash, bat (for windows) and cfg (the configuration format used by salomé): ::
25
26     sat environ <application> --shell [bash|cfg|all]
27
28 * Use a different prefix for the files (default is 'env'): ::
29
30     sat environ <application> --prefix <prefix>
31     This will create file <prefix>_launch.sh, <prefix>_build.sh...
32
33 * Use a different target directory for the files: ::
34
35     sat environ <application> --target <path>
36     This will create file env_launch.sh, env_build.sh... in the directory corresponding to <path>
37
38 * Generate the environment files only with the given products: ::
39
40     sat environ <application> --product <product1> --product <product2> ....
41     This will create the environment files only for the given products and their prerequisites.
42     It is useful when you want to visualise which environment uses sat to compile a given product.
43
44
45 Configuration
46 =============
47 The specification of the environment can be done through sevaral mechanisms.
48
49 1. For salome products (the products with the property is_SALOME_module : "yes") the environment is set automatically by sat, in respect with Salomé requirements.
50
51 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.
52
53 Within the section, the user can define environment variables. He can also modify PATH variables, by appending or prepending directories.
54 In the following example, we prepend <install_dir>/lib to LD_LIBRARY_PATH (note the underscore before), append <install_dir>/lib to PYTHONPATH (the underscore is after!), and set LAPACK_ROOT_DIR  to <install_dir>: ::
55
56     environ :
57     {
58        _LD_LIBRARY_PATH : $install_dir + $VARS.sep + "lib"
59        PYTHONPATH_ : $install_dir + $VARS.sep + "lib"
60        LAPACK_ROOT_DIR : $install_dir
61     }
62
63 It is possible here to distinguish the build environment from the launch environment. For that, 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: ::
64
65     environ :
66     {
67         build
68         {
69             LAPACK_ROOT_DIR : $install_dir
70         }
71         launch
72         {
73             LAPACK_ROOT_DIR : $install_dir
74            _LD_LIBRARY_PATH : $install_dir + $VARS.sep + "lib"
75            PYTHONPATH_ : $install_dir + $VARS.sep + "lib"
76         }
77     }
78
79 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 **env_script**: ::
80
81     environ :
82     {
83         env_script : "lapack.py"   
84     }
85
86 Please note that the two modes are complementary and are both taken into account.
87 Most of the time, the first mode is sufficient. The second mode can be used when the environment has to be set programmatically.
88 Here is an example: ::
89
90     #!/usr/bin/env python
91     #-*- coding:utf-8 -*-
92
93     import os.path
94     import platform
95
96     def set_env(env, prereq_dir, version):
97         env.set("TRUST_ROOT_DIR",prereq_dir)
98         env.prepend('PATH', os.path.join(prereq_dir, 'bin'))
99         env.prepend('PATH', os.path.join(prereq_dir, 'include'))
100         env.prepend('LD_LIBRARY_PATH', os.path.join(prereq_dir, 'lib'))
101         pass
102
103 The developer implements a handle which is called by sat to set the environment.
104 sat defines four handles:
105
106 * *set_env(env, prereq_dir, version)* : used at build and run time. 
107 * *set_env_launch(env, prereq_dir, version)* : used only at run time (if defined!)
108 * *set_env_build(env, prereq_dir, version)* : used only at build time (if defined!)
109 * *set_native_env(env)* : used only for native products, at build and run time.