[t] Refactor some namespace pmc tests to use throws_like
[parrot.git] / docs / configuration.pod
blob32ae820c316350ca576039ce28b201b8c04d1b45
1 # Copyright (C) 2004-2008, Parrot Foundation.
2 # $Id$
4 =pod
6 =head1 NAME
8 docs/configuration.pod - Parrot Configuration System
10 =head1 DESCRIPTION
12 Parrot configuration is broken up into I<steps>. Each step contains several
13 related I<prompts>, I<probes>, or I<generations>. Steps should be mostly of a
14 single type, though some overlap is allowed (for example, allowing a probe to
15 ask the user what to do in an exceptional situation).
17 The directory F<config> contains subdirectories for each type of step.  Each
18 step should consist of I<exactly one> F<.pm> file and any number of supporting
19 F<.c>, F<.in>, etc. files. Any supporting files should be in a folder whose
20 name is the same as the basename of the step's F<.pm> file; for example, if
21 F<foo.pm> uses F<bar_c.in>, F<bar_c.in> should be in a directory called F<foo>;
22 the full path might be F<config/auto/foo/bar_c.in>.
24 Generally, when adding a new component to the configuration process you should
25 add a new step unless that component I<clearly> belongs in a current step. For
26 example, if you added a new user-configurable type called C<FOOVAL>, you would
27 add the code used to determine its size in F<config/auto/sizes.pm>.  However,
28 if you were determining what dynaloading capabilities are available, you would
29 create a new step.
31 =head2 Initialization Steps
33 I<Initialization steps> are run before any other steps. They do tasks
34 such as preparing the configuration system's data structures and
35 checking the F<MANIFEST>. New initialization steps will only be added
36 when the configuration system is getting significant new capabilities.
37 They're kept in the directory F<config/init>.
39 =head2 Prompts
41 Prompts ask the user for some information. These should be used sparingly. A
42 step containing prompts is an I<interactive step>.  Interactive steps should be
43 in the F<config/inter> folder.
45 Interactive steps often include simple probes to determine good guesses of what
46 the user will answer. See L</Prompt or Probe?> for more information.
48 Note that, by default, these prompts are turned off. To enable them run
49 F<Configure.pl> with the C<--ask> option.
51 =head2 Probes
53 Probes are automated tests of some feature of the computer. These should be
54 used wherever a value will not need to be modified often by the user.  A step
55 containing probes is an I<automatic step>. Automatic steps should be in the
56 F<config/auto> folder.
58 =head2 Generations
60 Generations create files needed after configuration has completed, such as
61 Makefiles and configuration headers. A step containing generations is a
62 I<generation step>. Generation steps should be in the F<config/gen> folder.
64 Templates for files to be generated usually have the extension F<.in>.  There
65 are variable substitutes and funny macros like C<#IF> and C<#UNLESS>
66 (conditional lines).
68 =head2 Prompt or Probe?
70 It can sometimes be hard to decide whether a given step should be an automatic
71 or an interactive step. The guiding question is I<Would a user ever want to
72 change this?>, or conversely, I<Is this something that can be completely
73 determined without user intervention?>  A step figuring out what the
74 compiler's command is would probably be an interactive step; conversely, a
75 step figuring out if that command is connected to a specific compiler (like
76 F<gcc>) would be an automatic step.
78 =head2 Configuring Configuration
80 The configuration system gets its own configuration data from, and is invoked
81 via, the F<Configure.pl> script.  The system is invoked by instantiating a
82 L<Parrot::Configure> object, registering one or more steps with that object,
83 and then calling C<Parrot::Configure::runsteps()>.
85 =head2 Adding New Steps
87 New steps should be added in one of the four folders mentioned above.
89 All steps are really classes; each exists in a unique namespace.  The
90 namespace used depends on the step's relative path in the source tree sans the
91 F<config> prefix.  For example, the step F<config/init/defaults.pm> uses the
92 C<init::defaults> namespace.
94 Each step inherits its constructor and some other methods from
95 F<lib/Parrot/Configure/Step.pm>.  Each step needs to define only
96 two methods:  C<_init()> and C<runstep()>.
98 The C<_init()> method should follow the following example, defining three
99 elements within an internal hash:
101     sub _init {
102         my $self = shift;
103         my %data;
104         $data{description} = q{This is the step description};
105         $data{result}      = q{};
106         return \%data;
107     }
109 =over 4
111 =item C<description>
113 Of these three elements, C<description> is the most important as it is
114 used extensively within C<lib/Parrot/Configure.pm>.
116 Returns a short descriptive message that should be printed before the step
117 executes.
119 Some example descriptions:
121 =over 4
123 =item F<config/auto/cgoto.pm>
125     Does your compiler support computed goto...
127 =item F<gen/config_h.pm>
129     Generate C headers...
131 =back
133 Note that on non-interactive steps, the text I<done> will be printed after the
134 description when the step finishes executing; for example, the user will see:
136     Does your compiler support computed goto..............done.
138 =item C<result>
140 The C<result> is initialized to an empty string mainly to quiet
141 'uninitialized variable' warnings.  Most configuration steps override
142 the C<result> value inside their C<runstep()> method.
144 =item C<runstep()>
146 This method is called to actually execute the step.  The return
147 value should be C<1> if the step accomplishes what it is intended to do.
148 Otherwise, the step should simply C<return>, I<i.e.>, return an
149 undefined value.
151 =back
153 The configuration system won't execute your step by default unless it's
154 specifically told to. To do this, edit F<lib/Parrot/Configure/Step/List.pm>.
155 Steps are run in the order in which that are registered with the
156 L<Parrot::Configure> object.
158 Various utility functions for configuration steps are provided by the
159 L<Parrot::Configure::Utils> module.
161 A template for a new step might look like this:
163     package auto::newstep;
165     use strict;
166     use warnings;
167     our qw($description $result);
169     use base qw(Parrot::Configure::Step);
171     use Parrot::Configure::Utils;
173     sub _init {
174         my $self = shift;
175         my %data;
176         $data{description} = q{This is the step description};
177         $data{result}      = q{};
178         return \%data;
179     }
181     sub runstep {
182         my ($self, $conf) = @_
183         ...
184         if ($success) {
185             $self->set_result('yes');
186             return 1;
187         } else {
188             $self->set_result('no');
189             return;
190         }
191     }
193 The step's C<runstep()> method should return C<1> upon success and do a
194 bare return on failure (thereby returning an undefined value).
196 =head2 Command-line Arguments
198 Command-line arguments look like C</--[-\w]+(=.*)?/>; the equals sign separates
199 the name and the value. If the value is omitted, it's assumed to be C<1>. The
200 options C<--help> and C<--version> are built in to Configure; any others are
201 defined by steps.
203 Command-line arguments are now processed by C<process_options()>, a subroutine
204 exported by L<Parrot::Configure::Options>.  If you add a new option, don't
205 forget to add it to this documentation and to appropriate locations.  Most
206 options should be added to C<@shared_valid_options> in
207 F<lib/Parrot/Configure/Options/Conf/Shared.pm>.
209 Arguments passed to F<Configure.pl> are held in a L<Parrot::Configure::Data>
210 object stored inside the L<Parrot::Configure> object.  The options data object
211 may be accessed via the C<Parrot::Configure::options()> method.
213 =head2 Configuration by File
215 As an alternative to typing a long string of options on the command-line,
216 Parrot can now be configured from a configuration file.  You put the options
217 in a configuration file, then call F<Configure.pl> as follows:
219     perl Configure.pl --file=/path/to/config/file
221 That's it!  No other command-line arguments needed (or permitted)!  To learn
222 how to create such a configuration file, call:
224     perldoc Configure.pl
226 =head2 Building Up Configuration Data
228 The second step is F<config/init/defaults.pm>, which sets up some defaults in
229 a L<Parrot::Configure::Data> object contained by the main L<Parrot::Configure>
230 object.  It can be accessed via the C<Parrot::Configure::data()> method.  You
231 get and set configuration system's data by interacting with this object.  Some
232 of its methods are summarized below.
234 =over 4
236 =item C<get(keys)>
238 Returns the values for the given keys.
240 =item C<set(key, value, [key, value, ...])>
242 Sets the given keys to the given values.
244 =item C<add(delim, key, value, [key, value, ...])>
246 Sets the given keys to the given values or appends values delimited by I<delim>
247 to existing keys.
249 =item C<keys()>
251 Returns a list of all keys.
253 =item C<dump()>
255 Returns a string that can be C<eval>ed by Perl to create a hash representing
256 the configuration system's data.
258 See the L<Parrot::Configure::Data> documentation for further details.
260 =back
262 =head2 Special Configuration Items
264 Some configuration items, by convention, have a special meaning (mainly
265 prefixes) and are handled with some magic internally.
267 =over 4
269 =item C<i_(\w+)> include files
271 defines or undefs PARROT_HAS_HEADER_XXX in F<include/parrot/has_header.h>
273 =item C<HAS_(\w+)> features
275 defines PARROT_HAS_XXX in F<include/parrot/has_header.h>
277 =item C<TEMP_(\w+)> temporary settings
279 These settings are deleted before F<lib/Parrot/Config.pm> is written. These
280 entries are only used e.g. for Makefile creation.
282 =back
284 =head2 Accessing Configuration Information via Perl 5 Variables
286 Parrot configuration is currently jump-started by extracting
287 considerable information from variables associated with the instance of
288 Perl 5 which the user is using to run F<Configure.pl>.  These variables
289 are largely looked up in the C<%Config> found in the Perl 5
290 F<Config.pm>, but may also be sought in Perl 5 special variables such as
291 C<$^O>.  All such lookups should be done in configuration step
292 C<init::defaults> and B<only> in that step.  Special accessors are
293 available for working with such variables; see
294 F<config/init/defaults.pm> and F<lib/Parrot/Configure/Data.pm>.
296 =head1 HISTORY
298 The Parrot configuration system was created by Brent Dax and has been heavily
299 mangled by Joshua Hoblitt.  James Keenan refactored the configuration system.
301 =head1 SEE ALSO
303 L<Parrot::Configure>, L<Parrot::Configure::Data>,
304 L<Parrot::Configure::Utils>, L<Parrot::Configure::Step>
306 =cut