tcl catch syntax
Darren Weber
dweber at macports.org
Mon May 18 16:07:31 PDT 2009
On Mon, May 18, 2009 at 3:48 PM, Darren Weber <dweber at macports.org> wrote:
>
> The following works in tclsh:
>
> # Find all the example executables by parsing all the
> # CMakeLists.txt files within the src Examples path
> set exe {}
> foreach f [exec find ${worksrcpath}/Examples -name "CMakeLists.txt"] {
> catch {exec -ignorestderr grep -e "ADD_EXECUTABLE" ${f} } results
> options
> if {[dict get ${options} -code] == 0} {
> # Remove the string "ADD_EXECUTABLE(", with or without whitespace
> regsub -all "\[ \t\]*ADD_EXECUTABLE\[(\]\[ \t\]*" ${results} ""
> results
> # Remove the string ".cxx)", with or without whitespace
> regsub -all ".cxx\[ \t\]*\[)\]" ${results} "" results
> set exe [concat ${exe} ${results}]
> }
> }
>
>
> The idea here is to parse a file tree to pull out all the lines in files
> called "CMakeLists.txt" that contain the string "ADD_EXECUTABLES". The bash
> shell syntax using grep and sed is quite simple, but it get's messy when
> translated to tcl. Anyhow, it works in tclsh, but the destroot phase fails
> with this error:
>
> DEBUG: Executing proc-post-org.macports.destroot-destroot-2
> Error: Target org.macports.destroot returned: wrong # args: should be
> "catch command ?varName?"
> Warning: the following items did not execute (for InsightToolkit):
> org.macports.destroot
> Error: Status 1 encountered during processing.
>
>
> Here in the tcl 8.5 documentation, we have a different syntax that allows
> the "option" variable:
> http://www.tcl.tk/man/tcl8.5/TclCmd/catch.htm
>
> Where is this error about tcl syntax generated? Is this error tcl-version
> specific?
>
> Thanks, Darren
>
>
The following is another way of doing this without the option variable in
the catch statement:
set exe {}
foreach f [exec find ${worksrcpath}/Examples -name "CMakeLists.txt"]
{
catch {exec -ignorestderr grep -e "ADD_EXECUTABLE" ${f} }
results
if [expr ! [string match "*child process*" ${results}] ] {
# Remove the string "ADD_EXECUTABLE(", with or without
whitespace
regsub -all "\[ \t\]*ADD_EXECUTABLE\[(\]\[ \t\]*" ${results}
"" results
# Remove the string ".cxx)", with or without whitespace
regsub -all ".cxx\[ \t\]*\[)\]" ${results} "" results
set exe [concat ${exe} ${results}]
}
}
The destroot stage still fails, this time with a different error that is
almost impossible to track down:
Error: Target org.macports.destroot returned: list element in quotes
followed by ":" instead of space
Warning: the following items did not execute (for InsightToolkit):
org.macports.destroot
Error: Status 1 encountered during processing.
Where is this error coming from and how can I track it down?
Thanks in advance,
Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-dev/attachments/20090518/a6fd7114/attachment-0001.html>
More information about the macports-dev
mailing list