Skip to content

Commit c92fa44

Browse files
committed
fix up world builder + minimal computer to walk the releasepackages.lst from the git repo.
1 parent 2de30e4 commit c92fa44

File tree

4 files changed

+82
-23
lines changed

4 files changed

+82
-23
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AC_PREREQ(2.65)
22
AC_INIT([sgug-rpm-tools],
3-
[0.1.3],
3+
[0.1.4],
44
55

66
AC_SUBST(ACLOCAL_AMFLAGS, "-I macros")

src/sgug-rpm-tools/installedrpm.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ namespace sgug_rpm {
103103
// cout << "Changing require from " << req << endl;
104104
req = req.substr(0,firstspace-namestart);
105105
// cout << "It is now " << req << endl;
106+
if( str_starts_with(req,"(") && !str_ends_with(req, ")") ) {
107+
req = req.substr(1);
108+
// exit(EXIT_FAILURE);
109+
}
106110
}
107111
if( strncmp(req.c_str(), "rpmlib(", 7) == 0 ) {
108112
continue;

src/sgug-rpm-tools/sgug_minimal_computer.cpp

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <iostream>
88
#include <fstream>
9+
#include <filesystem>
10+
#include <optional>
911

1012
#include <rpm/rpmcli.h>
1113
#include <rpm/rpmdb.h>
@@ -31,16 +33,43 @@ using std::unordered_map;
3133
using std::unordered_set;
3234
using std::vector;
3335

36+
using std::filesystem::path;
37+
38+
namespace fs = std::filesystem;
39+
40+
static char * gitrootdir = NULL;
41+
3442
static struct poptOption optionsTable[] = {
3543
{
3644
NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
3745
"Common options for all rpm modes and executables",
3846
NULL },
47+
{
48+
"gitroot",
49+
'g',
50+
POPT_ARG_STRING,
51+
&gitrootdir,
52+
0,
53+
"RSE git repository directory containing releasepackages.lst",
54+
NULL
55+
},
3956
POPT_AUTOALIAS
4057
POPT_AUTOHELP
4158
POPT_TABLEEND
4259
};
4360

61+
optional<string> calculate_expected_specfile_path( string sgug_rse_git_root,
62+
string package_name ) {
63+
path srgr_path = std::filesystem::path(sgug_rse_git_root);
64+
path package_spec_path = srgr_path / "packages" / package_name / "SPECS" / (package_name + ".spec");
65+
if( fs::exists(package_spec_path) ) {
66+
return {fs::canonical(package_spec_path)};
67+
}
68+
else {
69+
return {};
70+
}
71+
}
72+
4473
int main(int argc, char**argv)
4574
{
4675
vector<sgug_rpm::specfile> valid_specfiles;
@@ -53,6 +82,12 @@ int main(int argc, char**argv)
5382
exit(EXIT_FAILURE);
5483
}
5584

85+
// Check we have outputdir and gitrootdir
86+
if( gitrootdir == NULL ) {
87+
cerr << "gitrootdir must be passed" << endl;
88+
exit(EXIT_FAILURE);
89+
}
90+
path gitrootdir_p = {gitrootdir};
5691
vector<string> spec_filenames;
5792

5893
// Capture any explicit minimum rpms
@@ -67,30 +102,50 @@ int main(int argc, char**argv)
67102

68103
cout << "# Reading spec files..." << endl;
69104

70-
rpmSpecFlags flags;
105+
std::ifstream input( fs::canonical(gitrootdir_p / "releasepackages.lst") );
71106

72-
if( spec_filenames.size() > 0 ) {
73-
for( const string & spec_file : spec_filenames ) {
74-
sgug_rpm::specfile dest;
75-
// Must reset rpm macros every time to be sure
76-
// no global are remembered
77-
popt_context.reset_rpm_macros();
78-
if( sgug_rpm::read_specfile( spec_file, flags, dest, pprinter ) ) {
79-
valid_specfiles.emplace_back(dest);
80-
}
81-
else {
82-
failed_specfiles.push_back(spec_file);
83-
}
84-
pprinter.accept_progress();
107+
vector<string> names_in;
108+
string curline;
109+
for( string line; std::getline(input, line); ) {
110+
// Skip comments + empty lines
111+
if( line.length() == 0 || line[0] == '#' ) {
112+
continue;
85113
}
86-
pprinter.reset();
114+
// For each package, check we have
115+
// a) a specfile
116+
// b) an SRPM we can install that matches
117+
string package_name = line;
118+
names_in.push_back(package_name);
87119
}
88-
else {
89-
sgug_rpm::read_rpmbuild_specfiles( popt_context,
90-
flags,
91-
valid_specfiles,
92-
failed_specfiles,
93-
pprinter );
120+
input.close();
121+
122+
for( string & package_name : names_in ) {
123+
optional<string> expected_specfile_path_opt =
124+
calculate_expected_specfile_path( gitrootdir_p,
125+
package_name );
126+
if( !expected_specfile_path_opt ) {
127+
cerr << "Missing spec for " << package_name << endl;
128+
cerr << "Looked under " << gitrootdir_p << "/packages/" <<
129+
package_name << "/SPECS/" << package_name << ".spec" << endl;
130+
exit(EXIT_FAILURE);
131+
}
132+
string expected_specfile_path = *expected_specfile_path_opt;
133+
sgug_rpm::specfile specfile;
134+
if( verbose ) {
135+
cout << "# Checking for spec at " << expected_specfile_path << endl;
136+
}
137+
rpmSpecFlags flags = (RPMSPEC_FORCE);
138+
if( sgug_rpm::read_specfile( expected_specfile_path,
139+
flags,
140+
specfile,
141+
pprinter ) ) {
142+
valid_specfiles.emplace_back( specfile );
143+
}
144+
else {
145+
failed_specfiles.push_back( package_name );
146+
}
147+
// Quick hack while testing, only do the first one
148+
//break;
94149
}
95150

96151
size_t num_specs = valid_specfiles.size();

src/sgug-rpm-tools/sgug_world_builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ int main(int argc, char**argv)
188188

189189
std::ifstream input( fs::canonical(gitrootdir_p / "releasepackages.lst") );
190190

191-
192191
vector<string> names_in;
193192
string curline;
194193
for( string line; std::getline(input, line); ) {
@@ -202,6 +201,7 @@ int main(int argc, char**argv)
202201
string package_name = line;
203202
names_in.push_back(package_name);
204203
}
204+
input.close();
205205

206206
for( string & package_name : names_in ) {
207207
optional<string> expected_specfile_path_opt =

0 commit comments

Comments
 (0)