The MinGW.org Installation Manager Tool
Révision | e4629b2485a9cec9cd023de36a68a2ed8591cc51 (tree) |
---|---|
l'heure | 2012-02-21 06:08:05 |
Auteur | Keith Marshall <keithmarshall@user...> |
Commiter | Keith Marshall |
Propagate sysroot path settings to scripts via the environment.
@@ -1,3 +1,23 @@ | ||
1 | +2012-02-20 Keith Marshall <keithmarshall@users.sourceforge.net> | |
2 | + | |
3 | + Propagate sysroot path settings to scripts via the environment. | |
4 | + | |
5 | + * src/pkgbase.h (PKG_PUTENV_FLAGS_MASK): New constant; it maps... | |
6 | + (PKG_PUTENV_DIRSEP_MSW, PKG_PUTENV_DIRSEP_POSIX): ...these flags... | |
7 | + (PKG_PUTENV_SCAN_VARNAME, PKG_PUTENV_NAME_TOUPPER): ...and these; | |
8 | + they are used to specify optional behavioural choices for... | |
9 | + (pkgPutEnv): ...this new function; declare it. | |
10 | + | |
11 | + * src/sysroot.cpp (pkgPutEnv): Implement it. | |
12 | + (pkgXmlDocument::LoadSystemMap): Use it to add $SUBSYSTEM_SYSROOT path | |
13 | + specifications to the environment, for each named subsystem associated | |
14 | + with the active system map. | |
15 | + | |
16 | + * src/pkgexec.cpp (pkgActionItem::Execute): Invoke pkgPutEnv() prior | |
17 | + to processing of each package install, upgrade, or remove action, so | |
18 | + as to update environment variable $SYSROOT to represent the sysroot | |
19 | + path for each package processed, during execution of script hooks. | |
20 | + | |
1 | 21 | 2012-02-17 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 22 | |
3 | 23 | Implement hooks to support lua scripting interface. |
@@ -71,6 +71,19 @@ | ||
71 | 71 | # endif |
72 | 72 | #endif |
73 | 73 | |
74 | +/* Define an API for registering environment variables. | |
75 | + */ | |
76 | +EXTERN_C int pkgPutEnv( int, char* ); | |
77 | + | |
78 | +#define PKG_PUTENV_DIRSEP_MSW (0x01) | |
79 | +#define PKG_PUTENV_DIRSEP_POSIX (0x02) | |
80 | +#define PKG_PUTENV_SCAN_VARNAME (0x04) | |
81 | +#define PKG_PUTENV_NAME_TOUPPER (0x08) | |
82 | + | |
83 | +#define PKG_PUTENV_FLAGS_MASK (0x0F) | |
84 | + | |
85 | +/* Begin class declarations. | |
86 | + */ | |
74 | 87 | class pkgSpecs; |
75 | 88 | |
76 | 89 | class pkgXmlNode : public TiXmlElement |
@@ -4,7 +4,7 @@ | ||
4 | 4 | * $Id$ |
5 | 5 | * |
6 | 6 | * Written by Keith Marshall <keithmarshall@users.sourceforge.net> |
7 | - * Copyright (C) 2009, 2010, 2011, MinGW Project | |
7 | + * Copyright (C) 2009, 2010, 2011, 2012, MinGW Project | |
8 | 8 | * |
9 | 9 | * |
10 | 10 | * Implementation of package management task scheduler and executive. |
@@ -430,10 +430,36 @@ void pkgActionItem::Execute() | ||
430 | 430 | * be performed, identifying the package to be processed. |
431 | 431 | */ |
432 | 432 | const char *tarname; |
433 | - if( (tarname = current->Selection()->GetPropVal( tarname_key, NULL )) == NULL ) | |
434 | - tarname = current->Selection( to_remove )->GetPropVal( tarname_key, value_unknown ); | |
433 | + pkgXmlNode *ref = current->Selection(); | |
434 | + if( (tarname = ref->GetPropVal( tarname_key, NULL )) == NULL ) | |
435 | + { | |
436 | + ref = current->Selection( to_remove ); | |
437 | + tarname = ref->GetPropVal( tarname_key, value_unknown ); | |
438 | + } | |
435 | 439 | dmh_printf( "%s: %s\n", action_name(current->flags & ACTION_MASK), tarname ); |
436 | 440 | |
441 | + /* Package pre/post processing scripts may need to | |
442 | + * refer to the sysroot path for the package; place | |
443 | + * a copy in the environment, to facilitate this. | |
444 | + */ | |
445 | + pkgSpecs lookup( tarname ); | |
446 | + ref = ref->GetSysRoot( lookup.GetSubSystemName() ); | |
447 | + const char *path = ref->GetPropVal( pathname_key, NULL ); | |
448 | + if( path != NULL ) | |
449 | + { | |
450 | + /* Format the sysroot path into an environment variable | |
451 | + * assignment specification; note that the recorded path | |
452 | + * name is likely to include macros such as "%R", so we | |
453 | + * filter it through mkpath(), to expand them. | |
454 | + */ | |
455 | + const char *nothing = ""; | |
456 | + char varspec_template[9 + strlen( path )]; | |
457 | + sprintf( varspec_template, "SYSROOT=%s", path ); | |
458 | + char varspec[mkpath( NULL, varspec_template, nothing, NULL )]; | |
459 | + mkpath( varspec, varspec_template, nothing, NULL ); | |
460 | + pkgPutEnv( PKG_PUTENV_DIRSEP_MSW, varspec ); | |
461 | + } | |
462 | + | |
437 | 463 | /* Check for any outstanding requirement to invoke the |
438 | 464 | * "self upgrade rites" process, so that we may install an |
439 | 465 | * upgrade for mingw-get itself... |
@@ -113,7 +113,74 @@ static bool samepath( const char *tstpath, const char *refpath ) | ||
113 | 113 | return (*tstpath == *refpath); |
114 | 114 | } |
115 | 115 | |
116 | +EXTERN_C int pkgPutEnv( int flags, char *varspec ) | |
117 | +{ | |
118 | + /* A helper routine for registration of sysroot path to | |
119 | + * subsystem name mappings in the process environment, so | |
120 | + * that they propagate to pre/post-processing hooks. | |
121 | + */ | |
122 | + if( flags ) | |
123 | + { | |
124 | + /* The flags allow us to specify certain transformations | |
125 | + * to be applied to the varspec. | |
126 | + */ | |
127 | + char *ref = varspec; | |
128 | + flags |= PKG_PUTENV_SCAN_VARNAME; | |
129 | + do { if( (flags & PKG_PUTENV_NAME_TOUPPER) == PKG_PUTENV_NAME_TOUPPER ) | |
130 | + { | |
131 | + /* The PKG_PUTENV_NAME_TOUPPER flag specifies that the varname | |
132 | + * part of varspec may contain lower case characters, which are | |
133 | + * to be converted to their upper case equivalents, before they | |
134 | + * are stored in the environment... | |
135 | + */ | |
136 | + if( *ref == '=' ) | |
137 | + /* | |
138 | + * ...but such transformation does not apply to the value | |
139 | + * part, so stop it when we find the first '=' character, | |
140 | + * (which separates the name and value parts of varspec). | |
141 | + */ | |
142 | + flags &= ~(PKG_PUTENV_SCAN_VARNAME | PKG_PUTENV_NAME_TOUPPER); | |
143 | + | |
144 | + else | |
145 | + /* ...we haven't yet encountered the '=', so apply the | |
146 | + * transformation. | |
147 | + */ | |
148 | + *ref = toupper( *ref ); } | |
149 | + | |
150 | + else if( *ref == '=' ) | |
151 | + /* | |
152 | + * We may be doing case transformation on the varname, so | |
153 | + * note when we've passed the '=' which separates it from | |
154 | + * any assigned value. | |
155 | + */ | |
156 | + flags &= ~PKG_PUTENV_SCAN_VARNAME; | |
157 | + | |
158 | + /* Once we've reached the value part of varspec, flags which | |
159 | + * include the PKG_PUTENV_DIRSEP_MSW bit, but do not include | |
160 | + * the PKG_PUTENV_DIRSEP_POSIX bit, request that POSIX style | |
161 | + * directory separators are to be replaced by the MS-Windows | |
162 | + * '\' counterpart... | |
163 | + */ | |
164 | + if( ((flags & PKG_PUTENV_FLAGS_MASK) == PKG_PUTENV_DIRSEP_MSW) && | |
165 | + (*ref == '/') ) *ref = '\\'; | |
166 | + | |
167 | + /* ...while conversely, the PKG_PUTENV_DIRSEP_POSIX bit, | |
168 | + * (without PKG_PUTENV_DIRSEP_MSW), requests MS-Windows to | |
169 | + * POSIX style transformation. | |
170 | + */ | |
171 | + else if( ((flags & PKG_PUTENV_FLAGS_MASK) == PKG_PUTENV_DIRSEP_POSIX) | |
172 | + && (*ref == '\\') ) *ref = '/'; | |
173 | + | |
174 | + } while( *++ref ); } | |
175 | + | |
176 | + /* Finally, we insert the variable specification, (which may have | |
177 | + * been transformed above), into the process environment. | |
178 | + */ | |
179 | + return putenv( varspec ); | |
180 | +} | |
181 | + | |
116 | 182 | void pkgXmlDocument::LoadSystemMap() |
183 | +#define PKG_SYSROOT_OPTIONS (PKG_PUTENV_NAME_TOUPPER | PKG_PUTENV_DIRSEP_MSW) | |
117 | 184 | { |
118 | 185 | /* Load an initial, or a replacement, system map into the |
119 | 186 | * internal XML database image space. |
@@ -188,11 +255,31 @@ void pkgXmlDocument::LoadSystemMap() | ||
188 | 255 | && ! samepath( path, sysroot->GetPropVal( pathname_key, NULL )) ) |
189 | 256 | sysroot = sysroot->FindNextAssociate( sysroot_key ); |
190 | 257 | |
191 | - DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INIT ), | |
258 | + /* Identify the subsystem name, logging a trace notification | |
259 | + * when running with appropriate debugging traces enabled. | |
260 | + */ | |
261 | + const char *sysname = subsystem->GetPropVal( subsystem_key, NULL ); | |
262 | + DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INIT ), | |
192 | 263 | dmh_printf( "Bind subsystem %s: sysroot = %s\n", |
193 | - subsystem->GetPropVal( subsystem_key, "<unknown>" ), path | |
264 | + (sysname == NULL) ? value_unknown : sysname, | |
265 | + path | |
194 | 266 | )); |
195 | 267 | |
268 | + if( sysname != NULL ) | |
269 | + { | |
270 | + /* Register the associated sysroot in the process environment, | |
271 | + * so that it may become available to pre/post-processing hooks; | |
272 | + * note that the recorded path name is likely to include macros | |
273 | + * such as "%R", so we filter it through mkpath() to ensure | |
274 | + * that they are expanded. | |
275 | + */ | |
276 | + char varname_template[11 + strlen( path )]; | |
277 | + sprintf( varname_template, "%%F_SYSROOT=%s", path ); | |
278 | + char varname[mkpath( NULL, varname_template, sysname, NULL )]; | |
279 | + mkpath( varname, varname_template, sysname, NULL ); | |
280 | + pkgPutEnv( PKG_SYSROOT_OPTIONS, varname ); | |
281 | + } | |
282 | + | |
196 | 283 | if( sysroot == NULL ) |
197 | 284 | { |
198 | 285 | /* This sysroot has not yet been registered... |
@@ -309,10 +396,23 @@ void pkgXmlDocument::LoadSystemMap() | ||
309 | 396 | /* Finally, if the current system map was not loaded... |
310 | 397 | */ |
311 | 398 | if( to_clear != NULL ) |
312 | - /* | |
313 | - * ...then we delete its declaration from the active data space. | |
399 | + { | |
400 | + /* ...clean up its declaration data... | |
401 | + */ | |
402 | + const char *sysname = to_clear->GetPropVal( subsystem_key, NULL ); | |
403 | + if( sysname != NULL ) | |
404 | + { | |
405 | + /* ...deleting its sysroot registration entry, if any, | |
406 | + * from the process environment... | |
407 | + */ | |
408 | + char varname[9 + strlen( sysname )]; | |
409 | + sprintf( varname, "%s_SYSROOT", sysname ); | |
410 | + pkgPutEnv( PKG_PUTENV_NAME_TOUPPER, varname ); | |
411 | + } | |
412 | + /* ...and removing its reference from the active XML data space. | |
314 | 413 | */ |
315 | 414 | dbase->DeleteChild( to_clear ); |
415 | + } | |
316 | 416 | } |
317 | 417 | } |
318 | 418 |