]>
cygwin.com Git - cygwin-apps/setup.git/blob - IniDBBuilderPackage.cc
2 * Copyright (c) 2002, Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #include "IniDBBuilderPackage.h"
17 #include "IniParseFeedback.h"
18 #include "package_db.h"
19 #include "package_meta.h"
20 #include "package_version.h"
21 #include "cygpackage.h"
22 #include "filemanip.h"
26 #include "LogSingleton.h"
27 #include "PackageSpecification.h"
30 IniDBBuilderPackage :: IniDBBuilderPackage ( IniParseFeedback
const & aFeedback
) :
31 cp ( 0 ), cbpv (), cspv (), currentSpec ( 0 ), currentOrList ( 0 ), currentAndList ( 0 ), trust ( 0 ), _feedback ( aFeedback
){}
34 IniDBBuilderPackage :: buildTimestamp ( String
const & time
)
36 timestamp
= strtoul ( time
. cstr_oneuse (), 0 , 0 );
40 IniDBBuilderPackage :: buildVersion ( String
const & aVersion
)
45 String ini_version
= canonicalize_version ( version
);
46 String our_version
= canonicalize_version (:: version
);
47 // XXX useversion < operator
48 if ( our_version
. compare ( ini_version
) < 0 )
49 _feedback
. warning ( "The current ini file is from a newer version of setup.exe. If you have any trouble installing, please download a fresh version from http://www.cygwin.com/setup.exe" );
53 void dumpAndList ( vector
< vector
< PackageSpecification
*> *> * currentAndList
);
56 IniDBBuilderPackage :: buildPackage ( String
const & name
)
61 log ( LOG_BABBLE
) << "Finished with package " << cp
-> name
<< endLog
;
64 log ( LOG_BABBLE
) << "Version " << cbpv
. Canonical_version () << endLog
;
65 log ( LOG_BABBLE
) << "Depends:" << endLog
;
66 dumpAndList ( cbpv
. depends ());
71 cp
= db
. findBinary ( PackageSpecification ( name
));
74 cp
= new packagemeta ( name
);
75 db
. packages
. push_back ( cp
);
77 cbpv
= cygpackage :: createInstance ( name
);
78 cspv
= packageversion ();
81 currentAndList
= NULL
;
84 log ( LOG_BABBLE
) << "Created package " << name
<< endLog
;
89 IniDBBuilderPackage :: buildPackageVersion ( String
const & version
)
91 cbpv
. setCanonicalVersion ( version
);
92 add_correct_version ();
96 IniDBBuilderPackage :: buildPackageSDesc ( String
const & theDesc
)
98 cbpv
. set_sdesc ( theDesc
);
102 IniDBBuilderPackage :: buildPackageLDesc ( String
const & theDesc
)
104 cbpv
. set_ldesc ( theDesc
);
106 _feedback
. warning ( theDesc
. cstr_oneuse ());
111 IniDBBuilderPackage :: buildPackageInstall ( String
const & path
)
113 process_src (* cbpv
. source (), path
);
117 IniDBBuilderPackage :: buildPackageSource ( String
const & path
, String
const & size
)
120 /* get an appropriate metadata */
121 csp
= db
. findSource ( PackageSpecification ( cbpv
. Name ()));
124 /* Copy the existing meta data to a new source package */
125 csp
= new packagemeta (* cp
);
126 /* delete versions information */
127 csp
-> versions
. clear ();
128 csp
-> desired
= packageversion ();
129 csp
-> installed
= packageversion ();
130 csp
-> prev
= packageversion ();
131 csp
-> curr
= packageversion ();
132 csp
-> exp
= packageversion ();
133 db
. sourcePackages
. push_back ( csp
);
135 /* create a source packageversion */
136 cspv
= cygpackage :: createInstance ( cbpv
. Name ());
137 cspv
. setCanonicalVersion ( cbpv
. Canonical_version ());
138 set
< packageversion
>:: iterator i
= find ( csp
-> versions
. begin (),
139 csp
-> versions
. end (), cspv
);
140 if ( i
== csp
-> versions
. end ())
142 csp
-> add_version ( cspv
);
147 if (! cspv
. source ()-> Canonical ())
148 cspv
. source ()-> set_canonical ( path
. cstr_oneuse ());
149 cspv
. source ()-> sites
. push_back ( site ( parse_mirror
));
151 cbpv
. setSourcePackageSpecification ( PackageSpecification ( cspv
. Name ()));
153 // process_src (*cspv.source(), path);
154 setSourceSize (* cspv
. source (), size
);
158 IniDBBuilderPackage :: buildSourceFile ( unsigned char const * md5
, String
const & size
, String
const & path
)
163 IniDBBuilderPackage :: buildPackageTrust ( int newtrust
)
166 if ( newtrust
!= TRUST_UNKNOWN
)
168 cbpv
= cygpackage :: createInstance ( cp
-> name
);
169 cspv
= packageversion ();
174 IniDBBuilderPackage :: buildPackageCategory ( String
const & name
)
176 cp
-> add_category ( name
);
179 void dumpAndList ( vector
< vector
< PackageSpecification
*> *> * currentAndList
)
183 log ( LOG_BABBLE
) << "AND list is:" << endLog
;
184 for ( vector
< vector
< PackageSpecification
*> *>:: const_iterator iAnd
=
185 currentAndList
-> begin (); iAnd
!= currentAndList
-> end (); ++ iAnd
)
187 for ( vector
< PackageSpecification
*>:: const_iterator i
=
189 i
!= (* iAnd
)-> end (); ++ i
)
190 log ( LOG_BABBLE
) << ** i
<< " |" << endLog
;
191 log ( LOG_BABBLE
) << "end of OR list," << endLog
;
197 IniDBBuilderPackage :: buildBeginDepends ()
200 log ( LOG_BABBLE
) << "Beginning of a depends statement for " << cp
-> name
202 dumpAndList ( currentAndList
);
205 currentOrList
= NULL
; /* set by the build AndListNode */
206 currentAndList
= cbpv
. depends ();
210 IniDBBuilderPackage :: buildBeginPreDepends ()
213 log ( LOG_BABBLE
) << "Beginning of a predepends statement" << endLog
;
214 dumpAndList ( currentAndList
);
217 currentOrList
= NULL
; /* set by the build AndListNode */
218 currentAndList
= cbpv
. predepends ();
222 IniDBBuilderPackage :: buildPriority ( String
const & priority
)
224 cp
-> priority
= priority
;
226 log ( LOG_BABBLE
) << "Package " << cp
-> name
<< " is " << priority
<< endLog
;
231 IniDBBuilderPackage :: buildInstalledSize ( String
const & size
)
233 cbpv
. source ()-> setInstalledSize ( atoi ( size
. cstr_oneuse ()));
235 log ( LOG_BABBLE
) << "Installed size for " << cp
-> name
<< " is " << cpv
-> bin
. installedSize () << endLog
;
240 IniDBBuilderPackage :: buildMaintainer ( String
const &){}
242 /* TODO: we can multiple arch's for a given package,
243 and it may befor either source or binary, so we need to either set both
244 or track a third current package that points to whether we altering source
245 or binary at the moment
248 IniDBBuilderPackage :: buildArchitecture ( String
const & arch
)
250 cp
-> architecture
= arch
;
252 log ( LOG_BABBLE
) << "Package " << cp
-> name
<< " is for " << arch
<< " architectures." << endLog
;
257 IniDBBuilderPackage :: buildInstallSize ( String
const & size
)
259 setSourceSize (* cbpv
. source (), size
);
263 IniDBBuilderPackage :: buildInstallMD5 ( unsigned char const * md5
)
265 if ( md5
&& ! cbpv
. source ()-> md5
. isSet ())
266 cbpv
. source ()-> md5
. set ( md5
);
270 IniDBBuilderPackage :: buildSourceMD5 ( unsigned char const * md5
)
272 if ( md5
&& ! cspv
. source ()-> md5
. isSet ())
273 cspv
. source ()-> md5
. set ( md5
);
277 IniDBBuilderPackage :: buildBeginRecommends ()
280 log ( LOG_BABBLE
) << "Beginning of a recommends statement" << endLog
;
281 dumpAndList ( currentAndList
);
284 currentOrList
= NULL
; /* set by the build AndListNode */
285 currentAndList
= cbpv
. recommends ();
289 IniDBBuilderPackage :: buildBeginSuggests ()
292 log ( LOG_BABBLE
) << "Beginning of a suggests statement" << endLog
;
293 dumpAndList ( currentAndList
);
296 currentOrList
= NULL
; /* set by the build AndListNode */
297 currentAndList
= cbpv
. suggests ();
301 IniDBBuilderPackage :: buildBeginReplaces ()
304 log ( LOG_BABBLE
) << "Beginning of a replaces statement" << endLog
;
305 dumpAndList ( currentAndList
);
308 currentOrList
= NULL
; /* set by the build AndListNode */
309 currentAndList
= cbpv
. replaces ();
313 IniDBBuilderPackage :: buildBeginConflicts ()
316 log ( LOG_BABBLE
) << "Beginning of a conflicts statement" << endLog
;
317 dumpAndList ( currentAndList
);
320 currentOrList
= NULL
; /* set by the build AndListNode */
321 currentAndList
= cbpv
. conflicts ();
325 IniDBBuilderPackage :: buildBeginProvides ()
328 log ( LOG_BABBLE
) << "Beginning of a provides statement" << endLog
;
329 dumpAndList ( currentAndList
);
332 currentOrList
= NULL
; /* set by the build AndListNode */
333 currentAndList
= cbpv
. provides ();
337 IniDBBuilderPackage :: buildBeginBuildDepends ()
340 log ( LOG_BABBLE
) << "Beginning of a Build-Depends statement" << endLog
;
341 dumpAndList ( currentAndList
);
344 currentOrList
= NULL
; /* set by the build AndListNode */
345 currentAndList
= cspv
. depends ();
350 IniDBBuilderPackage :: buildBeginBinary ()
353 log ( LOG_BABBLE
) << "Beginning of a Binary statement" << endLog
;
354 dumpAndList ( currentAndList
);
357 currentOrList
= NULL
; /* set by the build AndListNode */
358 currentAndList
= cspv
. binaries ();
362 IniDBBuilderPackage :: buildDescription ( String
const & descline
)
366 cbpv
. set_ldesc ( cbpv
. LDesc () + descline
+ " \n " );
368 log ( LOG_BABBLE
) << "Description for " << cp
-> name
<< ": \" " <<
369 descline
<< " \" ." << endLog
;
373 _feedback
. warning (( String ( "Attempt to set description for package" )
375 + "before creation of a version." ). cstr_oneuse ());
379 IniDBBuilderPackage :: buildSourceName ( String
const & name
)
383 cbpv
. setSourcePackageSpecification ( PackageSpecification ( name
));
385 log ( LOG_BABBLE
) << " \" " << cpv
-> sourcePackageSpecification () <<
386 " \" is the source package for " << cp
-> name
<< "." << endLog
;
390 _feedback
. warning (( String ( "Attempt to set source for package" )
392 + "before creation of a version." ). cstr_oneuse ());
396 IniDBBuilderPackage :: buildSourceNameVersion ( String
const & version
)
400 cbpv
. sourcePackageSpecification (). setOperator ( PackageSpecification :: Equals
);
401 cbpv
. sourcePackageSpecification (). setVersion ( version
);
403 log ( LOG_BABBLE
) << "The source version needed for " << cp
-> name
<<
404 " is " << version
<< "." << endLog
;
408 _feedback
. warning (( String ( "Attempt to set source version for package" )
410 + "before creation of a version." ). cstr_oneuse ());
414 IniDBBuilderPackage :: buildPackageListAndNode ()
419 log ( LOG_BABBLE
) << "New AND node for a package list" << endLog
;
422 ostream
& os
= log ( LOG_BABBLE
);
423 os
<< "Current OR list is :" ;
424 for ( vector
< PackageSpecification
*>:: const_iterator i
= currentOrList
-> begin ();
425 i
!= currentOrList
-> end (); ++ i
)
431 currentOrList
= new vector
< PackageSpecification
*>;
432 currentAndList
-> push_back ( currentOrList
);
435 _feedback
. warning (( String ( "Attempt to add And node when no AndList"
436 " present for package " )
437 + cp
-> name
). cstr_oneuse ());
441 IniDBBuilderPackage :: buildPackageListOrNode ( String
const & packageName
)
445 currentSpec
= new PackageSpecification ( packageName
);
446 currentOrList
-> push_back ( currentSpec
);
448 log ( LOG_BABBLE
) << "New OR node in a package list refers to \" " <<
449 * currentSpec
<< " \" ." << endLog
;
453 _feedback
. warning (( String ( "Attempt to set specification for package " )
455 + " before creation of a version." ). cstr_oneuse ());
459 IniDBBuilderPackage :: buildPackageListOperator ( PackageSpecification :: _operators
const & _operator
)
463 currentSpec
-> setOperator ( _operator
);
465 log ( LOG_BABBLE
) << "Current specification is " << * currentSpec
<< "." <<
470 _feedback
. warning (( String ( "Attempt to set an operator for package " )
472 + " with no current specification." ). cstr_oneuse ());
477 IniDBBuilderPackage :: buildPackageListOperatorVersion ( String
const & aVersion
)
481 currentSpec
-> setVersion ( aVersion
);
483 log ( LOG_BABBLE
) << "Current specification is " << * currentSpec
<< "." <<
488 _feedback
. warning (( String ( "Attempt to set an operator version for package " )
490 + " with no current specification." ). cstr_oneuse ());
496 IniDBBuilderPackage :: add_correct_version ()
499 for ( set
< packageversion
>:: iterator n
= cp
-> versions
. begin ();
500 ! merged
&& n
!= cp
-> versions
. end (); ++ n
)
503 packageversion ver
= * n
;
505 categories and requires are consistent for the same version across
508 /* Copy the binary mirror across if this site claims to have an install */
509 if ( cbpv
. source ()-> sites
. size () )
510 ver
. source ()-> sites
. push_back ( site ( cbpv
. source ()-> sites
. begin ()-> key
));
511 /* Copy the descriptions across */
512 if ( cbpv
. SDesc (). size () && ! n
-> SDesc (). size ())
513 ver
. set_sdesc ( cbpv
. SDesc ());
514 if ( cbpv
. LDesc (). size () && ! n
-> LDesc (). size ())
515 ver
. set_ldesc ( cbpv
. LDesc ());
516 if ( cbpv
. depends ()-> size () && ! ver
. depends ()-> size ())
517 * ver
. depends () = * cbpv
. depends ();
518 /* TODO: other package lists */
519 /* Prevent dangling references */
520 currentOrList
= NULL
;
521 currentAndList
= NULL
;
527 cp
-> add_version ( cbpv
);
532 if ( cp
-> currtimestamp
< timestamp
)
534 cp
-> currtimestamp
= timestamp
;
539 if ( cp
-> prevtimestamp
< timestamp
)
541 cp
-> prevtimestamp
= timestamp
;
546 if ( cp
-> exptimestamp
< timestamp
)
548 cp
-> exptimestamp
= timestamp
;
556 IniDBBuilderPackage :: process_src ( packagesource
& src
, String
const & path
)
558 if (! src
. Canonical ())
559 src
. set_canonical ( path
. cstr_oneuse ());
560 src
. sites
. push_back ( site ( parse_mirror
));
562 if (! cbpv
. Canonical_version (). size ())
565 if ( parse_filename ( path
, f
))
567 cbpv
. setCanonicalVersion ( f
. ver
);
568 add_correct_version ();
574 IniDBBuilderPackage :: setSourceSize ( packagesource
& src
, String
const & size
)
577 src
. size
= atoi ( size
. cstr_oneuse ());
This page took 0.061144 seconds and 5 git commands to generate.