]>
Dogcows Code - chaz/yoink/blob - build/config.lua
fa522cf9247a31b0b530e5923d78fe63737d178b
3 -- Execute this script with Lua to prepare the project for compiling.
5 -- Copyright (c) 2011, Charles McGarvey
6 -- Distributable under the terms and conditions of the 2-clause BSD
7 -- license; see the file COPYING for a complete text of the license.
11 --local function trace(event, line)
12 --local s = debug.getinfo(2).short_src
13 --print(s .. ":" .. line)
15 --debug.sethook(trace, "l")
18 -- Convert the arguments into standard form. Each argument should be a
19 -- string. A table is returned with the arguments' standard form as keys.
20 -- If an argument has a value, it will correspond to the appropriate key in
21 -- the table. This function supports autoconf-style arguments, including:
22 -- 1. -h, --help produce a --help key with a value of true.
23 -- 2. --enable-feature=[yes|no|whatever], --disable-feature produce a
24 -- --enable-feature key with a value of true, false, or a string.
25 -- 3. --with-package=[yes|no|whatever], --without-feature produce a
26 -- --with-package key with a value of true, false, or a string.
27 -- 4. SYMBOL=VALUE produce a SYMBOL key with VALUE as the string value.
28 -- 5. Anything else will appear as a key in the table as-is with a value of
30 -- If multiple arguments mapping to the same key are present in the
31 -- argument list, the last one is used.
32 local function parseArguments (...)
36 local function setPair ( key
, value
) result
[ key
] = value
end
37 local function setTrue ( key
) result
[ key
] = true end
38 local function addLibrarySearchPath ( path
)
39 package
. path
= path
.. "/?.lua;" .. package
. path
40 package
. cpath
= path
.. "/?.so;" .. package
. cpath
43 table . insert ( filters
, { "^-h$" , function () result
[ "--help" ] = true end })
44 table . insert ( filters
, { "^-L(.*)$" , addLibrarySearchPath
})
46 table . insert ( filters
, { "^(--enable%-[%w_-]+)=?(.*)$" , setPair
})
47 table . insert ( filters
, { "^--disable%-([%w_-]+)$" , function ( feature
)
48 setPair ( "--enable-" .. feature
, "no" )
51 table . insert ( filters
, { "^(--with%-[%w_-]+)=?(.*)$" , setPair
})
52 table . insert ( filters
, { "^--without%-([%w_-]+)$" , function ( package
)
53 setPair ( "--with-" .. package
, "no" )
56 table . insert ( filters
, { "^([%w_-]+)=(.*)$" , setPair
})
57 table . insert ( filters
, { "^([%w_-]+)$" , setTrue
})
59 for _
, a
in ipairs ( arg
)
61 for _
, filter
in pairs ( filters
)
63 local matches
= { a
: match ( filter
[ 1 ])}
64 if matches
[ 1 ] then filter
[ 2 ]( unpack ( matches
)) break end
72 local arguments
= parseArguments ( unpack ( arg
))
73 local interactive
= arguments
[ "--interactive" ]
74 local rules
= arguments
[ "--rules" ] or "options.lua"
75 local configfile
= arguments
[ "--configfile" ] or "config.mk"
76 local printendmsg
= arguments
[ "--print-instructions" ]
77 local exportHeader
= arguments
[ "--export-header" ]
78 local exportTerms
= arguments
[ "--export-terms" ]
81 local util
= require
"utility"
82 util
. logfile
= "config.log"
85 local printInfo
= util
. printer ( "%s - %s \n " )
86 local printWarning
= util
. printer ( " \a %s - %s \n " , "33" )
87 local printError
= util
. printer ( " \a %s - %s \n " , "31" )
88 local function beginProcess ( title
, caption
)
89 print ( string . format ( "%s: \n " , title
))
90 local updater
= util
. printer ( " [%3d%%] %s \n " )
92 return function ( progress
, caption
)
95 if 0.0 <= progress
and progress
<= 1.0 then progress
= progress
* 100 end
96 return updater ( progress
, caption
)
103 local function loadDialog ( name
, configfile
)
105 local result
, err
= pcall ( function () dialog
= require
"dialog" end )
111 dialog
. title
= string . format ( "%s - %s Configuration" , configfile
, name
)
112 printInfo
= dialog
. msgbox
113 printWarning
= dialog
. msgbox
114 printError
= dialog
. msgbox
115 beginProcess
= dialog
. gauge
120 local function topologicalSort ( lookup
)
121 local dependants
= util
. copy ( lookup
, "v" , { v
= function () return 0 end })
122 for _
, option
in pairs ( lookup
)
124 for _
, dep
in ipairs ( option
: getDirectDependants ())
126 dependants
[ dep
] = dependants
[ dep
] + 1
132 for symbol
, count
in pairs ( dependants
)
134 if count
== 0 then table . insert ( queued
, symbol
) end
138 local symbol
= table . remove ( queued
)
139 table . insert ( sorted
, symbol
)
140 for _
, dep
in ipairs ( lookup
[ symbol
]: getDirectDependants ())
142 dependants
[ dep
] = dependants
[ dep
] - 1
143 if dependants
[ dep
] == 0 then table . insert ( queued
, dep
) end
148 for symbol
, count
in pairs ( dependants
)
150 if 0 < count
then table . insert ( remaining
, symbol
) end
154 printWarning ( "Q.A. Notice" , "One or more circular dependencies were detected involving these symbols: "
155 .. table . concat ( remaining
, ", " ))
156 for _
, symbol
in ipairs ( remaining
) do table . insert ( sorted
, symbol
) end
162 local function checkSymbols ( symbols
)
163 local check
= topologicalSort ( symbols
)
165 local updateTask
= function () end
168 updateTask
= beginProcess ( "Checking Symbols" , "Resolving dependencies..." , 6 , 65 )
172 local option
= symbols
[ check
[ i]]
173 if option
: validate () == nil then isErr
= true end
174 updateTask ( i
/ # check
,
175 ( option
: getSymbol () .. ": " .. option
: toExpandedString ()): truncate ( 60 ))
178 if isErr
then return nil end
183 ---------------------------------------------------------------------------
184 local Option
= util
. class ()
185 ---------------------------------------------------------------------------
187 function Option
: __init ( rule
, lookup
, objects
)
188 self
. name
= rule
. name
189 self
. caption
= rule
. caption
190 self
. help
= rule
. help
191 self
. value
= rule
. value
192 self
. symbol
= rule
. symbol
193 self
. cmdline
= rule
. cmdline
194 self
. config
= rule
. config
195 self
. export
= rule
. export
196 self
. visible
= rule
. visible
197 self
. check
= rule
. check
198 self
. temp
= rule
. temp
199 self
. before
= rule
. before
200 self
. after
= rule
. after
201 self
. lookup
= lookup
or {}
202 self
. objects
= objects
or {}
204 if type ( self
. check
) == "function" then setfenv ( self
. check
, self
. lookup
) end
205 if type ( self
. visible
) == "function" then setfenv ( self
. visible
, self
. lookup
) end
207 if self
. symbol
~= nil
209 if self
. lookup
[ self
. symbol
] ~= nil
211 printWarning ( "duplicate symbol defined:" , self
. symbol
)
213 self
. lookup
[ self
. symbol
] = self
. value
214 self
. objects
[ self
. symbol
] = self
218 -- Get the symbol of the option. The symbol is used as a reference in the
219 -- string values of other options. It must be unique.
220 function Option
: getSymbol ()
224 -- Get the argument of the option.
225 function Option
: getArg ()
229 -- Get the value of the option as a string.
230 function Option
: toString ()
231 return tostring ( self
. lookup
[ self
. symbol
])
234 -- Get the value of the option as an expanded string. For most types of
235 -- options, this is the same as Option:toString().
236 function Option
: toExpandedString ()
237 return self
: toString ()
240 function Option
: getDirectDependants ()
241 return self
. before
or {}
244 function Option
: getUnsortedDependants ( dependants
)
245 dependants
= dependants
or {}
246 if dependants
[ self
. symbol
] then return dependants
end
247 dependants
[ self
. symbol
] = self
250 for _
, dep
in ipairs ( self
. before
)
252 local option
= self
. objects
[ dep
]
255 dependants
= option
: getUnsortedDependants ( dependants
)
257 printWarning ( "invalid dependency: " .. dep
)
264 function Option
: addDependant ( dependency
)
265 self
. before
= self
. before
or {}
266 table . insert ( self
. before
, dependency
)
269 function Option
: convertDependenciesToDependants ()
272 local dep
= table . remove ( self
. after
)
275 local option
= self
. objects
[ dep
]
278 option
: addDependant ( self
. symbol
)
280 printWarning ( "invalid dependency: " .. dep
)
282 dep
= table . remove ( self
. after
)
287 function Option
: getObjects ()
291 -- Check the value of the option for validity.
292 -- Returns a valid value based on the given value, or nil (with an error
293 -- message) if the value is invalid and could not be converted to a valid
295 function Option
: validate ( value
)
297 if value
== nil then value
= self
. lookup
[ self
. symbol
] end
299 if type ( self
. check
) == "function"
301 value
, err
= self
. check ( value
)
302 if value
== nil then self
. problem
= err
return nil , err
end
304 self
. lookup
[ self
. symbol
] = value
308 -- Set the value of the option to the value in a new lookup table.
309 function Option
: applyTable ( lookup
)
312 -- Set the value of the option based on a table of argument flags.
313 function Option
: applyArguments ()
316 -- Set the value of the option.
317 function Option
: set ( value
)
318 self
. lookup
[ self
. symbol
] = value
319 if checkSymbols ( self
: getUnsortedDependants ())
321 return self
. lookup
[ self
. symbol
]
325 -- Write the symbol and current value to the config file.
326 function Option
: writeSymbol ( fd
)
327 if self
. symbol
~= nil and not self
. temp
329 fd
: write ( util
. align ( self
. symbol
, "= " .. tostring ( self
. lookup
[ self
. symbol
]), 16 ) .. " \n " )
330 --fd:write(string.format("%s\t= %s\n", self.symbol, tostring(self.lookup[self.symbol])))
334 -- Write the option value to the config header file.
335 function Option
: writeCppLine ( fd
)
338 -- Write the option value as a string replacement to the sed file.
339 function Option
: writeSedLine ( fd
)
342 local value
= self
: toExpandedString (): gsub ( "/" , " \\ /" )
343 local function writeLine ( key
)
344 key
= tostring ( key
): gsub ( "/" , " \\ /" )
345 fd
: write ( string . format ( "s/@%s@/%s/g \n " , key
, value
))
347 if type ( self
. export
) == "table"
349 for _
, key
in ipairs ( self
. export
) do writeLine ( key
) end
351 writeLine ( self
. export
)
356 -- Run an interactive menu with the given dialog context. The type of menu
357 -- run will depend on the type of option.
358 function Option
: showMenu ( dialog
)
361 -- Get whether or not there is a problem with the current value of the
363 function Option
: isValid ()
364 return type ( self
. problem
) ~= "string"
367 -- Get a human-readable description of the problem(s) this option faces
368 -- before it can be considered valid.
369 function Option
: getProblem ()
373 -- Get the name to be used for this option in the interactive menu.
374 function Option
: getMenuItem ()
375 if not self
: isValid () then return self
. name
.. " <!>" end
379 -- Get the label used to represent this option in a menu.
380 function Option
: getLabel ()
384 -- Get whether or not this option should be visible in a menu of options.
385 -- Returns true if option is visible, false otherwise.
386 function Option
: isVisible ()
387 if type ( self
. visible
) == "function" then return self
. visible () end
391 -- If the option has an argument flag, print out a line with information
392 -- about the purpose of this option.
393 function Option
: printHelpLine ()
394 if self
. cmdline
~= nil
396 print ( util
. align ( " " .. self
: getArg (), self
. caption
, 32 ))
400 function Option
: getHelpText ()
401 local value
= self
: toString ()
402 local help
= self
. help
or "No help available. \n "
403 local name
= self
. name
or "Unnamed"
404 local symbol
= self
: getSymbol () or "None"
405 local arg
= self
: getArg () or "None"
407 local problem
= self
: getProblem ()
408 if problem
then problem
= " \n Problem(s): \n " .. problem
409 else problem
= "" end
415 Option Name: ]] .. name
.. [[
417 Symbol: ]] .. symbol
.. [[
419 Current Value: ]] .. value
.. [[
421 Argument: ]] .. arg
.. [[
427 ---------------------------------------------------------------------------
428 local StringOption
= util
. class ( Option
)
429 ---------------------------------------------------------------------------
431 -- Get the expanded option value. Symbols which begin with dollar signs
432 -- will be substituted for their values.
433 function StringOption
: toExpandedString ()
434 local function expand ( value
)
435 _
, value
, count
= pcall ( string . gsub , value
, "%$%(([%w_]+)%)" , self
. lookup
)
436 if not count
then count
= 0 end
439 local value
= self
. lookup
[ self
. symbol
]
444 value
, count
= expand ( value
)
445 if count
== 0 then return value
end
446 iterations
= iterations
+ 1
451 function StringOption
: applyTable ( lookup
)
452 local value
= lookup
[ self
. symbol
]
453 if type ( value
) == "string" then self
. lookup
[ self
. symbol
] = tostring ( value
) end
456 function StringOption
: applyArguments ( args
)
457 local value
= args
[ self
. cmdline
]
458 if value
~= nil then self
: validate ( tostring ( value
)) end
461 function StringOption
: writeCppLine ( fd
)
464 local value
= self
: toExpandedString ()
465 local function writeLine ( key
)
466 if type ( self
. value
) == "string"
468 fd
: write ( string . format ( "#define %s %q \n " , key
, value
))
470 fd
: write ( string . format ( "#define %s %s \n " , key
, value
))
473 if type ( self
. config
) == "table"
475 for _
, key
in ipairs ( self
. config
) do writeLine ( key
) end
477 writeLine ( self
. config
)
482 function StringOption
: showMenu ( dialog
)
483 local code
, item
= dialog
. inputbox ( self
. name
, self
. caption
, self
. lookup
[ self
. symbol
])
484 if code
== 0 and item
~= self
. lookup
[ self
. symbol
]
486 return self
: set ( item
)
490 function StringOption
: getLabel ()
491 return self
: toExpandedString ()
495 ---------------------------------------------------------------------------
496 local EnumOption
= util
. class ( StringOption
)
497 ---------------------------------------------------------------------------
499 -- An enumeration option is like a string, but it can only hold certain
500 -- pre-determined values. In a rule, it is distinguished by its value key
501 -- which refers to an array of the possible (string) values.
502 function EnumOption
: __init ( rule
, lookup
, objects
)
503 Option
. __init ( self
, rule
, lookup
, objects
)
504 self
. lookup
[ self
. symbol
] = self
. value
[ 1 ]
507 function EnumOption
: getArg ()
508 if self
. cmdline
== nil then return nil end
509 return self
. cmdline
.. "=[" .. table . concat ( self
. value
, "|" ) .. "]"
512 function EnumOption
: validate ( str
)
513 str
= str
or self
. lookup
[ self
. symbol
]
514 for _
, value
in ipairs ( self
. value
)
516 if value
== str
then return Option
. validate ( self
, str
) end
518 self
. problem
= "The assigned value (" .. str
.. ") is not a valid option."
519 return nil , self
. problem
522 function EnumOption
: applyArguments ( args
)
523 -- Just like applying arguments for strings, but if the argument is
524 -- false, assume the first value should be assigned.
525 local value
= args
[ self
. cmdline
]
526 if value
== false then self
: validate ( self
. value
[ 1 ]) return end
527 StringOption
. applyArguments ( self
, args
)
530 function EnumOption
: writeCppLine ( fd
)
533 local value
= self
: toString (): upper ()
534 local function writeLine ( key
)
535 key
= tostring ( key
) .. "_" .. value
536 fd
: write ( string . format ( "#define %s 1 \n " , key
))
538 if type ( self
. config
) == "table"
540 for _
, key
in ipairs ( self
. config
) do writeLine ( key
) end
542 writeLine ( self
. config
)
547 function EnumOption
: showMenu ( dialog
)
549 for _
, value
in ipairs ( self
. value
)
551 table . insert ( menuitems
, { value
, "" })
553 local code
, item
= dialog
. menu (
557 self
. lookup
[ self
. symbol
],
558 {[ "--ok-label" ] = "Select" }
560 if code
== 0 and item
~= self
. lookup
[ self
. symbol
]
562 return self
: set ( item
)
566 function EnumOption
: getLabel ()
567 return "[" .. StringOption
. getLabel ( self
) .. "]"
571 ---------------------------------------------------------------------------
572 local BooleanOption
= util
. class ( Option
)
573 ---------------------------------------------------------------------------
575 function BooleanOption
: toString ()
576 if self
. lookup
[ self
. symbol
] then return "Yes" else return "No" end
579 function BooleanOption
: applyTable ( lookup
)
580 local value
= lookup
[ self
. symbol
]
581 if type ( value
) == "boolean" then self
. lookup
[ self
. symbol
] = value
end
584 function BooleanOption
: applyArguments ( args
)
585 local value
= args
[ self
. cmdline
]
586 if value
== "yes" or value
== "" then value
= true end
587 if value
== "no" then value
= false end
588 if type ( value
) == "boolean" then self
: validate ( value
) end
591 function BooleanOption
: writeCppLine ( fd
)
594 local value
= self
. lookup
[ self
. symbol
]
595 local function writeLine ( key
)
596 -- Reverse the value if key starts with a bang.
598 if key
: byte ( 1 ) == 33 then key
= key
: sub ( 2 ) value
= not value
end
601 fd
: write ( "#define " .. key
.. " 1 \n " )
603 fd
: write ( "/* #undef " .. key
.. " */ \n " )
606 if type ( self
. config
) == "table"
608 for _
, key
in ipairs ( self
. config
) do writeLine ( key
) end
610 writeLine ( self
. config
)
615 function BooleanOption
: showMenu ( dialog
)
616 local item
= not self
. lookup
[ self
. symbol
]
617 return self
: set ( item
)
620 function BooleanOption
: getLabel ()
621 if self
. lookup
[ self
. symbol
] then return "[X]" else return "[ ]" end
625 ---------------------------------------------------------------------------
626 local NullOption
= util
. class ( Option
)
627 ---------------------------------------------------------------------------
629 -- Null options don't really hold any useful information; they just
630 -- translate to a blank line in the menuconfig. Any non-table object in a
631 -- rule will become this type of option.
632 function NullOption
: __init ()
637 function NullOption
: validate ()
640 function NullOption
: isVisible ()
645 ---------------------------------------------------------------------------
646 local GroupOption
= util
. class ( Option
)
647 ---------------------------------------------------------------------------
649 local function optionFactory ( rule
, lookup
, objects
)
650 local jump
= setmetatable ({
651 string = StringOption
,
652 number = StringOption
,
654 boolean
= BooleanOption
656 __index
= function () return GroupOption
end
658 if type ( rule
) == "table"
660 return jump
[ type ( rule
. value
)]( rule
, lookup
, objects
)
662 -- If the rule is not a table, just insert a placeholder option for
668 -- A GroupOption is not really an option itself, but a group of options.
669 function GroupOption
: __init ( rule
, lookup
, objects
)
670 Option
. __init ( self
, rule
, lookup
, objects
)
673 for _
, child
in ipairs ( rule
)
675 table . insert ( self
. children
, optionFactory ( child
, self
. lookup
, self
. objects
))
679 function GroupOption
: toString ()
683 -- Call the method with an arbitrary number of arguments to each
685 function GroupOption
: recurse ( method
, ...)
686 for _
, child
in ipairs ( self
. children
)
688 child
[ method
]( child
, unpack ( arg
))
692 function GroupOption
: convertDependenciesToDependants ()
693 self
: recurse ( "convertDependenciesToDependants" )
696 -- Validate each sub-option in order. The validation will short-circuit
697 -- and return nil (with an error message) upon the first failed validation.
698 function GroupOption
: validate ()
699 for _
, child
in ipairs ( self
. children
)
701 local result
, err
= child
: validate ()
702 if result
== nil then return result
, err
end
707 function GroupOption
: isValid ()
708 for _
, child
in ipairs ( self
. children
)
710 if not child
: isValid () then return false end
715 function GroupOption
: getProblem ()
717 for _
, child
in ipairs ( self
. children
)
719 local problem
= child
: getProblem ()
722 local symbol
= child
: getSymbol ()
725 problems
= problems
.. util
. align ( symbol
.. ":" , problem
, 16 ) .. " \n "
727 problems
= problems
.. problem
.. " \n "
729 util
. align ( symbol
, problem
, 16 )
732 if problems
== "" then return nil end
733 return util
. trim ( problems
)
736 function GroupOption
: applyTable ( lookup
)
737 self
: recurse ( "applyTable" , lookup
)
740 function GroupOption
: applyArguments ( args
)
741 self
: recurse ( "applyArguments" , args
)
744 function GroupOption
: writeSymbol ( fd
)
745 if self
. name
~= nil then
746 fd
: write ( string . format ( " \n # %s \n " , self
. name
))
747 self
: recurse ( "writeSymbol" , fd
)
751 function GroupOption
: writeCppLine ( fd
)
752 self
: recurse ( "writeCppLine" , fd
)
755 function GroupOption
: writeSedLine ( fd
)
756 self
: recurse ( "writeSedLine" , fd
)
760 function GroupOption
: showMenu ( dialog
)
761 local running
, dirty
, selected
= true
765 for _
, value
in ipairs ( self
. children
)
767 if type ( value
) ~= "table"
769 table . insert ( menuitems
, value
)
770 elseif type ( value
. name
) == "string" and value
: isVisible ()
772 local name
= value
: getMenuItem ()
773 local label
= value
: getLabel ()
775 if type ( value
. caption
) == "string"
777 caption
= value
. caption
778 menuitems
[ "HELP " .. value
. caption
] = value
780 menuitems
[ name
] = value
781 table . insert ( menuitems
, { name
, label
, caption
})
785 local code
, item
= dialog
. menu (
791 [ "--ok-label" ] = "Select" ,
792 [ "--cancel-label" ] = "Exit" ,
793 [ "--item-help" ] = true ,
794 [ "--help-button" ] = true
800 local value
= menuitems
[ item
]
801 if type ( value
) == "table"
803 if value
: showMenu ( dialog
) ~= nil then dirty
= "changed" end
804 selected
= value
: getMenuItem ()
810 local value
= menuitems
[ item
]
813 dialog
. msgbox ( value
. name
, value
: getHelpText (), {[ "--no-collapse" ] = true })
814 selected
= value
: getMenuItem ()
816 dialog
. msgbox ( "No Help" ,
817 "Sorry, no help is available for this option." )
826 function GroupOption
: getLabel ()
830 function GroupOption
: printHelpLine ()
831 if self
: isVisible () and self
. name
~= nil then
832 print ( string . format ( " \n %s:" , self
. name
))
833 self
: recurse ( "printHelpLine" )
838 -- Print arguments and usage information for all of the sub-options.
839 function GroupOption
: printHelp ( name
)
842 This script prepares ]] .. name
.. [[ for building on your system.
843 Usage: ./configure [OPTION]... [VAR=VALUE]...]] )
849 -- Set values of the sub-options based on a table that is loaded from a
850 -- file. The table is formatted as one or more lines with keys and values
851 -- separated by an equal sign. The pound sign (#) serves to start a
852 -- comment on the line. The first equal sign on a line is used as the
853 -- separator, so keys cannot have an equal sign.
854 function GroupOption
: loadFromFile ( filepath
)
856 local fd
= io
. open ( filepath
)
859 for line
in fd
: lines ()
861 if not line
: find ( "^%s*#" )
863 key
, value
= line
: match ( "^%s*(%S.-)%s*=%s*(.*)%s*" )
866 if value
: upper () == "TRUE" then value
= true
867 elseif value
: upper () == "FALSE" then value
= false end
869 if key
then lookup
[ key
] = value
end
874 self
: applyTable ( lookup
)
877 -- Save a table with the current values of the sub-options to a file. The
878 -- file can be reloaded with GroupOption:loadFromFile.
879 function GroupOption
: saveToFile ( filepath
)
880 local fd
= io
. open ( filepath
, "w" )
883 fd
: write ( string . format ( " \n # Auto-generated: %s" , os
. date ()))
887 printError ( "couldn't save config file to:" , filepath
)
891 -- Exports the config header file. The key-value pairs of sub-options with
892 -- "config" defined will be written to the file.
893 function GroupOption
: exportHeader ( filepath
)
894 local fd
= io
. open ( filepath
, "w" )
895 self
: writeCppLine ( fd
)
899 -- Exports the search 'n replace file. The key-value pairs of sub-options
900 -- with "export" defined will be written to the file.
901 function GroupOption
: exportTerms ( filepath
)
902 local fd
= io
. open ( filepath
, "w" )
903 self
: writeSedLine ( fd
)
907 -- Run menuconfig. This is different from showMenu in that this method
908 -- tracks changes and returns an action: save, cancel, nochange or error.
909 function GroupOption
: runMenu ()
910 local result
, dirty
= nil , false
913 if self
: showMenu ( dialog
) ~= nil then dirty
= true end
914 if not self
: isValid ()
916 local code
= dialog
. yesno ( "Oh drat!" ,
917 "There is at least one problem with the configuration, marked with <!>, and the configuration will not be saved. Do you really want to exit without saving?" ,
919 [ "--extra-button" ] = false ,
920 [ "--ok-label" ] = "Exit" ,
921 [ "--cancel-label" ] = "Back"
923 if code
== 0 or code
== 255 then result
= "error" end
926 local code
= dialog
. yesno ( "Save Changes?" ,
927 "Your configuration has been altered. Do you want to save the changes?" ,
929 [ "--ok-label" ] = "Save" ,
930 [ "--cancel-label" ] = "Back" ,
931 [ "--extra-button" ] = true ,
932 [ "--extra-label" ] = "Exit"
934 if code
== 0 then result
= "save"
935 elseif code
== 3 or code
== 255 then result
= "cancel" end
944 local loadFn
= assert ( loadfile ( rules
))
945 local name
, rules
= loadFn ()
947 local options
= optionFactory ( rules
)
948 if arguments
[ "--help" ] then options
: printHelp ( name
) os
. exit () end
950 options
: loadFromFile ( configfile
)
951 if exportHeader
or exportTerms
953 if exportHeader
then options
: exportHeader ( exportHeader
) end
954 if exportTerms
then options
: exportTerms ( exportTerms
) end
959 printInfo ( name
, "Preparing for building and installation on your system. \n " )
960 options
: applyArguments ( arguments
)
962 if interactive
then loadDialog ( name
, configfile
) end
964 options
: convertDependenciesToDependants ()
965 checkSymbols ( options
: getObjects ())
969 local action
= options
: runMenu ()
970 if action
== "exit" or action
== "error"
972 print ( "configuration aborted by user request" )
975 options
: saveToFile ( configfile
)
976 print ( "configuration saved to " .. configfile
)
978 elseif options
: isValid ()
980 options
: saveToFile ( configfile
)
982 printError ( "Uh oh!" , [[
983 There is at least one unresolved problem with the configuration.
984 ]] .. options
: getProblem () .. " \n " )
988 if printendmsg
~= "no"
990 printInfo ( "Configuration complete!" , [[
991 To finish the installation, type:
997 -- vi:ts=4 sw=4 tw=75
This page took 0.076052 seconds and 4 git commands to generate.