[Omake] Confirmation dialog

Aleksey Nogin anogin at hrl.com
Mon Feb 18 09:39:22 PST 2008


On 18.02.2008 03:30, Andrew Gacek wrote:

> This code works nicely, but I have two more questions/issues.
> 
> 1) If I change confirm to be a no argument function, then it is
> executed twice when building the test target.

This is an expected consequence of how we do things, but IMHO should 
nevertheless be considered a bug. I've filed 
http://bugzilla.metaprl.org/show_bug.cgi?id=713 on this.

> 2) I would prefer to prompt the user for confirmation before doing any
> build work. For example, suppose the test target above depended on
> building some large-file.zip. I tried to make a separate dependency
> called confirm which handled this, but I was not able to ensure that
> it would be the first dependency built.
> 
What you need to do is to make sure that the confirmation happens at 
rule expansion time, not at rule execution time. One of the easiest ways 
is to use active rules. For example, the following works for me:

---------------------------------------------
.PHONY: test brain-eater

test:
     section rule
         print($"This will eat your brain! Type YES to confirm or press 
Enter to abort: ")
         RESULT = $(input-line $(stdin))
         if $(mem $(RESULT), YES yes)
             test: brain-eater
                 println($"Now testing the eaten brain")
         else
             test:
                 eprintln($"Brain eater aborted by the user")
                 exit 1

brain-eater:
     println($"Consider your brain eaten!")

.DEFAULT: test
----------------------------------------------

Note that here the confirmation dialog is not considered to be a part of 
any actual rule body, so the $(stdin) reference no longer needs to be 
quarantined into a helper function.

Aleksey

-- 
Aleksey Nogin, Research Scientist
Advanced Technologies Department, Information & System Sciences Lab
HRL Laboratories, LLC, Malibu, CA


More information about the Omake mailing list