Ignore:
Timestamp:
May 11, 2015, 9:00:32 PM (4 years ago)
Author:
larryv@…
Message:

muniversal-1.0: Refactor merger_target_provides

An attempt to escape quoting hell[1] by using a script template and
substituting salient values with string map[2].

[1] http://wiki.tcl.tk/1726
[2] http://wiki.tcl.tk/37332#pagetoc04c6ab3f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dports/_resources/port1.0/group/muniversal-1.0.tcl

    r136058 r136144  
    9595    # User-code exceptions are caught and returned as a result of the target.
    9696    # Thus if the user code breaks, dependent targets will not execute.
     97    set script_template {
     98        variable proc_index
     99        set proc_index [llength [ditem_key ${ditem} post]]
     100        set proc_name proc-merger-post-${ident}-${target}-$proc_index
     101        ditem_append ${ditem} merger-post $proc_name
     102        proc $proc_name name {
     103            set userproc_name user[lindex [info level 0] 0]
     104            if {[catch $userproc_name result]} {
     105                return -code error $result
     106            }
     107            return 0
     108        }
     109        makeuserproc user$proc_name $args
     110    }
    97111    foreach target $args {
    98         set origproc [ditem_key $ditem procedure]
    99112        set ident [ditem_key $ditem name]
    100         proc merger-post-$target {args} "
    101             variable proc_index
    102             set proc_index \[llength \[ditem_key $ditem post\]\]
    103             ditem_append $ditem merger-post proc-merger-post-${ident}-${target}-\${proc_index}
    104             proc proc-merger-post-${ident}-${target}-\${proc_index} {name} \"
    105                 if {\\\[catch userproc-merger-post-${ident}-${target}-\${proc_index} result\\\]} {
    106                     return -code error \\\$result
    107                 } else {
    108                     return 0
    109                 }
    110             \"
    111             makeuserproc userproc-merger-post-${ident}-${target}-\${proc_index} \$args
    112         "
     113        proc merger-post-$target args \
     114                [string map [list \${ditem} [list $ditem] \
     115                                  \${ident} [list $ident] \
     116                                  \${target} [list $target]] \
     117                            $script_template]
    113118    }
    114119}
Note: See TracChangeset for help on using the changeset viewer.