Add command-line option help-text localization
[cygwin-setup.git] / IniDBBuilderPackage.cc
blob3a8f10f8c81bf16f8bbbb4ebd9cd6e139fc56e47
1 /*
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
10 * http://www.gnu.org/
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"
25 #include "ini.h"
26 // for strtoul
27 #include <string.h>
28 #include "LogSingleton.h"
29 #include "PackageSpecification.h"
30 #include <algorithm>
32 IniDBBuilderPackage::IniDBBuilderPackage (IniParseFeedback const &aFeedback) :
33 currentSpec (0), _feedback (aFeedback), minimum_version_checked(FALSE) {}
35 IniDBBuilderPackage::~IniDBBuilderPackage()
37 process();
38 packagedb db;
39 db.solver.internalize();
42 void
43 IniDBBuilderPackage::buildTimestamp (const std::string& time)
45 timestamp = strtoul (time.c_str(), 0, 0);
48 void
49 IniDBBuilderPackage::buildVersion (const std::string& aVersion)
51 version = 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
57 to warn as well. */
58 if (minimum_version_checked)
59 return;
61 if (version.size())
63 if (version_compare(setup_version, version) < 0)
65 char old_vers[256];
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);
77 const std::string
78 IniDBBuilderPackage::buildMinimumVersion (const std::string& minimum)
80 minimum_version_checked = TRUE;
81 if (version_compare(setup_version, minimum) < 0)
83 char min_vers[256];
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",
87 minimum.c_str(),
88 is_64bit ? "x86_64" : "x86");
89 return min_vers;
91 return "";
94 void
95 IniDBBuilderPackage::buildPackage (const std::string& _name)
97 process();
99 /* Reset for next package */
100 name = _name;
101 message_id = "";
102 message_string = "";
103 categories.clear();
104 replace_versions.clear();
106 cbpv.reponame = release;
107 cbpv.version = "";
108 cbpv.vendor = release;
109 cbpv.sdesc = "";
110 cbpv.ldesc = "";
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();
121 currentSpec = NULL;
122 currentNodeList = NULL;
123 dependsNodeList = PackageDepends();
124 obsoletesNodeList = PackageDepends();
125 providesNodeList = PackageDepends();
126 conflictsNodeList = PackageDepends();
127 #if DEBUG
128 Log (LOG_BABBLE) << "Created package " << name << endLog;
129 #endif
132 void
133 IniDBBuilderPackage::buildPackageVersion (const std::string& version)
135 cbpv.version = version;
138 void
139 IniDBBuilderPackage::buildPackageSDesc (const std::string& theDesc)
141 cbpv.sdesc = theDesc;
144 void
145 IniDBBuilderPackage::buildPackageLDesc (const std::string& theDesc)
147 cbpv.ldesc = theDesc;
150 void
151 IniDBBuilderPackage::buildPackageInstall (const std::string& path,
152 const std::string& size,
153 char *hash,
154 hashType type)
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));
161 switch (type) {
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;
168 break;
170 case hashType::md5:
171 if (hash && !cbpv.archive.md5.isSet())
172 cbpv.archive.md5.set((unsigned char *)hash);
173 break;
175 case hashType::none:
176 break;
180 void
181 IniDBBuilderPackage::buildPackageSource (const std::string& path,
182 const std::string& size,
183 char *hash,
184 hashType type)
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));
203 switch (type) {
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;
210 break;
212 case hashType::md5:
213 if (hash && !cspv.archive.md5.isSet())
214 cspv.archive.md5.set((unsigned char *)hash);
215 break;
217 case hashType::none:
218 break;
221 packagedb db;
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;
229 void
230 IniDBBuilderPackage::buildPackageTrust (trusts newtrust)
232 process();
233 cbpv.stability = newtrust;
236 void
237 IniDBBuilderPackage::buildPackageCategory (const std::string& name)
239 categories.insert(name);
242 void
243 IniDBBuilderPackage::buildBeginDepends ()
245 #if DEBUG
246 Log (LOG_BABBLE) << "Beginning of a depends statement " << endLog;
247 #endif
248 currentSpec = NULL;
249 dependsNodeList = PackageDepends();
250 currentNodeList = &dependsNodeList;
251 cbpv.requires = &dependsNodeList;
254 void
255 IniDBBuilderPackage::buildBeginBuildDepends ()
257 #if DEBUG
258 Log (LOG_BABBLE) << "Beginning of a Build-Depends statement" << endLog;
259 #endif
260 currentSpec = NULL;
261 currentNodeList = NULL;
262 /* there is currently nowhere to store Build-Depends information */
265 void
266 IniDBBuilderPackage::buildBeginObsoletes ()
268 #if DEBUG
269 Log (LOG_BABBLE) << "Beginning of an obsoletes statement" << endLog;
270 #endif
271 currentSpec = NULL;
272 obsoletesNodeList = PackageDepends();
273 currentNodeList = &obsoletesNodeList;
274 cbpv.obsoletes = &obsoletesNodeList;
277 void
278 IniDBBuilderPackage::buildBeginProvides ()
280 #if DEBUG
281 Log (LOG_BABBLE) << "Beginning of a provides statement" << endLog;
282 #endif
283 currentSpec = NULL;
284 providesNodeList = PackageDepends();
285 currentNodeList = &providesNodeList;
286 cbpv.provides = &providesNodeList;
289 void
290 IniDBBuilderPackage::buildBeginConflicts ()
292 #if DEBUG
293 Log (LOG_BABBLE) << "Beginning of a conflicts statement" << endLog;
294 #endif
295 currentSpec = NULL;
296 conflictsNodeList = PackageDepends();
297 currentNodeList = &conflictsNodeList;
298 cbpv.conflicts = &conflictsNodeList;
301 void
302 IniDBBuilderPackage::buildSourceName (const std::string& _name)
304 // When there is a Source: line, that names a real source package
305 packagedb db;
306 cbpv.spkg = PackageSpecification(_name);
307 cbpv.spkg_id = db.findSourceVersion (PackageSpecification(_name, cbpv.version));
308 #if DEBUG
309 Log (LOG_BABBLE) << "\"" << _name << "\" is the source package for " << name << "." << endLog;
310 #endif
313 void
314 IniDBBuilderPackage::buildSourceNameVersion (const std::string& version)
316 // XXX: should be stored as sourceevr
319 void
320 IniDBBuilderPackage::buildPackageListNode (const std::string & name)
322 #if DEBUG
323 Log (LOG_BABBLE) << "New node '" << name << "' for package list" << endLog;
324 #endif
325 currentSpec = new PackageSpecification (name);
326 if (currentNodeList)
327 currentNodeList->push_back (currentSpec);
330 void
331 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators const &_operator)
333 if (currentSpec)
335 currentSpec->setOperator (_operator);
336 #if DEBUG
337 Log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
338 endLog;
339 #endif
343 void
344 IniDBBuilderPackage::buildPackageListOperatorVersion (const std::string& aVersion)
346 if (currentSpec)
348 currentSpec->setVersion (aVersion);
349 #if DEBUG
350 Log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
351 endLog;
352 #endif
356 void
357 IniDBBuilderPackage::buildMessage (const std::string& _message_id, const std::string& _message_string)
359 message_id = _message_id;
360 message_string = _message_string;
363 void
364 IniDBBuilderPackage::buildPackageReplaceVersionsList (const std::string& version)
366 replace_versions.insert(version);
369 /* privates */
370 void
371 IniDBBuilderPackage::process ()
373 if (!name.size())
374 return;
376 if (cbpv.version.empty())
377 return;
379 // no install: line, no package
380 if (!cbpv.archive.Canonical())
381 return;
383 #if DEBUG
384 Log (LOG_BABBLE) << "Finished with package " << name << endLog;
385 Log (LOG_BABBLE) << "Version " << cbpv.version << endLog;
386 #endif
388 /* Transfer the accumulated package information to packagedb */
389 packagedb db;
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
402 cbpv.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();