| 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 | package provide portutil 1.0 |
|---|
| 36 | package require Pextlib 1.0 |
|---|
| 37 | package require macports_dlist 1.0 |
|---|
| 38 | package require macports_util 1.0 |
|---|
| 39 | package require msgcat |
|---|
| 40 | package require porttrace 1.0 |
|---|
| 41 | |
|---|
| 42 | global targets target_uniqid all_variants |
|---|
| 43 | |
|---|
| 44 | set targets [list] |
|---|
| 45 | set target_uniqid 0 |
|---|
| 46 | |
|---|
| 47 | set all_variants [list] |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | namespace eval options { |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | proc option {name args} { |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | global $name |
|---|
| 65 | if {[llength $args] > 0} { |
|---|
| 66 | ui_debug "setting option $name to $args" |
|---|
| 67 | set $name [lindex $args 0] |
|---|
| 68 | } |
|---|
| 69 | return [set $name] |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | proc exists {name} { |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | global $name |
|---|
| 82 | return [info exists $name] |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | proc handle_option {option args} { |
|---|
| 91 | global $option user_options option_procs |
|---|
| 92 | |
|---|
| 93 | if {![info exists user_options($option)]} { |
|---|
| 94 | set $option $args |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | proc handle_option-append {option args} { |
|---|
| 104 | global $option user_options option_procs |
|---|
| 105 | |
|---|
| 106 | if {![info exists user_options($option)]} { |
|---|
| 107 | if {[info exists $option]} { |
|---|
| 108 | set $option [concat [set $option] $args] |
|---|
| 109 | } else { |
|---|
| 110 | set $option $args |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | proc handle_option-delete {option args} { |
|---|
| 121 | global $option user_options option_procs |
|---|
| 122 | |
|---|
| 123 | if {![info exists user_options($option)] && [info exists $option]} { |
|---|
| 124 | set temp [set $option] |
|---|
| 125 | foreach val $args { |
|---|
| 126 | set temp [ldelete $temp $val] |
|---|
| 127 | } |
|---|
| 128 | set $option $temp |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | proc options {args} { |
|---|
| 140 | foreach option $args { |
|---|
| 141 | interp alias {} $option {} handle_option $option |
|---|
| 142 | interp alias {} $option-append {} handle_option-append $option |
|---|
| 143 | interp alias {} $option-delete {} handle_option-delete $option |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | proc options::export {option action {value ""}} { |
|---|
| 154 | global $option PortInfo |
|---|
| 155 | switch $action { |
|---|
| 156 | set { |
|---|
| 157 | set PortInfo($option) $value |
|---|
| 158 | } |
|---|
| 159 | delete { |
|---|
| 160 | unset PortInfo($option) |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | proc options_export {args} { |
|---|
| 170 | foreach option $args { |
|---|
| 171 | option_proc $option options::export |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | proc option_proc {option args} { |
|---|
| 181 | global option_procs $option |
|---|
| 182 | if {[info exists option_procs($option)]} { |
|---|
| 183 | set option_procs($option) [concat $option_procs($option) $args] |
|---|
| 184 | |
|---|
| 185 | } else { |
|---|
| 186 | set option_procs($option) $args |
|---|
| 187 | trace add variable $option {read write unset} option_proc_trace |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | proc option_proc_trace {optionName index op} { |
|---|
| 194 | global option_procs |
|---|
| 195 | upvar $optionName $optionName |
|---|
| 196 | switch $op { |
|---|
| 197 | write { |
|---|
| 198 | foreach p $option_procs($optionName) { |
|---|
| 199 | $p $optionName set [set $optionName] |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | read { |
|---|
| 203 | foreach p $option_procs($optionName) { |
|---|
| 204 | $p $optionName read |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | unset { |
|---|
| 208 | foreach p $option_procs($optionName) { |
|---|
| 209 | if {[catch {$p $optionName delete} result]} { |
|---|
| 210 | ui_debug "error during unset trace ($p): $result\n$::errorInfo" |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | trace add variable $optionName {read write unset} option_proc_trace |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | proc commands {args} { |
|---|
| 222 | foreach option $args { |
|---|
| 223 | options use_${option} ${option}.dir ${option}.pre_args ${option}.args ${option}.post_args ${option}.env ${option}.type ${option}.cmd |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | proc command_string {command} { |
|---|
| 230 | global ${command}.dir ${command}.pre_args ${command}.args ${command}.post_args ${command}.cmd |
|---|
| 231 | |
|---|
| 232 | if {[info exists ${command}.dir]} { |
|---|
| 233 | append cmdstring "cd \"[set ${command}.dir]\" &&" |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | if {[info exists ${command}.cmd]} { |
|---|
| 237 | foreach string [set ${command}.cmd] { |
|---|
| 238 | append cmdstring " $string" |
|---|
| 239 | } |
|---|
| 240 | } else { |
|---|
| 241 | append cmdstring " ${command}" |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | foreach var "${command}.pre_args ${command}.args ${command}.post_args" { |
|---|
| 245 | if {[info exists $var]} { |
|---|
| 246 | foreach string [set ${var}] { |
|---|
| 247 | append cmdstring " ${string}" |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | ui_debug "Assembled command: '$cmdstring'" |
|---|
| 253 | return $cmdstring |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | proc command_exec {command args} { |
|---|
| 262 | global ${command}.env ${command}.env_array env |
|---|
| 263 | set notty 0 |
|---|
| 264 | set command_prefix "" |
|---|
| 265 | set command_suffix "" |
|---|
| 266 | |
|---|
| 267 | if {[llength $args] > 0} { |
|---|
| 268 | if {[lindex $args 0] == "-notty"} { |
|---|
| 269 | set notty 1 |
|---|
| 270 | set args [lrange $args 1 end] |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if {[llength $args] > 0} { |
|---|
| 274 | set command_prefix [lindex $args 0] |
|---|
| 275 | if {[llength $args] > 1} { |
|---|
| 276 | set command_suffix [lindex $args 1] |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | if {![array exists ${command}.env_array]} { |
|---|
| 287 | parse_environment ${command} |
|---|
| 288 | } |
|---|
| 289 | if {[option macosx_deployment_target] ne ""} { |
|---|
| 290 | set ${command}.env_array(MACOSX_DEPLOYMENT_TARGET) [option macosx_deployment_target] |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | ui_debug "Environment: [environment_array_to_string ${command}.env_array]" |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | set cmdstring [command_string ${command}] |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | array set saved_env [array get env] |
|---|
| 303 | |
|---|
| 304 | array set env [array get ${command}.env_array] |
|---|
| 305 | |
|---|
| 306 | set fullcmdstring "$command_prefix $cmdstring $command_suffix" |
|---|
| 307 | if {$notty} { |
|---|
| 308 | set code [catch {system -notty $fullcmdstring} result] |
|---|
| 309 | } else { |
|---|
| 310 | set code [catch {system $fullcmdstring} result] |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | array unset ${command}.env_array |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | array unset env * |
|---|
| 317 | unsetenv * |
|---|
| 318 | array set env [array get saved_env] |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | return -code $code $result |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | proc default {option val} { |
|---|
| 329 | global $option option_defaults |
|---|
| 330 | if {[info exists option_defaults($option)]} { |
|---|
| 331 | ui_debug "Re-registering default for $option" |
|---|
| 332 | |
|---|
| 333 | trace vdelete $option rwu default_check |
|---|
| 334 | } else { |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | if {[info exists $option]} { |
|---|
| 338 | return |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | set option_defaults($option) $val |
|---|
| 342 | set $option $val |
|---|
| 343 | trace variable $option rwu default_check |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | proc default_check {optionName index op} { |
|---|
| 350 | global option_defaults $optionName |
|---|
| 351 | switch $op { |
|---|
| 352 | w { |
|---|
| 353 | unset option_defaults($optionName) |
|---|
| 354 | trace vdelete $optionName rwu default_check |
|---|
| 355 | return |
|---|
| 356 | } |
|---|
| 357 | r { |
|---|
| 358 | upvar $optionName option |
|---|
| 359 | uplevel |
|---|
| 360 | return |
|---|
| 361 | } |
|---|
| 362 | u { |
|---|
| 363 | unset option_defaults($optionName) |
|---|
| 364 | trace vdelete $optionName rwu default_check |
|---|
| 365 | return |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | proc variant {args} { |
|---|
| 373 | global all_variants PortInfo porturl |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | if {![info exists PortInfo(vinfo)]} { |
|---|
| 384 | set PortInfo(vinfo) {} |
|---|
| 385 | } |
|---|
| 386 | array set vinfo $PortInfo(vinfo) |
|---|
| 387 | |
|---|
| 388 | set len [llength $args] |
|---|
| 389 | set code [lindex $args end] |
|---|
| 390 | set args [lrange $args 0 [expr $len - 2]] |
|---|
| 391 | |
|---|
| 392 | set ditem [variant_new "temp-variant"] |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | set mode "provides" |
|---|
| 399 | foreach arg $args { |
|---|
| 400 | switch -exact $arg { |
|---|
| 401 | description - |
|---|
| 402 | provides - |
|---|
| 403 | requires - |
|---|
| 404 | conflicts { set mode $arg } |
|---|
| 405 | default { ditem_append $ditem $mode $arg } |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | ditem_key $ditem name "[join [ditem_key $ditem provides] -]" |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | makeuserproc "variant-[ditem_key $ditem name]" \{$code\} |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | set variant_provides [ditem_key $ditem provides] |
|---|
| 418 | if {[variant_exists $variant_provides]} { |
|---|
| 419 | |
|---|
| 420 | variant_remove_ditem $variant_provides |
|---|
| 421 | } else { |
|---|
| 422 | |
|---|
| 423 | if {![info exists vinfo($variant_provides)]} { |
|---|
| 424 | set vinfo($variant_provides) {} |
|---|
| 425 | } |
|---|
| 426 | array set variant $vinfo($variant_provides) |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | set vconflicts [join [lsort [ditem_key $ditem conflicts]]] |
|---|
| 430 | if {$vconflicts ne ""} { |
|---|
| 431 | array set variant [list conflicts $vconflicts] |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | lappend PortInfo(variants) $variant_provides |
|---|
| 435 | set vdesc [join [ditem_key $ditem description]] |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | if {$vdesc == ""} { |
|---|
| 439 | set vdesc [variant_desc $porturl $variant_provides] |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | if {$vdesc ne ""} { |
|---|
| 444 | array set variant [list description $vdesc] |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | lappend PortInfo(variant_desc) $variant_provides $vdesc |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | set vrequires [join [lsort [ditem_key $ditem requires]]] |
|---|
| 452 | if {$vrequires ne ""} { |
|---|
| 453 | array set variant [list requires $vrequires] |
|---|
| 454 | } |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | array set vinfo [list $variant_provides [array get variant]] |
|---|
| 459 | set PortInfo(vinfo) [array get vinfo] |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | lappend all_variants $ditem |
|---|
| 463 | } |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | proc variant_isset {name} { |
|---|
| 468 | global variations |
|---|
| 469 | |
|---|
| 470 | if {[info exists variations($name)] && $variations($name) == "+"} { |
|---|
| 471 | return 1 |
|---|
| 472 | } |
|---|
| 473 | return 0 |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | proc variant_set {name} { |
|---|
| 479 | global variations |
|---|
| 480 | set variations($name) + |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | proc variant_unset {name} { |
|---|
| 486 | global variations |
|---|
| 487 | |
|---|
| 488 | set variations($name) - |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | proc variant_undef {name} { |
|---|
| 494 | global variations PortInfo |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | array unset variations $name |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | if {[info exists PortInfo(variants)]} { |
|---|
| 501 | set variant_index [lsearch -exact $PortInfo(variants) $name] |
|---|
| 502 | if {$variant_index >= 0} { |
|---|
| 503 | set new_list [lreplace $PortInfo(variants) $variant_index $variant_index] |
|---|
| 504 | if {"$new_list" == {}} { |
|---|
| 505 | unset PortInfo(variants) |
|---|
| 506 | } else { |
|---|
| 507 | set PortInfo(variants) $new_list |
|---|
| 508 | } |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | variant_remove_ditem $name |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | proc variant_remove_ditem {name} { |
|---|
| 519 | global all_variants |
|---|
| 520 | set item_index 0 |
|---|
| 521 | foreach variant_item $all_variants { |
|---|
| 522 | set item_provides [ditem_key $variant_item provides] |
|---|
| 523 | if {$item_provides == $name} { |
|---|
| 524 | set all_variants [lreplace $all_variants $item_index $item_index] |
|---|
| 525 | break |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | incr item_index |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | proc variant_exists {name} { |
|---|
| 535 | global PortInfo |
|---|
| 536 | if {[info exists PortInfo(variants)] && |
|---|
| 537 | [lsearch -exact $PortInfo(variants) $name] >= 0} { |
|---|
| 538 | return 1 |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | return 0 |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | proc variant_desc {porturl variant} { |
|---|
| 551 | global variant_descs_global |
|---|
| 552 | |
|---|
| 553 | set descfile [getportresourcepath $porturl "port1.0/variant_descriptions.conf"] |
|---|
| 554 | if {![info exists variant_descs_global($descfile)]} { |
|---|
| 555 | set variant_descs_global($descfile) yes |
|---|
| 556 | |
|---|
| 557 | if {[file exists $descfile]} { |
|---|
| 558 | if {[catch {set fd [open $descfile r]} err]} { |
|---|
| 559 | ui_warn "Could not open global variant description file: $err" |
|---|
| 560 | return "" |
|---|
| 561 | } |
|---|
| 562 | set lineno 0 |
|---|
| 563 | while {[gets $fd line] >= 0} { |
|---|
| 564 | incr lineno |
|---|
| 565 | set name [lindex $line 0] |
|---|
| 566 | set desc [lindex $line 1] |
|---|
| 567 | if {$name != "" && $desc != ""} { |
|---|
| 568 | set variant_descs_global(${descfile}_$name) $desc |
|---|
| 569 | } else { |
|---|
| 570 | ui_warn "Invalid variant description in $descfile at line $lineno" |
|---|
| 571 | } |
|---|
| 572 | } |
|---|
| 573 | close $fd |
|---|
| 574 | } |
|---|
| 575 | } |
|---|
| 576 | |
|---|
| 577 | if {[info exists variant_descs_global(${descfile}_${variant})]} { |
|---|
| 578 | return $variant_descs_global(${descfile}_${variant}) |
|---|
| 579 | } else { |
|---|
| 580 | return "" |
|---|
| 581 | } |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | proc platform {args} { |
|---|
| 589 | global all_variants PortInfo os.platform os.arch os.version os.major |
|---|
| 590 | |
|---|
| 591 | set len [llength $args] |
|---|
| 592 | set code [lindex $args end] |
|---|
| 593 | set os [lindex $args 0] |
|---|
| 594 | set args [lrange $args 1 [expr $len - 2]] |
|---|
| 595 | |
|---|
| 596 | set ditem [variant_new "temp-variant"] |
|---|
| 597 | |
|---|
| 598 | foreach arg $args { |
|---|
| 599 | if {[regexp {(^[0-9]+$)} $arg match result]} { |
|---|
| 600 | set release $result |
|---|
| 601 | } elseif {[regexp {([a-zA-Z0-9]*)} $arg match result]} { |
|---|
| 602 | set arch $result |
|---|
| 603 | } |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | set platform $os |
|---|
| 608 | if {[info exists release]} { set platform ${platform}_${release} } |
|---|
| 609 | if {[info exists arch]} { set platform ${platform}_${arch} } |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | if {[variant_exists $platform]} { |
|---|
| 613 | set suffix 1 |
|---|
| 614 | while {[variant_exists "$platform-$suffix"]} { |
|---|
| 615 | incr suffix |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | set platform "$platform-$suffix" |
|---|
| 619 | } |
|---|
| 620 | variant $platform $code |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | set matches 1 |
|---|
| 624 | if {[info exists os.platform] && ${os.platform} == $os} { |
|---|
| 625 | set sel_platform $os |
|---|
| 626 | if {[info exists os.major] && [info exists release]} { |
|---|
| 627 | if {${os.major} == $release } { |
|---|
| 628 | set sel_platform ${sel_platform}_${release} |
|---|
| 629 | } else { |
|---|
| 630 | set matches 0 |
|---|
| 631 | } |
|---|
| 632 | } |
|---|
| 633 | if {$matches == 1 && [info exists arch] && [info exists os.arch]} { |
|---|
| 634 | if {${os.arch} == $arch} { |
|---|
| 635 | set sel_platform ${sel_platform}_${arch} |
|---|
| 636 | } else { |
|---|
| 637 | set matches 0 |
|---|
| 638 | } |
|---|
| 639 | } |
|---|
| 640 | if {$matches == 1} { |
|---|
| 641 | variant_set $sel_platform |
|---|
| 642 | } |
|---|
| 643 | } |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | proc parse_environment {command} { |
|---|
| 651 | global ${command}.env ${command}.env_array |
|---|
| 652 | |
|---|
| 653 | if {[info exists ${command}.env]} { |
|---|
| 654 | |
|---|
| 655 | set the_environment [join [set ${command}.env]] |
|---|
| 656 | |
|---|
| 657 | while {[regexp "^(?: *)(\[^= \]+)=(\"|'|)(\[^\"'\]*?)\\2(?: +|$)(.*)$" ${the_environment} matchVar key delimiter value remaining]} { |
|---|
| 658 | set the_environment ${remaining} |
|---|
| 659 | set ${command}.env_array(${key}) ${value} |
|---|
| 660 | } |
|---|
| 661 | } else { |
|---|
| 662 | array set ${command}.env_array {} |
|---|
| 663 | } |
|---|
| 664 | } |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | proc append_to_environment_value {command key value} { |
|---|
| 669 | global ${command}.env_array |
|---|
| 670 | |
|---|
| 671 | if {[string length $value] == 0} { |
|---|
| 672 | return |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | |
|---|
| 676 | set append_value $value |
|---|
| 677 | if {[regexp {^("|')(.*)\1$} $append_value matchVar append_delim matchedValue]} { |
|---|
| 678 | set append_value $matchedValue |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | if {[info exists ${command}.env_array($key)]} { |
|---|
| 682 | set original_value [set ${command}.env_array($key)] |
|---|
| 683 | set ${command}.env_array($key) "${original_value} ${append_value}" |
|---|
| 684 | } else { |
|---|
| 685 | set ${command}.env_array($key) $append_value |
|---|
| 686 | } |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | # Append several items to a value in the parsed environment. |
|---|
| 690 | proc append_list_to_environment_value {command key vallist} { |
|---|
| 691 | foreach {value} $vallist { |
|---|
| 692 | append_to_environment_value ${command} $key $value |
|---|
| 693 | } |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | # Build the environment as a string. |
|---|
| 697 | # Remark: this method is only used for debugging purposes. |
|---|
| 698 | proc environment_array_to_string {environment_array} { |
|---|
| 699 | upvar 1 ${environment_array} env_array |
|---|
| 700 | |
|---|
| 701 | set theString "" |
|---|
| 702 | foreach {key value} [array get env_array] { |
|---|
| 703 | if {$theString == ""} { |
|---|
| 704 | set theString "$key='$value'" |
|---|
| 705 | } else { |
|---|
| 706 | set theString "${theString} $key='$value'" |
|---|
| 707 | } |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | return $theString |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | ########### Distname utility functions ########### |
|---|
| 714 | |
|---|
| 715 | # Given a distribution file name, return the appended tag |
|---|
| 716 | # Example: getdisttag distfile.tar.gz:tag1 returns "tag1" |
|---|
| 717 | # / isn't included in the regexp, thus allowing port specification in URLs. |
|---|
| 718 | proc getdisttag {name} { |
|---|
| 719 | if {[regexp {.+:([0-9A-Za-z_-]+)$} $name match tag]} { |
|---|
| 720 | return $tag |
|---|
| 721 | } else { |
|---|
| 722 | return "" |
|---|
| 723 | } |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | # Given a distribution file name, return the name without an attached tag |
|---|
| 727 | # Example : getdistname distfile.tar.gz:tag1 returns "distfile.tar.gz" |
|---|
| 728 | # / isn't included in the regexp, thus allowing port specification in URLs. |
|---|
| 729 | proc getdistname {name} { |
|---|
| 730 | regexp {(.+):[0-9A-Za-z_-]+$} $name match name |
|---|
| 731 | return $name |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | |
|---|
| 735 | ########### Misc Utility Functions ########### |
|---|
| 736 | |
|---|
| 737 | # tbool (testbool) |
|---|
| 738 | # If the variable exists in the calling procedure's namespace |
|---|
| < |
|---|