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;
3133using std::unordered_set;
3234using std::vector;
3335
36+ using std::filesystem::path;
37+
38+ namespace fs = std::filesystem;
39+
40+ static char * gitrootdir = NULL ;
41+
3442static 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+
4473int 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 ();
0 commit comments