Skip to content

Commit

Permalink
set microdnf and tdnf as part of the minimal set, remove git-all for now
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhams committed Dec 5, 2020
1 parent 2fd3f08 commit 8eccb36
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 28 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ(2.65)
AC_INIT([sgug-rpm-tools],
[0.1.5],
[0.1.6],
[[email protected]])

AC_SUBST(ACLOCAL_AMFLAGS, "-I macros")
Expand Down
2 changes: 2 additions & 0 deletions src/sgug-rpm-tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sgug_world_builder_SOURCES= \
sgug_dep_engine.hpp \
specfile.hpp \
standalonerpm.hpp \
dependencyset.cpp \
helpers.cpp \
installedrpm.cpp \
sgug_world_builder.cpp \
Expand All @@ -24,6 +25,7 @@ sgug_minimal_computer_SOURCES= \
sgug_dep_engine.hpp \
specfile.hpp \
standalonerpm.hpp \
dependencyset.cpp \
helpers.cpp \
installedrpm.cpp \
sgug_dep_engine.cpp \
Expand Down
70 changes: 70 additions & 0 deletions src/sgug-rpm-tools/dependencyset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <dependencyset.hpp>

#include <string>
#include <vector>
#include <unordered_set>

#include <algorithm>

#include <iostream>

using std::string;
using std::vector;
using std::unordered_set;

namespace sgug_rpm
{
void rpmds_read_deps( Header package_header,
std::vector<std::string> & provides,
std::vector<std::string> & requires ) {
// Provides
rpmds_h rpmds_prov( package_header, RPMTAG_PROVIDENAME, 0);
unordered_set<string> prov_set;
while( rpmds_prov.next() >= 0 ) {
const char * DNEVR;
if((DNEVR = rpmdsDNEVR(rpmds_prov.dependency_set)) != NULL) {
string prov(DNEVR + 2);
if( strncmp(prov.c_str(), "rpmlib(", 7) == 0 ) {
continue;
}
if( prov_set.find(prov) != prov_set.end() ) {
// cerr << "Warning: Dupe provide dep on package for " <<
// specfile.get_name() << ":" << pkg << ":" <<
// prov << endl;
}
else {
prov_set.insert(prov);
}
}
}
for( const string & s : prov_set ) {
provides.push_back(s);
// std::cout << "Found provide: " << s << std::endl;
}
// Requires
rpmds_h rpmds_req( package_header, RPMTAG_REQUIRENAME, 0);
unordered_set<string> req_set;
while( rpmds_req.next() >= 0 ) {
const char * DNEVR;
if((DNEVR = rpmdsDNEVR(rpmds_req.dependency_set)) != NULL) {
string req(DNEVR + 2);
if( strncmp(req.c_str(), "rpmlib(", 7) == 0 ) {
continue;
}
if( req_set.find(req) != req_set.end() ) {
// cerr << "Warning: Dupe require dep on package for " <<
// specfile.get_name() << ":" << pkg << ":" <<
// req << endl;
}
else {
req_set.insert(req);
}
}
}
for( const string & s : req_set ) {
requires.push_back(s);
// std::cout << "Found require: " << s << std::endl;
}
}

}
8 changes: 8 additions & 0 deletions src/sgug-rpm-tools/dependencyset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
#define DEPENDENCYSET_HPP

#include <rpm/rpmdb.h>
#include <rpm/rpmds.h>
#include <rpm/rpmts.h>

#include <vector>
#include <string>

namespace sgug_rpm {

class rpmds_h {
Expand All @@ -21,6 +25,10 @@ namespace sgug_rpm {
}
};

void rpmds_read_deps( Header package_header,
std::vector<std::string> & provides,
std::vector<std::string> & requires );

}

#endif
126 changes: 126 additions & 0 deletions src/sgug-rpm-tools/sgug_builddep_extractor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include "helpers.hpp"
#include "specfile.hpp"
#include "installedrpm.hpp"
#include "standalonerpm.hpp"
#include "dependencyset.hpp"

#include <iostream>
#include <fstream>
#include <sstream>
#include <filesystem>
#include <optional>

#include <rpm/header.h>
#include <rpm/rpmcli.h>
#include <rpm/rpmdb.h>
#include <rpm/rpmds.h>
#include <rpm/rpmts.h>
#include <rpm/rpmarchive.h>
#include <rpm/rpmlog.h>

