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"
18 #include "csu_util/version_compare.h"
20 #include "setup_version.h"
22 #include "IniParseFeedback.h"
23 #include "package_db.h"
24 #include "package_meta.h"
28 #include "LogSingleton.h"
29 #include "PackageSpecification.h"
32 IniDBBuilderPackage::IniDBBuilderPackage (IniParseFeedback
const &aFeedback
) :
33 currentSpec (0), _feedback (aFeedback
), minimum_version_checked(FALSE
) {}
35 IniDBBuilderPackage::~IniDBBuilderPackage()
39 db
.solver
.internalize();
43 IniDBBuilderPackage::buildTimestamp (const std::string
& time
)
45 timestamp
= strtoul (time
.c_str(), 0, 0);
49 IniDBBuilderPackage::buildVersion (const std::string
& aVersion
)
53 /* We shouldn't need to warn about potential setup.ini parse problems if we
54 exceed the version in setup-minimum-version: (we will still advise about a
55 possible setup upgrade in do_ini_thread()). If we don't exceed
56 setup-minimum-version:, we've already encountered a fatal error, so no need
58 if (minimum_version_checked
)
63 if (version_compare(setup_version
, version
) < 0)
66 snprintf (old_vers
, sizeof old_vers
,
67 "The current ini file is from a newer version of setup-%s.exe. "
68 "If you have any trouble installing, please download a fresh "
69 "version from https://cygwin.com/setup-%s.exe",
70 is_64bit
? "x86_64" : "x86",
71 is_64bit
? "x86_64" : "x86");
72 _feedback
.warning(old_vers
);
78 IniDBBuilderPackage::buildMinimumVersion (const std::string
& minimum
)
80 minimum_version_checked
= TRUE
;
81 if (version_compare(setup_version
, minimum
) < 0)
84 snprintf (min_vers
, sizeof(min_vers
),
85 "The current ini file requires at least version %s of setup.\n"
86 "Please download a newer version from https://cygwin.com/setup-%s.exe",
88 is_64bit
? "x86_64" : "x86");
95 IniDBBuilderPackage::buildPackage (const std::string
& _name
)
99 /* Reset for next package */
104 replace_versions
.clear();
106 cbpv
.reponame
= release
;
108 cbpv
.vendor
= release
;
111 cbpv
.stability
= TRUST_CURR
;
112 cbpv
.type
= package_binary
;
113 cbpv
.spkg
= PackageSpecification();
114 cbpv
.spkg_id
= packageversion();
115 cbpv
.requires
= NULL
;
116 cbpv
.obsoletes
= NULL
;
117 cbpv
.provides
= NULL
;
118 cbpv
.conflicts
= NULL
;
119 cbpv
.archive
= packagesource();
122 currentNodeList
= NULL
;
123 dependsNodeList
= PackageDepends();
124 obsoletesNodeList
= PackageDepends();
125 providesNodeList
= PackageDepends();
126 conflictsNodeList
= PackageDepends();
128 Log (LOG_BABBLE
) << "Created package " << name
<< endLog
;
133 IniDBBuilderPackage::buildPackageVersion (const std::string
& version
)
135 cbpv
.version
= version
;
139 IniDBBuilderPackage::buildPackageSDesc (const std::string
& theDesc
)
141 cbpv
.sdesc
= theDesc
;
145 IniDBBuilderPackage::buildPackageLDesc (const std::string
& theDesc
)
147 cbpv
.ldesc
= theDesc
;
151 IniDBBuilderPackage::buildPackageInstall (const std::string
& path
,
152 const std::string
& size
,
156 // set archive path, size, mirror, hash
157 cbpv
.archive
.set_canonical(path
.c_str());
158 cbpv
.archive
.size
= atoi(size
.c_str());
159 cbpv
.archive
.sites
.push_back(site(parse_mirror
));
162 case hashType::sha512
:
163 if (hash
&& !cbpv
.archive
.sha512_isSet
)
165 memcpy (cbpv
.archive
.sha512sum
, hash
, sizeof(cbpv
.archive
.sha512sum
));
166 cbpv
.archive
.sha512_isSet
= true;
171 if (hash
&& !cbpv
.archive
.md5
.isSet())
172 cbpv
.archive
.md5
.set((unsigned char *)hash
);
181 IniDBBuilderPackage::buildPackageSource (const std::string
& path
,
182 const std::string
& size
,
186 /* When there is a source: line, we invent a package to contain the source,
187 and make it the source package for this package. */
189 /* create a source package version */
190 SolverPool::addPackageData cspv
= cbpv
;
191 cspv
.type
= package_source
;
192 cspv
.requires
= NULL
;
193 cspv
.obsoletes
= NULL
;
194 cspv
.provides
= NULL
;
195 cspv
.conflicts
= NULL
;
197 /* set archive path, size, mirror, hash */
198 cspv
.archive
= packagesource();
199 cspv
.archive
.set_canonical(path
.c_str());
200 cspv
.archive
.size
= atoi(size
.c_str());
201 cspv
.archive
.sites
.push_back(site(parse_mirror
));
204 case hashType::sha512
:
205 if (hash
&& !cspv
.archive
.sha512_isSet
)
207 memcpy (cspv
.archive
.sha512sum
, hash
, sizeof(cspv
.archive
.sha512sum
));
208 cspv
.archive
.sha512_isSet
= true;
213 if (hash
&& !cspv
.archive
.md5
.isSet())
214 cspv
.archive
.md5
.set((unsigned char *)hash
);
222 packageversion spkg_id
= db
.addSource (name
+ "-src", cspv
);
224 /* create relationship between binary and source packageversions */
225 cbpv
.spkg
= PackageSpecification(name
+ "-src");
226 cbpv
.spkg_id
= spkg_id
;
230 IniDBBuilderPackage::buildPackageTrust (trusts newtrust
)
233 cbpv
.stability
= newtrust
;
237 IniDBBuilderPackage::buildPackageCategory (const std::string
& name
)
239 categories
.insert(name
);
243 IniDBBuilderPackage::buildBeginDepends ()
246 Log (LOG_BABBLE
) << "Beginning of a depends statement " << endLog
;
249 dependsNodeList
= PackageDepends();
250 currentNodeList
= &dependsNodeList
;
251 cbpv
.requires
= &dependsNodeList
;
255 IniDBBuilderPackage::buildBeginBuildDepends ()
258 Log (LOG_BABBLE
) << "Beginning of a Build-Depends statement" << endLog
;
261 currentNodeList
= NULL
;
262 /* there is currently nowhere to store Build-Depends information */
266 IniDBBuilderPackage::buildBeginObsoletes ()
269 Log (LOG_BABBLE
) << "Beginning of an obsoletes statement" << endLog
;
272 obsoletesNodeList
= PackageDepends();
273 currentNodeList
= &obsoletesNodeList
;
274 cbpv
.obsoletes
= &obsoletesNodeList
;
278 IniDBBuilderPackage::buildBeginProvides ()
281 Log (LOG_BABBLE
) << "Beginning of a provides statement" << endLog
;
284 providesNodeList
= PackageDepends();
285 currentNodeList
= &providesNodeList
;
286 cbpv
.provides
= &providesNodeList
;
290 IniDBBuilderPackage::buildBeginConflicts ()
293 Log (LOG_BABBLE
) << "Beginning of a conflicts statement" << endLog
;
296 conflictsNodeList
= PackageDepends();
297 currentNodeList
= &conflictsNodeList
;
298 cbpv
.conflicts
= &conflictsNodeList
;
302 IniDBBuilderPackage::buildSourceName (const std::string
& _name
)
304 // When there is a Source: line, that names a real source package
306 cbpv
.spkg
= PackageSpecification(_name
);
307 cbpv
.spkg_id
= db
.findSourceVersion (PackageSpecification(_name
, cbpv
.version
));
309 Log (LOG_BABBLE
) << "\"" << _name
<< "\" is the source package for " << name
<< "." << endLog
;
314 IniDBBuilderPackage::buildSourceNameVersion (const std::string
& version
)
316 // XXX: should be stored as sourceevr
320 IniDBBuilderPackage::buildPackageListNode (const std::string
& name
)
323 Log (LOG_BABBLE
) << "New node '" << name
<< "' for package list" << endLog
;
325 currentSpec
= new PackageSpecification (name
);
327 currentNodeList
->push_back (currentSpec
);
331 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators
const &_operator
)
335 currentSpec
->setOperator (_operator
);
337 Log (LOG_BABBLE
) << "Current specification is " << *currentSpec
<< "." <<
344 IniDBBuilderPackage::buildPackageListOperatorVersion (const std::string
& aVersion
)
348 currentSpec
->setVersion (aVersion
);
350 Log (LOG_BABBLE
) << "Current specification is " << *currentSpec
<< "." <<
357 IniDBBuilderPackage::buildMessage (const std::string
& _message_id
, const std::string
& _message_string
)
359 message_id
= _message_id
;
360 message_string
= _message_string
;
364 IniDBBuilderPackage::buildPackageReplaceVersionsList (const std::string
& version
)
366 replace_versions
.insert(version
);
371 IniDBBuilderPackage::process ()
376 if (cbpv
.version
.empty())
379 // no install: line, no package
380 if (!cbpv
.archive
.Canonical())
384 Log (LOG_BABBLE
) << "Finished with package " << name
<< endLog
;
385 Log (LOG_BABBLE
) << "Version " << cbpv
.version
<< endLog
;
388 /* Transfer the accumulated package information to packagedb */
390 packagemeta
*pkg
= db
.addBinary (name
, cbpv
);
392 // For no good historical reason, some data lives in packagemeta rather than
393 // the packageversion
394 for (auto i
= categories
.begin(); i
!= categories
.end(); i
++)
396 pkg
->add_category(*i
);
398 pkg
->set_message(message_id
, message_string
);
399 pkg
->set_version_blacklist(replace_versions
);
401 // Reset for next version
403 cbpv
.type
= package_binary
;
404 cbpv
.spkg
= PackageSpecification();
405 cbpv
.spkg_id
= packageversion();
406 cbpv
.archive
= packagesource();
407 obsoletesNodeList
= PackageDepends();
408 providesNodeList
= PackageDepends();
409 conflictsNodeList
= PackageDepends();