port-tclsh script for checking if tests exist

Clemens Lang cal at macports.org
Mon Aug 12 14:19:45 UTC 2019


Hi,

----- On 12 Aug, 2019, at 14:30, Artur Szostak aszostak at partner.eso.org wrote:

> Could someone with more knowledge please indicate how to test if a Portfile has
> the test phase coded in Tcl. I need to pragmatically check if a Portfile has
> either the test.run set to 'yes' or if the 'test {}' code block exists in a
> Portfile. I was trying to prepare a script to run in port-tclsh, by deciphering
> what the MacPorts code is doing. But without the design documents, trying to
> reverse engineer this is proving to be a challenge.

It's probably complicated to check whether the test {} block is set, but checking
whether test.run is yes should be simple enough.

The most recent examples of using the macports1.0 API are available from in our
build automation scripts at [1]. Specifically, [2] might be helpful: You can keep
almost the entire script as-is, but only replace the
  $workername eval get_portimage_path
statement at the end. Everything you put after the "eval" will run in the Portfile
context, i.e. just as if you were putting it directly into a Portfile. test.run is
what MacPorts calls an "option" [3]. Options are implemented as global variables
(inside the Portfile context), which gives you two methods to access them: Either
by using
  [option test.run]
or using
  ${test.run}.

Additionally, you can re-use the same approach [4] uses to test whether test.run is
true:
  puts [$workername eval {tbool test.run}]
should give you what you want (although I'm not sure on the quoting of the argument
of eval).


 [1] https://github.com/macports/mpbb/blob/master/tools/
 [2] https://github.com/macports/mpbb/blob/master/tools/archive-path.tcl
 [3] https://github.com/macports/macports-base/blob/master/src/port1.0/porttest.tcl#L16
 [4] https://github.com/macports/macports-base/blob/master/src/port1.0/porttest.tcl#L34


HTH,
-- 
Clemens Lang


More information about the macports-users mailing list