// C++ structures/algorithms
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>

using std::string;
using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::ofstream;
using std::stringstream;
using std::vector;
using std::unordered_map;
using std::unordered_set;

using std::optional;

using std::filesystem::path;

namespace fs = std::filesystem;

static struct poptOption optionsTable[] = {
{
NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
"Common options for all rpm modes and executables",
NULL },
POPT_AUTOALIAS
POPT_AUTOHELP
POPT_TABLEEND
};

optional<string> calculate_expected_specfile_path( string sgug_rse_git_root,
string package_name ) {
path srgr_path = std::filesystem::path(sgug_rse_git_root);
path package_spec_path = srgr_path / "packages" / package_name / "SPECS" / (package_name + ".spec");
if( fs::exists(package_spec_path) ) {
return {fs::canonical(package_spec_path)};
}
else {
return {};
}
}

int main(int argc, char**argv)
{
sgug_rpm::poptcontext_h popt_context( argc, argv, optionsTable );
rpmlogSetMask(RPMLOG_ERR);

if( popt_context.context == NULL ) {
exit(EXIT_FAILURE);
}

// Process the package passed on the command line
vector<string> names_in;
const char * extra_arg;
while( (extra_arg = poptGetArg(popt_context.context)) != NULL ) {
names_in.push_back(extra_arg);
}

if( names_in.size() == 0 ) {
cerr << "No packages specified. Exiting." << endl;
exit(EXIT_FAILURE);
}

bool verbose = popt_context.verbose;

sgug_rpm::progress_printer pprinter;

sgug_rpm::specfile specfile;
for( const string & one_package : names_in ) {
if( verbose ) {
cout << "# Opening spec " << one_package << endl;
}
rpmSpecFlags flags = (RPMSPEC_FORCE);
if( !sgug_rpm::read_specfile( one_package,
flags,
specfile,
pprinter ) ) {
cerr << "Unable to read specfile " << one_package << endl;
exit(EXIT_FAILURE);
}
}

cout << "PackageName: " << specfile.get_name() << endl;
cout << "PackagePath: " << specfile.get_filepath() << endl;
const vector<string> & packages = specfile.get_packages();
for( const string & sub_package : packages ) {
cout << "OutputRPM: " << sub_package << endl;
}
const unordered_map<string,vector<string>> & build_deps =
specfile.get_build_deps();
for( auto & entry : build_deps ) {
if( verbose ) {
cout << "# Examining entry " << entry.first << endl;
}
const vector<string> & entry_deps = entry.second;
for( const string & builddep_package : entry_deps ) {
cout << "BuildDep: " << builddep_package << endl;
}
}

return 0;
}
7 changes: 5 additions & 2 deletions src/sgug-rpm-tools/sgug_minimal_computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,16 @@ int main(int argc, char**argv)
special_packages.emplace("rpm");
special_packages.emplace("sudo");
special_packages.emplace("vim-minimal");
special_packages.emplace("git-all");
special_packages.emplace("tar");
special_packages.emplace("bzip2");
special_packages.emplace("gzip");
special_packages.emplace("xz");
special_packages.emplace("unzip");
special_packages.emplace("sgug-getopt");
/*special_packages.emplace("sgugshell");*/
special_packages.emplace("microdnf");
special_packages.emplace("tdnf");
/*special_packages.emplace("git-all");*/
/*special_packages.emplace("sgug-getopt");*/

