OpenROAD icon indicating copy to clipboard operation
OpenROAD copied to clipboard

Make `info script` return path to script executing

Open oharboe opened this issue 1 year ago • 10 comments

Description

$ cat blah.tcl
puts "Script running: [info script]"
$ tclsh blah.tcl 
Script running: blah.tcl
$ openroad -exit blah.tcl
OpenROAD v2.0-14658-gd48987e36 
[deleted]
Script running: 

Use case:

Implement the following source idiom to remove dependency on pwd, just like #include "foo.h" in C++ that includes the foo.h in the same folder as the compilation unit.

source [file dirname [info script]]/util.tcl

Suggested Solution

Reduce surprises, make info script return same as for tclsh

Additional Context

No response

oharboe avatar Jul 22 '24 12:07 oharboe

Looks like the problem is that Tcl_Eval instead of Tcl_EvalFile is used.

oharboe avatar Jul 22 '24 18:07 oharboe

where?

maliberty avatar Jul 22 '24 18:07 maliberty

where?

https://github.com/The-OpenROAD-Project/OpenSTA/blob/1c7f022cd0a02ce71d047aa3dbb64e924b6efbd5/app/StaMain.cc#L95

oharboe avatar Jul 22 '24 18:07 oharboe

So not an openroad issue but an sta one

maliberty avatar Jul 22 '24 18:07 maliberty

So not an openroad issue but an sta one

I wouldn't say so. It is the choice of OpenROAD to use "source ..." instead of Tcl_EvalFile(). This choice is encoded into the OpenROAD GUI code:

https://github.com/The-OpenROAD-Project/OpenROAD/blob/0e7dcb1f9100f6667a7d76a39f7d2f0a43749b17/src/Main.cc#L395

https://github.com/The-OpenROAD-Project/OpenROAD/blob/0e7dcb1f9100f6667a7d76a39f7d2f0a43749b17/src/Main.cc#L441

https://github.com/The-OpenROAD-Project/OpenROAD/blob/0e7dcb1f9100f6667a7d76a39f7d2f0a43749b17/src/Main.cc#L401

https://github.com/The-OpenROAD-Project/OpenROAD/blob/0e7dcb1f9100f6667a7d76a39f7d2f0a43749b17/src/Main.cc#L433

oharboe avatar Jul 23 '24 06:07 oharboe

If #5427 and #5428 are merged, then the remaining failing case for info script is when the GUI is enabled, which I think is a somewhat marginal use-case(info script is most critical in batch processing) that can be fixed eventually by someone who has a need for it.

$ cat blah.tcl
puts "Script running: [info script]"
$ tclsh blah.tcl 
Script running: blah.tcl
$ openroad -gui -exit blah.tcl
OpenROAD v2.0-14658-gd48987e36 
[deleted]
Script running: 

Expected output can be seen in non-gui case:

$ openroad -exit blah.tcl
OpenROAD v2.0-14711-ga257a8578 
Features included (+) or not (-): +Charts +GPU +GUI +Python
This program is licensed under the BSD-3 license. See the LICENSE file for details.
Components of this program may be licensed under more restrictive licenses which must be honored.
Script running: blah.tcl

oharboe avatar Jul 23 '24 09:07 oharboe

When I asked 'where' you pointed to StaMain.cc but all your subsequent PRs are unrelated to that. Was that a red herring?

maliberty avatar Jul 23 '24 13:07 maliberty

Sort of. The fn I referred to was a banal call and error reporting, so I duplicated it and changed to Tcl_EvalFile().

However @gadfort pointed out the the tcl "source" language feature has been monkeypatched to add some logging and verbosity features(not uniquely better on for instance error reporting compared to tcl).

oharboe avatar Jul 23 '24 14:07 oharboe

@oharboe I think something like: https://github.com/gadfort/OpenSTA/commit/f467add240f120768aeb6478e6b650b8d26945c9 will solve the issue. This ensures the file is set before the "virtual" source is called and reset at the end.

gadfort avatar Jul 23 '24 21:07 gadfort

@oharboe I think something like: gadfort/OpenSTA@f467add will solve the issue. This ensures the file is set before the "virtual" source is called and reset at the end.

Makes sense... I want to hear on #5436 before forming an opinion... If OpenSTA grows a batch mode where it doesn't introduce features into or change tcl then for my part that solves the issues. My main concern is automated/scripted mode. In the GUI(including REPL console mode), I'm not particularly concerned about the fine details of tcl, there is a human there to intervene when it comes to the userinterface works.

oharboe avatar Jul 24 '24 04:07 oharboe

Fixed upstream and will be in the next update

maliberty avatar Feb 02 '25 00:02 maliberty

Fixed upstream and will be in the next update

@hovind FYI

oharboe avatar Feb 02 '25 08:02 oharboe