1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
<!--
__COPYRIGHT__
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<para>
When &SCons; builds a target file,
it does not execute the commands with
the same external environment
that you used to execute &SCons;.
Instead, it uses the dictionary
stored in the &cv-link-ENV; construction variable
as the external environment
for executing commands.
</para>
<para>
The most important ramification of this behavior
is that the &PATH; environment variable,
which controls where the operating system
will look for commands and utilities,
is not the same as in the external environment
from which you called &SCons;.
This means that &SCons; will not, by default,
necessarily find all of the tools
that you can execute from the command line.
</para>
<para>
The default value of the &PATH; environment variable
on a POSIX system
is <literal>/usr/local/bin:/bin:/usr/bin</literal>.
The default value of the &PATH; environment variable
on a Windows system comes from the Windows registry
value for the command interpreter.
If you want to execute any commands--compilers, linkers, etc.--that
are not in these default locations,
you need to set the &PATH; value
in the &cv-ENV; dictionary
in your construction environment.
</para>
<para>
The simplest way to do this is to initialize explicitly
the value when you create the construction environment;
this is one way to do that:
</para>
<programlisting>
path = ['/usr/local/bin', '/bin', '/usr/bin']
env = Environment(ENV = {'PATH' : path})
</programlisting>
<para>
Assign a dictionary to the &cv-ENV;
construction variable in this way
completely resets the external environment
so that the only variable that will be
set when external commands are executed
will be the &PATH; value.
If you want to use the rest of
the values in &cv-ENV; and only
set the value of &PATH;,
the most straightforward way is probably:
</para>
<programlisting>
env['ENV']['PATH'] = ['/usr/local/bin', '/bin', '/usr/bin']
</programlisting>
<para>
Note that &SCons; does allow you to define
the directories in the &PATH; in a string,
separated by the pathname-separator character
for your system (':' on POSIX systems, ';' on Windows):
</para>
<programlisting>
env['ENV']['PATH'] = '/usr/local/bin:/bin:/usr/bin'
</programlisting>
<para>
But doing so makes your &SConscript; file less portable,
(although in this case that may not be a huge concern
since the directories you list are likley system-specific, anyway).
</para>
<!--
<scons_example name="ex1">
<file name="SConstruct" printme="1">
env = Environment()
env.Command('foo', [], '__ROOT__/usr/bin/printenv.py')
</file>
<file name="__ROOT__/usr/bin/printenv.py" chmod="0755">
#!/usr/bin/env python
import os
import sys
if len(sys.argv) > 1:
keys = sys.argv[1:]
else:
keys = os.environ.keys()
keys.sort()
for key in keys:
print " " + key + "=" + os.environ[key]
</file>
</scons_example>
<para>
</para>
<scons_output example="ex1">
<scons_output_command>scons -Q</scons_output_command>
</scons_output>
-->
<section>
<title>Propagating &PATH; From the External Environment</title>
<para>
You may want to propagate the external &PATH;
to the execution environment for commands.
You do this by initializing the &PATH;
variable with the &PATH; value from
the <literal>os.environ</literal>
dictionary,
which is Python's way of letting you
get at the external environment:
</para>
<programlisting>
import os
env = Environment(ENV = {'PATH' : os.environ['PATH']})
</programlisting>
<para>
Alternatively, you may find it easier
to just propagate the entire external
environment to the execution environment
for commands.
This is simpler to code than explicity
selecting the &PATH; value:
</para>
<programlisting>
import os
env = Environment(ENV = os.environ)
</programlisting>
<para>
Either of these will guarantee that
&SCons; will be able to execute
any command that you can execute from the command line.
The drawback is that the build can behave
differently if it's run by people with
different &PATH; values in their environment--for example,
both the <literal>/bin</literal> and
<literal>/usr/local/bin</literal> directories
have different &cc; commands,
then which one will be used to compile programs
will depend on which directory is listed
first in the user's &PATH; variable.
</para>
</section>
|