ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/doc/tex/manual/Examples.tex
Revision: 1.2
Committed: Fri Nov 4 16:32:44 2005 UTC (19 years, 6 months ago) by sashby
Content type: application/x-tex
Branch: MAIN
Changes since 1.1: +68 -1 lines
Log Message:
doc change.

File Contents

# User Rev Content
1 sashby 1.1 %%____________________________________________________________________
2     %% File: Examples.tex
3     %%____________________________________________________________________
4     %%
5     %% Author: Shaun ASHBY <Shaun.Ashby@cern.ch>
6     %% Update: 2005-11-02 17:08:52+0100
7 sashby 1.2 %% Revision: $Id: Examples.tex,v 1.1 2005/11/02 16:24:18 sashby Exp $
8 sashby 1.1 %%
9     %% Copyright: 2005 (C) Shaun ASHBY
10     %%
11     %%--------------------------------------------------------------------
12     \chapter{Examples}\label{ch:examples}
13    
14 sashby 1.2 This chapter contains some usefull examples of how to work with
15     \scram.
16 sashby 1.1
17     \section{Configuring New Projects}\label{sec:configuringprojectexample}
18    
19 sashby 1.2 This section covers how to create a new project using the boot
20     mechanism. Normally, a boot file will instruct \scram\ to download
21     configuration documents from a \texttt{CVS} repository. However,
22     sometimes this may not be possible because the appropriately
23     configured files may not yet be available in a repository or it is
24     more desirable to make a prototype locally before committing anything.
25 sashby 1.1
26     \subsection{Creating Standalone Projects}\label{sec:configuringstandaloneprojects}
27    
28 sashby 1.2 First we will describe how to boot a project from copies of
29     configuration files based on the templates provided by
30     \scram. These templates can be obtained using \texttt{scram project -t}.
31     The \texttt{config} directory created locally contains build
32     templates and a global \buildfile, plus the boot and requirements
33     files. The boot file looks like this:
34     \small{
35     \begin{verbatim}
36     <doc type=Configuration::BootStrapProject version=1.0>
37     <project name=SCRATCHTEST version=1_0>
38     <base url="cvs://cmscvs.cern.ch/cvs_server/repositories/SCRAMToolBox
39     ?auth=pserver&user=anonymous&passkey=AA_:yZZ3e&version=CMS_127_2">
40     <download url="cvs:?module=SCRAMToolBox/CMSconfigs" name=config/site>
41     </base>
42    
43     <Config dir=config>
44     <base url="file:config">
45     <download url="file:/" name="config">
46     <RequirementsDoc name=config/requirements>
47     </base>
48     </project>
49     \end{verbatim}}\normalsize
50    
51     \ni and the requirements document looks like this:
52     \small{
53     \begin{verbatim}
54    
55    
56     \end{verbatim}}\normalsize
57    
58    
59    
60    
61    
62    
63    
64    
65    
66    
67     These must now be edited to suit.
68    
69     \ni Here is a recipe:
70    
71     \begin{description}
72     \item[Decide on a project name and version:]\mbox{}\\
73     Edit the boot file, changing the name and version of the project as
74     desired.
75     \item[Configure a toolbox with required tools:]\mbox{}\\
76     In this example, we configure a completely standalone toolbox as a
77     directory structure containing the tool descriptions needed for the
78     project dependencies. There are no references to \texttt{cvs:\\} type
79     URLS and therefore no interaction with a CVS repository.
80     This allows for a very fast setup process since files are
81     "downloaded" from a local disk.
82     \end{decsription}
83    
84     \ni Now we follow a second example in which a toolbox configuration
85     already exists, as prepared by the software librarian, with a
86     published CVS tag.
87 sashby 1.1
88    
89     \section{BuildSystem and Configuration Tips And Tricks}
90    
91     Examples of useful tips? For configuration, could mention changes to \texttt{Self}.
92    
93     \paragraph{Using Project ClassPaths to Customise the Build System}
94    
95     Describe a proper ClassPath.
96    
97     \paragraph{Redefining An Existing Tool}
98    
99     Currently it is not possible to have multiple versions of the same
100     tool. Therefore, this recipe should be followed if an installed tool
101     should be modified, for example to redefine the libraries used or to
102     add an extra runtime variable definition.
103    
104     - Create a new template using \scram, or copy the installed version
105     from \texttt{.SCRAM/architecture/InstalledTools}. If you cannot see
106     the \texttt{InstalledTools} directory (which sometimes happens for
107     %% FIXME>> Should this be ``scram set'' or will ``scram setup <tool>'' work?
108     developer areas), type \texttt{scram setup} or copy the tool description file
109     from the release area for the version of the project you're using to
110     the project area.
111    
112     Next, edit this version of the tool file.
113    
114     Delete the installed version by running \texttt{scram tool remove <tool>}.
115    
116     Set up the new version of the tool, giving a \texttt{file:} URL to
117     point to your new tool description file.
118    
119     \paragraph{Creating an executable}
120    
121     How to create a binary executable.
122    
123     \paragraph{Creating a test executable}
124    
125     How to create a test binary executable. How is this different to a
126     normal binary? Different template defines custom behaviour, in this
127     case to move the product to a \texttt{test} storage location and
128     defining rules for executing the test.
129    
130     \paragraph{Changing the default name of a package library}
131    
132     The CMSSW example. Demonstrate how to change the name of the target,
133     taking the path information from the standard template for the library.
134    
135     \paragraph{Creating an extra shared library}
136    
137     How to use the \texttt{extra\_library.tmpl} template. Types of globs
138     to pick up source files from a stubs directory, for example.
139    
140    
141     \paragraph{How to create a debug version of something}
142    
143     Basically by adding $<$flags \texttt{CXXFLAGS}=\texttt{-g -O0}$>$ to
144     the \buildfile. Easy.
145    
146     \subsection{How To Avoid Rebuilding}
147    
148     Info here on creating a private ``release'' area from which to create
149     a developer area.
150    
151    
152     \example{Example} An example of the contents of a bootstrap file for
153     a project is shown below. \index{example bootstrap file}
154     %\footnotesize{\begin{verbatim}
155     %<doc type=Configuration::BootStrapProject version=1.0>
156     %<project name=P version=P_1_0>
157     %<base url="cvs://server.cern.ch?auth=pserver&user=anoncvs&passkey=Ah<Z&version=TAG">
158     %<download url="cvs:?module=SCRAMToolBox/configs" name=config/site>
159     %</base>
160     %
161     %*************************************************************
162     %
163     %<Config dir=config>
164     %<base url="cvs://server.cern.ch/cvs/SEAL?auth= \
165     %pserver&user=anoncvs&passkey=Ah<Z&version=SEAL_1_1_0">
166     %<download url="cvs:?module=scram" name="config">
167     %<RequirementsDoc name=config/RequirementsDoc>
168     %</base>
169     %</project>
170     %\end{verbatim}}\normalsize
171    
172     \ni This bootstrap file instructs \scram to create a project area
173     called \texttt{P\_1\_0}. Inside this area there is a
174     directory called \texttt{config} (the configuration directory)
175     where all project configuration files are stored. All source code
176     for the project is downloaded to a directory called
177     \texttt{src}. Once the configuration files have been downloaded,
178     \scram parses the requirements file \texttt{RequirementsDoc},
179     found in the \texttt{config} directory.
180    
181     \example{Example} Here is part of the requirements file for the
182     \texttt{COBRA} project example used above:\index{example requirements file}
183     %% \footnotesize{\begin{verbatim}
184     %% <doc type=BuildSystem::Requirements version=2.0>
185     %% <baseurl="cvs://cmscvs.cern.ch/cvs_server/repositories/ToolBox?auth=\
186     %% pserver&user=anonymous&passkey=AA_:yZZ3e&version=CMS_53_1">
187     %% <include url="cvs:?module=ToolBox/CMS/Configuration/CMSconfiguration">
188     %% <Architecture name=SunOS__5>
189     %% <select name=CC>
190     %% </Architecture>
191     %% <Architecture name=Linux__2>
192     %% <select name=gcc>
193     %% </Architecture>
194     %% <select name=clhep>
195     %% <select name=htl>
196     %% <select name=qt>
197     %% </base>
198     %% \end{verbatim}}\normalsize
199    
200     %% \ni The base URL is set to point to a CVS repository for the
201     %% toolbox. The version of the toolbox to be used has the CVS
202     %% symbolic tag \texttt{CMS\_53\_1} according to local
203     %% conventions.The configuration file \texttt{CMSconfiguration} is
204     %% included using an \lbkt\texttt{include}\rbkt statement. This file
205     %% contains entries like these\index{example using the \texttt{include} directive}
206    
207     %% \footnotesize{\begin{verbatim}
208     %% <Architecture name=SunOS__5>
209     %% <require name=CC version=5.2 url="cvs:?module=ToolBox/CompilerTools/CXX/SunCC">
210     %% </require>
211     %% </Architecture>
212     %% <Architecture name=Linux__2>
213     %% <require name=cxxcompiler version=2.95.2 url="cvs:?module=ToolBox/CompilerTools/CXX/gcc">
214     %% </require>
215     %% </Architecture>
216     %% <require name=Qt version=3.0.1 url="cvs:?module=ToolBox/LHCxx/Qt">
217     %% </require>
218     %% <require name=CLHEP version=1.7.5.0 url="cvs:?module=ToolBox/LHCxx/CLHEP">
219     %% </require>
220     %% <require name=HTL version=1.3.2.1 url="cvs:?module=ToolBox/LHCxx/HTL">
221     %% </require>
222     %% \end{verbatim}}\normalsize
223    
224     \ni which are parsed directly after the file is downloaded,
225     \ie the behaviour is exactly the same as if the
226     \lbkt\texttt{require}\rbkt statements are written in the
227     requirements file itself. The compiler tool document wraps the
228     architecture-specific information within the document itself so that
229     it is only necessary to have \lbkt\texttt{use} name=\texttt{cxxcompiler}\rbkt
230     declared in the project \texttt{BuildFile} to use the specified
231     compiler. If no compiler is declared like this, the native
232     \texttt{g++/gcc} will be used instead.
233     %Notice that the compilers are
234     %enclosed within architecture specific blocks-- more details
235     %concerning compiler support can be found in Section~\ref{sec:compilersupport}.
236    
237    
238     \example{Example} Here is an example of a \texttt{ToolDoc} for a tool
239     called \texttt{CLHEP}: \index{\texttt{ToolDoc}!example}
240     %% \footnotesize{\begin{verbatim}
241     %% <doc type=BuildSystem::ToolDoc version=1.0>
242     %% <Tool name=CLHEP version=1.7.5.0>
243     %% <info url=http://wwwinfo.cern.ch/asd/lhc++/clhep></info>
244     %% <LIB name=CLHEP>
245     %% <Client>
246     %% <Environment name=CLHEP_BASE>
247     %% The top of the standard CLHEP distribution.
248     %% </Environment>
249     %% <Environment name=LIBDIR default="$CLHEP_BASE/lib" type=lib>
250     %% The Library location for the CLHEP distribution
251     %% </Environment>
252     %% <Environment name=INCLUDE default="$CLHEP_BASE/include">
253     %% The header file location for the CLHEP distribution
254     %% </Environment>
255     %% </Client>
256     %% <Environment name=LD_LIBRARY_PATH value="$LIBDIR" type=Runtime_path>
257     %% </Environment>
258     %% </Tool>
259     %% \end{verbatim}}\normalsize
260     %% %$
261     \ni When this \texttt{ToolDoc} is parsed by \scram,
262     \texttt{CLHEP\_BASE} is set by the configuration manager
263     (either automatically or by prompting the user if necessary), both
264     \texttt{LIBDIR} and \texttt{INCLUDE} are set to the default
265     values if these paths are found to be valid and, at runtime, the
266     value of the path \texttt{\$LIBDIR} is appended to the user
267     shell variable \texttt{\$LD\_LIBRARY\_PATH} if it exists
268     (otherwise, it is defined automatically).
269    
270    
271     \ni Here area several examples illustrating how to use the \texttt{scram setup} command.
272    
273     \example{Example A} We want to add to our area an analysis tool called \texttt{ROOT}.
274     This tool is included in the tagged configuration available to all projects, so the
275     setup command to use in this case is--
276    
277     \small{\begin{verbatim}
278     scram setup [-i] root 3.05.03 \
279     'cvs://lcgapp.cern.ch/cvs/SPITOOLS? \
280     auth=pserver&module=SCRAMToolBox/General/ROOT \
281     &passkey=Ah<Z&user=anonymous&version=LCG_06'
282     \end{verbatim}}\normalsize
283    
284     \example{Example B} We want to add the tool \texttt{ruby}
285     to our project area. This is not a regularly used tool (that is, the tool is not contained in
286     the configuration), so we will add it using a local tool
287     description file. The command is
288    
289     \begin{scramcmd}{setup}
290     \flag{-i}~\marg{ruby}~\marg{1.6.7}~\marg{file:./ruby-1.6.7}
291     \end{scramcmd}
292    
293     \ni The tool description file looks like this:
294    
295     \footnotesize{
296     \begin{verbatim}
297     <doc type=BuildSystem::ToolDoc version=1.0>
298     <Tool name=RUBY version=1.6.7>
299     <Client>
300     <Environment name=RUBY_BASE>
301     The top of the Ruby distribution.
302     </Environment>
303     <Environment name=LIBDIR default=$RUBY_BASE/lib/ruby/1.6 type=lib>
304     </Environment>
305     </Client>
306     <Environment name=PATH value="$RUBY_BASE/bin" type=Runtime_path>
307     </Environment>
308     <Environment name=LD_LIBRARY_PATH value=$LIBDIR type=Runtime_path>
309     </Environment>
310     </Tool>
311     \end{verbatim}
312     }\normalsize
313     %$
314     \ni so the interactive setup mechanism will ask for a value for
315     \texttt{RUBY\_BASE} and the other values will be set automatically.
316    
317    
318     \example{ClassPath Example} Following the recommended project
319     structure conventions, here is an
320     example of \lbkt\texttt{ClassPath}\rbkt settings for a project:
321     \index{\texttt{ClassPath} tag!example}
322     %% \small{\begin{verbatim}
323     %% <ClassPath path=+Project/+SubSystem/+Package/src+library>
324     %% <ClassPath path=+Project/+SubSystem/+Package/test+UnitTest>
325     %% <ClassPath path=+Project/+SubSystem/+Package/application+binaryApp>
326     %% \end{verbatim}}\normalsize
327     \index{structure templates! and the \texttt{ClassPath}}
328     \ni These settings will associate the top-level \texttt{src}
329     directory with \texttt{Project\_template.tmpl} and any directory in the next
330     level with the template \texttt{SubSystem\_template.tmpl}.
331     The level below that will be associated with \texttt{Package\_template.tmpl}.
332     The last elements have a pattern-matching string before the \texttt{+}
333     sign: only directories matching the names \texttt{src},
334     \texttt{test} and \texttt{application} at the third level below
335     the top-level \texttt{src} directory will be mapped to the
336     templates \texttt{library\_template.tmpl},
337     \texttt{UnitTest\_template.tmpl} and
338     \texttt{binaryApp\_template.tmpl} respectively. Thus, any
339     source files in a directory \texttt{src} at package-level will
340     source the template \texttt{library\_template.tmpl} for build
341     rules to build a library. Likewise, binary applications will be
342     built from sources located in any directory called
343     \texttt{application} using a template
344     \texttt{binaryApp\_template.tmpl}.
345    
346     \example{ProductStore Example} To create separate \texttt{include},
347     \texttt{bin} and \texttt{lib} subdirectories, all of which are
348     architecture-dependent, the following tags would be added to the project \texttt{BuildFile}:
349     \index{\texttt{ProductStore} tag!example}
350     %% \small{\begin{verbatim}
351     %% <ProductStore name=include type=arch></ProductStore>
352     %% <ProductStore name=lib type=arch></ProductStore>
353     %% <ProductStore name=bin type=arch></ProductStore>
354     %% <ProductStore name=module type=arch swap=t></ProductStore>
355     %% \end{verbatim}}\normalsize
356    
357     \ni In the above example, the storage location for modules is architecture-dependent and is
358     created as \texttt{module/rh73\_gcc32} on a system with a \scram
359     architecture \texttt{rh73\_gcc32}. The other directories
360     (\texttt{bin}, \texttt{lib} and \texttt{include}) are created under a
361     directory \texttt{rh73\_gcc32} in the project area.
362    
363    
364     \ni Here are two examples of how the tag might be used.
365     \index{using external libraries!example}
366     \example{Example 1} Working in a local area, you want to link against
367     the X11 libraries. Firstly, X11 must be an external tool that is
368     available in your project configuration. You can check this by seeing
369     if X11 is listed when you run \texttt{scram tool list}. Then just add
370     the line
371    
372     \begin{tagprint}
373     \lbkt\texttt{external} ref=\texttt{X11}\rbkt
374     \end{tagprint}
375    
376     \ni to your \texttt{BuildFile} to use the X11 libraries.
377    
378    
379     \example{Example 2} You are developing code which is dependent on
380     another \textsc{scram}-managed project called \texttt{fooproject}.
381     Following the previous example would result in all of the project
382     libraries being used. However, if libraries belonging to one
383     particular subsystem are required, and only these libraries, the line
384    
385     \begin{tagprint}
386     \lbkt\texttt{external} ref=\texttt{fooproject} use=\texttt{barsub}\rbkt
387     \end{tagprint}
388    
389     \ni will select only the subsystem \texttt{barsub}.
390    
391     \example{Example Binary BuildFile} Here is an example of a
392     \texttt{BuildFile} to build two binary executables:
393    
394     \small{\begin{verbatim}
395     <environment>
396     <Group name=SimReader>
397     <Use name=CARF>
398     <bin file=testSimReader.cpp>SimReader test executable</bin>
399     <bin file=testObserver.cpp>Observer test executable</bin>
400     </environment>
401     \end{verbatim}}\normalsize
402    
403     \ni The object files for both binaries are linked against the
404     libraries provided by group \texttt{SimReader} which is defined in the
405     \texttt{CARF} subsystem \texttt{BuildFile} to produce the executables.
406    
407     \example{Example Module BuildFile} This example will build
408     two separate modules:
409    
410     \small{\begin{verbatim}
411     <environment>
412     <Group name=BaseUtilities>
413     <Use name=Utilities>
414     <module file=BaseUtilitiesModule.cpp>Base utilities plug-in</module>
415     </environment>
416    
417     <environment>
418     <Group name=Persistency>
419     <Use name=Utilities>
420     <module file=PersistencyModule.cpp>Persistency layer</module>
421     </environment>
422     \end{verbatim}}\normalsize
423    
424     \example{Adding a New Rule} Suppose that for a package called
425     \texttt{myPackage}, some additional library should be built in
426     addition to the default library \texttt{libmyPackage.so}.
427     The typical \tagstart{ClassPath} entry to build a library looks like
428     this
429     %% \small{\begin{verbatim}
430     %% <ClassPath path=+Project/myPackage+Package/src+library>
431     %% \end{verbatim}}\normalsize
432     %% \ni and this uses a makefile called \texttt{library\_makefile.tmpl}.
433     %% At the top of this makefile there exists a statement for the default
434     %% build, namely,
435     %% \small{\begin{verbatim}
436     %% # Package Context Defaults
437     %% library : lib
438     %% \end{verbatim}}\normalsize
439     %% \ni A new build rule called \texttt{customlib} can be defined in the
440     %% structure makefile: if it is added above, it will be run by default
441     %% when building \textit{any} library.
442     %% For this action to take place only for the package \texttt{myPackage},
443     %% it is best to create a new structure makefile with a different name,
444     %% say \texttt{myCustomlib\_makefile.tmpl}, in which the new rule is
445     %% defined. Now the statement in \texttt{myCustomlib\_makefile.tmpl}
446     %% for the default build looks like this
447    
448     %% \small{\begin{verbatim}
449     %% # Package Context Defaults
450     %% myCustomlib : lib customlib
451     %% \end{verbatim}}\normalsize
452    
453     %% \ni and the corresponding \tagstart{ClassPath}
454    
455     %% \small{\begin{verbatim}
456     %% <ClassPath path=+Project/myPackage+Package/src+myCustomlib>
457     %% \end{verbatim}}\normalsize
458    
459     \ni will ensure that the new rule is used when building in the
460     \texttt{src/myPackage} directory.
461    
462     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463    
464     %%% Local Variables:
465     %%% mode: latex
466     %%% TeX-master: "SCRAM-manual"
467     %%% End:
468    
469     %%____________________________________________________________________
470     %% End of Examples.tex
471     %%____________________________________________________________________
472     %%