]>
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 :: buildPackageTrust ( int newtrust
)
161 if ( newtrust
!= TRUST_UNKNOWN
)
163 cbpv
= cygpackage :: createInstance ( cp
-> name
);
164 cspv
= packageversion ();
169 IniDBBuilderPackage :: buildPackageCategory ( String
const & name
)
171 cp
-> add_category ( name
);
174 void dumpAndList ( vector
< vector
< PackageSpecification
*> *> * currentAndList
)
178 log ( LOG_BABBLE
) << "AND list is:" << endLog
;
179 for ( vector
< vector
< PackageSpecification
*> *>:: const_iterator iAnd
=
180 currentAndList
-> begin (); iAnd
!= currentAndList
-> end (); ++ iAnd
)
182 for ( vector
< PackageSpecification
*>:: const_iterator i
=
184 i
!= (* iAnd
)-> end (); ++ i
)
185 log ( LOG_BABBLE
) << ** i
<< " |" << endLog
;
186 log ( LOG_BABBLE
) << "end of OR list," << endLog
;
192 IniDBBuilderPackage :: buildBeginDepends ()
195 log ( LOG_BABBLE
) << "Beginning of a depends statement for " << cp
-> name
197 dumpAndList ( currentAndList
);
200 currentOrList
= NULL
; /* set by the build AndListNode */
201 currentAndList
= cbpv
. depends ();
205 IniDBBuilderPackage :: buildBeginPreDepends ()
208 log ( LOG_BABBLE
) << "Beginning of a predepends statement" << endLog
;
209 dumpAndList ( currentAndList
);
212 currentOrList
= NULL
; /* set by the build AndListNode */
213 currentAndList
= cbpv
. predepends ();
217 IniDBBuilderPackage :: buildPriority ( String
const & priority
)
219 cp
-> priority
= priority
;
221 log ( LOG_BABBLE
) << "Package " << cp
-> name
<< " is " << priority
<< endLog
;
226 IniDBBuilderPackage :: buildInstalledSize ( String
const & size
)
228 cbpv
. source ()-> setInstalledSize ( atoi ( size
. cstr_oneuse ()));
230 log ( LOG_BABBLE
) << "Installed size for " << cp
-> name
<< " is " << cpv
-> bin
. installedSize () << endLog
;
235 IniDBBuilderPackage :: buildMaintainer ( String
const &){}
237 /* TODO: we can multiple arch's for a given package,
238 and it may befor either source or binary, so we need to either set both
239 or track a third current package that points to whether we altering source
240 or binary at the moment
243 IniDBBuilderPackage :: buildArchitecture ( String
const & arch
)
245 cp
-> architecture
= arch
;
247 log ( LOG_BABBLE
) << "Package " << cp
-> name
<< " is for " << arch
<< " architectures." << endLog
;
252 IniDBBuilderPackage :: buildInstallSize ( String
const & size
)
254 setSourceSize (* cbpv
. source (), size
);
258 IniDBBuilderPackage :: buildInstallMD5 ( unsigned char const * md5
)
260 if ( md5
&& ! cbpv
. source ()-> md5
. isSet ())
261 cbpv
. source ()-> md5
. set ( md5
);
265 IniDBBuilderPackage :: buildSourceMD5 ( unsigned char const * md5
)
267 if ( md5
&& ! cspv
. source ()-> md5
. isSet ())
268 cspv
. source ()-> md5
. set ( md5
);
272 IniDBBuilderPackage :: buildBeginRecommends ()
275 log ( LOG_BABBLE
) << "Beginning of a recommends statement" << endLog
;
276 dumpAndList ( currentAndList
);
279 currentOrList
= NULL
; /* set by the build AndListNode */
280 currentAndList
= cbpv
. recommends ();
284 IniDBBuilderPackage :: buildBeginSuggests ()
287 log ( LOG_BABBLE
) << "Beginning of a suggests statement" << endLog
;
288 dumpAndList ( currentAndList
);
291 currentOrList
= NULL
; /* set by the build AndListNode */
292 currentAndList
= cbpv
. suggests ();
296 IniDBBuilderPackage :: buildBeginReplaces ()
299 log ( LOG_BABBLE
) << "Beginning of a replaces statement" << endLog
;
300 dumpAndList ( currentAndList
);
303 currentOrList
= NULL
; /* set by the build AndListNode */
304 currentAndList
= cbpv
. replaces ();
308 IniDBBuilderPackage :: buildBeginConflicts ()
311 log ( LOG_BABBLE
) << "Beginning of a conflicts statement" << endLog
;
312 dumpAndList ( currentAndList
);
315 currentOrList
= NULL
; /* set by the build AndListNode */
316 currentAndList
= cbpv
. conflicts ();
320 IniDBBuilderPackage :: buildBeginProvides ()
323 log ( LOG_BABBLE
) << "Beginning of a provides statement" << endLog
;
324 dumpAndList ( currentAndList
);
327 currentOrList
= NULL
; /* set by the build AndListNode */
328 currentAndList
= cbpv
. provides ();
332 IniDBBuilderPackage :: buildBeginBuildDepends ()
335 log ( LOG_BABBLE
) << "Beginning of a Build-Depends statement" << endLog
;
336 dumpAndList ( currentAndList
);
339 currentOrList
= NULL
; /* set by the build AndListNode */
340 currentAndList
= cspv
. depends ();
345 IniDBBuilderPackage :: buildBeginBinary ()
348 log ( LOG_BABBLE
) << "Beginning of a Binary statement" << endLog
;
349 dumpAndList ( currentAndList
);
352 currentOrList
= NULL
; /* set by the build AndListNode */
353 currentAndList
= cspv
. binaries ();
357 IniDBBuilderPackage :: buildDescription ( String
const & descline
)
361 cbpv
. set_ldesc ( cbpv
. LDesc () + descline
+ " \n " );
363 log ( LOG_BABBLE
) << "Description for " << cp
-> name
<< ": \" " <<
364 descline
<< " \" ." << endLog
;
368 _feedback
. warning (( String ( "Attempt to set description for package" )
370 + "before creation of a version." ). cstr_oneuse ());
374 IniDBBuilderPackage :: buildSourceName ( String
const & name
)
378 cbpv
. setSourcePackageSpecification ( PackageSpecification ( name
));
380 log ( LOG_BABBLE
) << " \" " << cpv
-> sourcePackageSpecification () <<
381 " \" is the source package for " << cp
-> name
<< "." << endLog
;
385 _feedback
. warning (( String ( "Attempt to set source for package" )
387 + "before creation of a version." ). cstr_oneuse ());
391 IniDBBuilderPackage :: buildSourceNameVersion ( String
const & version
)
395 cbpv
. sourcePackageSpecification (). setOperator ( PackageSpecification :: Equals
);
396 cbpv
. sourcePackageSpecification (). setVersion ( version
);
398 log ( LOG_BABBLE
) << "The source version needed for " << cp
-> name
<<
399 " is " << version
<< "." << endLog
;
403 _feedback
. warning (( String ( "Attempt to set source version for package" )
405 + "before creation of a version." ). cstr_oneuse ());
409 IniDBBuilderPackage :: buildPackageListAndNode ()
414 log ( LOG_BABBLE
) << "New AND node for a package list" << endLog
;
417 ostream
& os
= log ( LOG_BABBLE
);
418 os
<< "Current OR list is :" ;
419 for ( vector
< PackageSpecification
*>:: const_iterator i
= currentOrList
-> begin ();
420 i
!= currentOrList
-> end (); ++ i
)
426 currentOrList
= new vector
< PackageSpecification
*>;
427 currentAndList
-> push_back ( currentOrList
);
430 _feedback
. warning (( String ( "Attempt to add And node when no AndList"
431 " present for package " )
432 + cp
-> name
). cstr_oneuse ());
436 IniDBBuilderPackage :: buildPackageListOrNode ( String
const & packageName
)
440 currentSpec
= new PackageSpecification ( packageName
);
441 currentOrList
-> push_back ( currentSpec
);
443 log ( LOG_BABBLE
) << "New OR node in a package list refers to \" " <<
444 * currentSpec
<< " \" ." << endLog
;
448 _feedback
. warning (( String ( "Attempt to set specification for package " )
450 + " before creation of a version." ). cstr_oneuse ());
454 IniDBBuilderPackage :: buildPackageListOperator ( PackageSpecification :: _operators
const & _operator
)
458 currentSpec
-> setOperator ( _operator
);
460 log ( LOG_BABBLE
) << "Current specification is " << * currentSpec
<< "." <<
465 _feedback
. warning (( String ( "Attempt to set an operator for package " )
467 + " with no current specification." ). cstr_oneuse ());
472 IniDBBuilderPackage :: buildPackageListOperatorVersion ( String
const & aVersion
)
476 currentSpec
-> setVersion ( aVersion
);
478 log ( LOG_BABBLE
) << "Current specification is " << * currentSpec
<< "." <<
483 _feedback
. warning (( String ( "Attempt to set an operator version for package " )
485 + " with no current specification." ). cstr_oneuse ());
491 IniDBBuilderPackage :: add_correct_version ()
494 for ( set
< packageversion
>:: iterator n
= cp
-> versions
. begin ();
495 ! merged
&& n
!= cp
-> versions
. end (); ++ n
)
498 packageversion ver
= * n
;
500 categories and requires are consistent for the same version across
503 /* Copy the binary mirror across if this site claims to have an install */
504 if ( cbpv
. source ()-> sites
. size () )
505 ver
. source ()-> sites
. push_back ( site ( cbpv
. source ()-> sites
. begin ()-> key
));
506 /* Copy the descriptions across */
507 if ( cbpv
. SDesc (). size () && ! n
-> SDesc (). size ())
508 ver
. set_sdesc ( cbpv
. SDesc ());
509 if ( cbpv
. LDesc (). size () && ! n
-> LDesc (). size ())
510 ver
. set_ldesc ( cbpv
. LDesc ());
511 if ( cbpv
. depends ()-> size () && ! ver
. depends ()-> size ())
512 * ver
. depends () = * cbpv
. depends ();
513 /* TODO: other package lists */
514 /* Prevent dangling references */
515 currentOrList
= NULL
;
516 currentAndList
= NULL
;
522 cp
-> add_version ( cbpv
);
527 if ( cp
-> currtimestamp
< timestamp
)
529 cp
-> currtimestamp
= timestamp
;
534 if ( cp
-> prevtimestamp
< timestamp
)
536 cp
-> prevtimestamp
= timestamp
;
541 if ( cp
-> exptimestamp
< timestamp
)
543 cp
-> exptimestamp
= timestamp
;
551 IniDBBuilderPackage :: process_src ( packagesource
& src
, String
const & path
)
553 if (! src
. Canonical ())
554 src
. set_canonical ( path
. cstr_oneuse ());
555 src
. sites
. push_back ( site ( parse_mirror
));
557 if (! cbpv
. Canonical_version (). size ())
560 if ( parse_filename ( path
, f
))
562 cbpv
. setCanonicalVersion ( f
. ver
);
563 add_correct_version ();
569 IniDBBuilderPackage :: setSourceSize ( packagesource
& src
, String
const & size
)
572 src
. size
= atoi ( size
. cstr_oneuse ());
This page took 0.100601 seconds and 5 git commands to generate.