vector<sgug_rpm::resolvedrpm> resolved_rpms =
sgug_rpm::flatten_sort_packages( rpms_to_resolve,
Expand Down
37 changes: 25 additions & 12 deletions src/sgug-rpm-tools/sgug_world_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace fs = std::filesystem;
static char * inputdir = NULL;
static char * outputdir = NULL;
static char * gitrootdir = NULL;
static int partial_allowed = 0;

static struct poptOption optionsTable[] = {
{
Expand All @@ -54,7 +55,7 @@ static struct poptOption optionsTable[] = {
POPT_ARG_STRING,
&inputdir,
0,
"Input directory where SRPM packages may be found",
"Input dir with an SRPM subdirectory",
NULL
},
{
Expand All @@ -63,7 +64,7 @@ static struct poptOption optionsTable[] = {
POPT_ARG_STRING,
&outputdir,
0,
"Output directory where SRPM and RPM files will be placed",
"Output dir for SRPM and RPM output files",
NULL
},
{
Expand All @@ -72,7 +73,16 @@ static struct poptOption optionsTable[] = {
POPT_ARG_STRING,
&gitrootdir,
0,
"RSE git repository directory containing releasepackages.lst",
"RSE git repo dir containing releasepackages.lst",
NULL
},
{
"partial",
'p',
POPT_ARG_NONE,
&partial_allowed,
0,
"Accept partial SRPM/spec availability (do NOT use this when performing a complete build)",
NULL
},
POPT_AUTOALIAS
Expand Down Expand Up @@ -168,6 +178,12 @@ int main(int argc, char**argv)
path gitrootdir_p = {gitrootdir};

bool verbose = popt_context.verbose;
bool partial = partial_allowed != 0;

if (partial) {
cout << "WARNING: Partial graphs are allowed. This should not be " <<
"used when performing a full world build" << endl;
}

sgug_rpm::progress_printer pprinter;

Expand All @@ -176,14 +192,6 @@ int main(int argc, char**argv)
path outputsrpm_p = outputdir_p / "SRPMS";
path outputrpm_p = outputdir_p / "RPMS";

/*
string sgug_rse_git_root = "/usr/people/dan/Sources/GitClones/sgug-rse.git";
string build_progress_dir = "/usr/people/dan/Temp/build0.0.6round2/PROGRESS";
string sgug_rse_srpm_archive_root = "/usr/people/dan/Temp/build0.0.6round1/SRPMS";
string sgug_rse_srpm_output_root = "/usr/people/dan/Temp/build0.0.6round2/SRPMS";
string sgug_rse_rpm_output_root = "/usr/people/dan/Temp/build0.0.6round2/RPMS";
*/

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

std::ifstream input( fs::canonical(gitrootdir_p / "releasepackages.lst") );
Expand Down Expand Up @@ -275,7 +283,9 @@ int main(int argc, char**argv)
}
}

if( missing_srpms.size() > 0 ) {
// If we aren't allowing partial graphs of dependencies
// we will warn and bail about the missing SRPMs
if( !partial && missing_srpms.size() > 0 ) {
for( const string & missing_srpm : missing_srpms ) {
cerr << "Unable to find SRPM for " << missing_srpm << endl;
}
Expand Down Expand Up @@ -371,6 +381,9 @@ int main(int argc, char**argv)

for( const sgug_rpm::specfile & spec : specs_to_rebuild ) {
const string & name = spec.get_name();
if( package_to_srpm_map.find(name) == package_to_srpm_map.end() ) {
continue;
}
const string & srpm = package_to_srpm_map[name];
worldrebuilderfile << "doPackageBuild '" << name << "' '" <<
srpm << "'" << endl;
Expand Down
10 changes: 5 additions & 5 deletions src/sgug-rpm-tools/specfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ namespace sgug_rpm {
specfile::specfile( string filepath,
string name,
vector<string> packages,
unordered_map<string,vector<string>> package_deps )
unordered_map<string,vector<string>> build_deps )
: _filepath(filepath),
_name(name),
_packages(packages),
_package_deps(package_deps) {}
_build_deps(build_deps) {}

bool read_specfile( const string & path,
rpmSpecFlags flags,
Expand All @@ -81,7 +81,7 @@ namespace sgug_rpm {
rpmSpecPkg spec_pkg;
bool first=true;
vector<string> packages;
unordered_map<string, vector<string>> package_deps;
unordered_map<string, vector<string>> build_deps;
while((spec_pkg = specpkgiter_h.next()) != NULL ) {

Header spec_header = rpmSpecPkgHeader(spec_pkg);
Expand All @@ -92,10 +92,10 @@ namespace sgug_rpm {
first = false;
}
packages.push_back(pkg_name);
package_deps.emplace(pkg_name, vector<string>());
build_deps.emplace(pkg_name, vector<string>());
}

dest = specfile{ path, spec_name, packages, package_deps };
dest = specfile{ path, spec_name, packages, build_deps };

return true;
}
Expand Down
Loading

0 comments on commit 8eccb36

Please sign in to comment.