Commit 98475765 authored by guinux's avatar guinux

add clone action and --no-clone build option

parent 86230bd6
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Pamac\n"
"Report-Msgid-Bugs-To: guillaume@manjaro.org\n"
"POT-Creation-Date: 2018-10-13 11:01+0200\n"
"POT-Creation-Date: 2018-10-17 16:07+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -142,6 +142,11 @@ msgstr ""
msgid "Synchronizing package databases"
msgstr ""
#: src/transaction.vala src/cli.vala
#, c-format
msgid "Cloning %s build files"
msgstr ""
#: src/transaction.vala
#, c-format
msgid "Checking %s dependencies"
......@@ -363,16 +368,16 @@ msgstr ""
msgid "Edit %s build files"
msgstr ""
#: src/transaction-gtk.vala
msgid "Save"
msgstr ""
#: src/transaction-gtk.vala src/manager_window.vala
#: resources/transaction_sum_dialog.ui resources/manager_window.ui
#: resources/choose_ignorepkgs_dialog.ui
msgid "_Cancel"
msgstr ""
#: src/transaction-gtk.vala
msgid "Save"
msgstr ""
#: src/transaction-gtk.vala resources/progress_dialog.ui
#: resources/history_dialog.ui resources/preferences_dialog.ui
msgid "_Close"
......@@ -719,6 +724,10 @@ msgstr ""
msgid "Building packages as root is not allowed"
msgstr ""
#: src/cli.vala
msgid "No PKGBUILD file found in current directory"
msgstr ""
#: src/cli.vala
msgid "Available actions"
msgstr ""
......@@ -795,7 +804,7 @@ msgid "list files owned by the given packages"
msgstr ""
#: src/cli.vala
msgid "Build packages from AUR and install them with their dependencies"
msgid "Clone or sync packages build files from AUR"
msgstr ""
#: src/cli.vala
......@@ -808,6 +817,33 @@ msgstr ""
msgid "dir"
msgstr ""
#: src/cli.vala
msgid "also clone needed dependencies"
msgstr ""
#: src/cli.vala
msgid "overwrite existing files"
msgstr ""
#: src/cli.vala
msgid "Build packages from AUR and install them with their dependencies"
msgstr ""
#: src/cli.vala
msgid ""
"If no package name is given, use the PKGBUILD file is the current directory"
msgstr ""
#: src/cli.vala
msgid ""
"The build directory will be the parent directory, --builddir option will be "
"ignored"
msgstr ""
#: src/cli.vala
msgid "do not clone build files from AUR, only use local files"
msgstr ""
#: src/cli.vala
msgid ""
"ignore a package upgrade, multiple packages can be specified by separating "
......
......@@ -692,19 +692,23 @@ namespace Pamac {
unowned Alpm.List<unowned Alpm.DB> syncdbs = alpm_handle.syncdbs;
while (syncdbs != null) {
unowned Alpm.DB db = syncdbs.data;
unowned Alpm.Group? grp = db.get_group ("base-devel");
if (grp != null) {
unowned Alpm.List<unowned Alpm.Package> packages = grp.packages;
while (packages != null) {
unowned Alpm.Package pkg = packages.data;
if (Alpm.find_satisfier (alpm_handle.localdb.pkgcache, pkg.name) == null) {
to_install += pkg.name;
} else {
// remove the needed pkg from to_remove
backup_to_remove.remove (pkg.name);
// base-devel group is in core
if (db.name == "core") {
unowned Alpm.Group? grp = db.get_group ("base-devel");
if (grp != null) {
unowned Alpm.List<unowned Alpm.Package> packages = grp.packages;
while (packages != null) {
unowned Alpm.Package pkg = packages.data;
if (Alpm.find_satisfier (alpm_handle.localdb.pkgcache, pkg.name) == null) {
to_install += pkg.name;
} else {
// remove the needed pkg from to_remove
backup_to_remove.remove (pkg.name);
}
packages.next ();
}
packages.next ();
}
break;
}
syncdbs.next ();
}
......
......@@ -34,6 +34,7 @@ namespace Pamac {
bool waiting;
string[] temporary_ignorepkgs;
string[] overwrite_files;
GenericSet<string?> already_checked_aur_dep;
public Subprocess pkttyagent;
public Cli () {
......@@ -172,7 +173,39 @@ namespace Pamac {
init_database ();
list_installed ();
}
} else if (args[1] == "clone") {
if (args.length > 2) {
if (args[2] == "--help" || args[2] == "-h") {
display_clone_help ();
} else {
init_database ();
database.config.enable_aur = true;
string[] targets = {};
bool overwrite = false;
bool recurse = false;
int i = 2;
while (i < args.length) {
unowned string arg = args[i];
if (arg == "--overwrite") {
overwrite = true;
} else if (arg == "--recurse" || arg == "-r") {
recurse = true;
} else if (arg == "--builddir") {
stdout.printf ("dir %s\n", args[i + 1]);
if (args[i + 1] != null) {
database.config.aur_build_dir = args[i + 1];
}
i++;
} else {
targets += arg;
}
i++;
}
clone_build_files (targets, overwrite, recurse);
}
} else {
display_clone_help ();
}
} else if (args[1] == "build") {
if (Posix.geteuid () == 0) {
// can't build as root
......@@ -183,19 +216,44 @@ namespace Pamac {
if (args.length > 2) {
if (args[2] == "--help" || args[2] == "-h") {
display_build_help ();
} else if (args[2] == "--builddir") {
init_transaction ();
database.config.enable_aur = true;
database.config.aur_build_dir = args[3];
build_pkgs (args[4:args.length]);
return;
}
}
init_transaction ();
database.config.enable_aur = true;
string[] targets = {};
int i = 2;
while (i < args.length) {
unowned string arg = args[i];
if (arg == "--no-clone") {
transaction.clone_build_files = false;
} else if (arg == "--builddir") {
if (args[i + 1] != null) {
database.config.aur_build_dir = args[i + 1];
}
i++;
} else {
init_transaction ();
database.config.enable_aur = true;
build_pkgs (args[2:args.length]);
targets += arg;
}
} else {
display_build_help ();
i++;
}
if (targets.length == 0) {
// set pkgname to the current dir
var current_dir = File.new_for_path (Environment.get_current_dir ());
var pkgbuild = current_dir.get_child ("PKGBUILD");
if (!pkgbuild.query_exists ()) {
stdout.printf (dgettext (null, "No PKGBUILD file found in current directory"));
stdout.printf ("\n");
return;
}
targets += current_dir.get_basename ();
// set buildir to the parent dir
File? parent = current_dir.get_parent ();
if (parent != null) {
database.config.aur_build_dir = parent.get_path ();
}
}
build_pkgs (targets);
} else if (args[1] == "install") {
if (args.length > 2) {
if (args[2] == "--help" || args[2] == "-h") {
......@@ -299,7 +357,9 @@ namespace Pamac {
database.config.enable_aur = true;
database.config.check_aur_updates = true;
} else if (arg == "--builddir") {
database.config.aur_build_dir = args[i+1];
if (args[i + 1] != null) {
database.config.aur_build_dir = args[i + 1];
}
i++;
} else if (arg == "--force-refresh") {
force_refresh = true;
......@@ -367,6 +427,7 @@ namespace Pamac {
bool trans_cancel () {
if (waiting) {
waiting = false;
stdout.printf ("\n");
loop.quit ();
} else if (trans_cancellable) {
transaction.cancel ();
......@@ -475,6 +536,7 @@ namespace Pamac {
"list",
"install",
"reinstall",
"clone",
"build",
"remove",
"update,upgrade"};
......@@ -485,6 +547,7 @@ namespace Pamac {
"install",
"reinstall",
"build",
"clone",
"remove",
"update,upgrade"};
string[] targets_actions = {"search",
......@@ -493,6 +556,7 @@ namespace Pamac {
"install",
"reinstall",
"build",
"clone",
"remove",
"update,upgrade"};
stdout.printf (dgettext (null, "Available actions") + ":\n");
......@@ -601,10 +665,44 @@ namespace Pamac {
}
}
void display_clone_help () {
stdout.printf (dgettext (null, "Clone or sync packages build files from AUR"));
stdout.printf ("\n\n");
stdout.printf ("pamac clone [%s] <%s>".printf (dgettext (null, "options"), dgettext (null, "package(s)")));
stdout.printf ("\n\n");
stdout.printf (dgettext (null, "options") + ":\n");
int max_length = 25;
string[] cuts = split_string (dgettext (null, "build directory, if no directory is given the one specified in pamac.conf file is used"), max_length + 2);
print_aligned (" %s <%s>".printf ("--builddir", dgettext (null, "dir")), ": %s".printf (cuts[0]), max_length);
int i = 1;
while (i < cuts.length) {
print_aligned ("", "%s".printf (cuts[i]), max_length + 2);
i++;
}
cuts = split_string (dgettext (null, "also clone needed dependencies"), max_length + 2);
print_aligned (" -r,--recurse", ": %s".printf (cuts[0]), max_length);
i = 1;
while (i < cuts.length) {
print_aligned ("", "%s".printf (cuts[i]), max_length + 2);
i++;
}
cuts = split_string (dgettext (null, "overwrite existing files"), max_length + 2);
print_aligned (" --overwrite", ": %s".printf (cuts[0]), max_length);
i = 1;
while (i < cuts.length) {
print_aligned ("", "%s".printf (cuts[i]), max_length + 2);
i++;
}
}
void display_build_help () {
stdout.printf (dgettext (null, "Build packages from AUR and install them with their dependencies"));
stdout.printf ("\n\n");
stdout.printf ("pamac build [%s] <%s>".printf (dgettext (null, "options"), dgettext (null, "package(s)")));
stdout.printf (dgettext (null, "If no package name is given, use the PKGBUILD file is the current directory"));
stdout.printf ("\n");
stdout.printf (dgettext (null, "The build directory will be the parent directory, --builddir option will be ignored"));
stdout.printf ("\n\n");
stdout.printf ("pamac build [%s] [%s]".printf (dgettext (null, "options"), dgettext (null, "package(s)")));
stdout.printf ("\n\n");
stdout.printf (dgettext (null, "options") + ":\n");
int max_length = 25;
......@@ -615,6 +713,13 @@ namespace Pamac {
print_aligned ("", "%s".printf (cuts[i]), max_length + 2);
i++;
}
cuts = split_string (dgettext (null, "do not clone build files from AUR, only use local files"), max_length + 2);
print_aligned (" --no-clone", ": %s".printf (cuts[0]), max_length);
i = 1;
while (i < cuts.length) {
print_aligned ("", "%s".printf (cuts[i]), max_length + 2);
i++;
}
}
void display_install_help () {
......@@ -1631,6 +1736,68 @@ namespace Pamac {
try_lock_and_run (start_transaction);
}
void clone_build_files (string[] pkgnames, bool overwrite, bool recurse) {
already_checked_aur_dep = new GenericSet<string?> (str_hash, str_equal);
// set waiting to allow cancellation
waiting = true;
clone_build_files_real.begin (pkgnames, overwrite, recurse, () => {
waiting = false;
loop.quit ();
});
loop.run ();
}
async void clone_build_files_real (string[] pkgnames, bool overwrite, bool recurse) {
foreach (unowned string pkgname in pkgnames) {
var aur_pkg_details = yield database.get_aur_pkg_details (pkgname);
if (aur_pkg_details.name == "") {
print_error (dgettext (null, "target not found: %s").printf (pkgname) + "\n");
return;
} else {
// clone build files
stdout.printf (dgettext (null, "Cloning %s build files".printf (pkgname)) + "...\n");
// use packagebase in case of split package
File? clone_dir = yield database.clone_build_files (aur_pkg_details.packagebase, overwrite);
if (clone_dir == null) {
// error
return;
} else if (recurse) {
string[] dep_to_check = {};
var depends = new List<string> ();
foreach (unowned string depend in aur_pkg_details.depends) {
depends.append (depend);
}
foreach (unowned string depend in aur_pkg_details.makedepends) {
depends.append (depend);
}
foreach (unowned string depend in aur_pkg_details.checkdepends) {
depends.append (depend);
}
// check deps
foreach (unowned string dep_string in depends) {
var pkg = database.find_installed_satisfier (dep_string);
if (pkg.name == "") {
pkg = database.find_sync_satisfier (dep_string);
}
if (pkg.name == "") {
string dep_name = database.get_alpm_dep_name (dep_string);
if (!(dep_name in already_checked_aur_dep)) {
already_checked_aur_dep.add (dep_name);
var aur_pkg = yield database.get_aur_pkg (dep_name);
if (aur_pkg.name != "") {
dep_to_check += (owned) dep_name;
}
}
}
}
if (dep_to_check.length > 0) {
yield clone_build_files_real (dep_to_check, overwrite, recurse);
}
}
}
}
}
async bool check_build_pkgs () {
bool success = true;
foreach (unowned string pkgname in to_build) {
......
......@@ -120,6 +120,10 @@ namespace Pamac {
return country;
}
public string get_alpm_dep_name (string dep_string) {
return Alpm.Depend.from_string (dep_string).name;
}
public bool get_checkspace () {
return alpm_handle.checkspace == 1 ? true : false;
}
......
......@@ -1592,54 +1592,35 @@ namespace Pamac {
}
void on_dep_button_clicked (Gtk.Button button) {
bool sync_pkg = false;
if (filters_stack.visible_child_name == "updates") {
sync_pkg = true;
}
if (display_package_queue.find_custom (current_package_displayed, strcmp) == null) {
display_package_queue.push_tail (current_package_displayed);
}
string depstring = button.label;
// if depstring contains a version restriction search a satisfier directly
if (">" in depstring || "=" in depstring || "<" in depstring) {
var pkg = database.find_installed_satisfier (depstring);
if (pkg.name != "") {
display_package_properties (pkg.name, "", sync_pkg);
} else {
pkg = database.find_sync_satisfier (depstring);
if (pkg.name != "") {
display_package_properties (pkg.name, "", sync_pkg);
}
}
bool sync_pkg = false;
if (filters_stack.visible_child_name == "updates") {
sync_pkg = true;
}
if (display_package_queue.find_custom (current_package_displayed, strcmp) == null) {
display_package_queue.push_tail (current_package_displayed);
}
string depstring = button.label;
var pkg = database.find_installed_satisfier (depstring);
if (pkg.name != "") {
display_package_properties (pkg.name, "", sync_pkg);
} else {
pkg = database.find_sync_satisfier (depstring);
if (pkg.name != "") {
display_package_properties (pkg.name, "", sync_pkg);
} else {
// just search for the name first to search for AUR after
if (database.get_installed_pkg (depstring).name != "") {
display_package_properties (depstring, "", sync_pkg);
} else if (database.get_sync_pkg (depstring).name != "") {
display_package_properties (depstring, "", sync_pkg);
} else {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
database.get_aur_pkg.begin (depstring, (obj, res) => {
this.get_window ().set_cursor (null);
if (database.get_aur_pkg.end (res).name != "") {
display_aur_properties (depstring);
} else {
var pkg = database.find_installed_satisfier (depstring);
if (pkg.name != "") {
display_package_properties (pkg.name, "", sync_pkg);
} else {
pkg = database.find_sync_satisfier (depstring);
if (pkg.name != "") {
display_package_properties (pkg.name, "", sync_pkg);
}
}
}
});
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
string dep_name = database.get_alpm_dep_name (depstring);
database.get_aur_pkg.begin (dep_name, (obj, res) => {
this.get_window ().set_cursor (null);
if (database.get_aur_pkg.end (res).name != "") {
display_aur_properties (dep_name);
}
});
}
}
}
void on_properties_stack_visible_child_changed () {
......
......@@ -61,6 +61,7 @@ namespace Pamac {
// transaction options
public Database database { get; construct set; }
public int flags { get; set; } //Alpm.TransFlag
public bool clone_build_files { get; set; }
public signal void emit_action (string action);
public signal void emit_action_progress (string action, string status, double progress);
......@@ -104,6 +105,7 @@ namespace Pamac {
// transaction options
flags = 0;
enable_downgrade = false;
clone_build_files = true;
// run transaction data
current_action = "";
current_status = "";
......@@ -231,6 +233,7 @@ namespace Pamac {
}
void on_get_authorization_finished (bool authorized) {
emit_script_output ("");
get_authorization_finished (authorized);
}
......@@ -372,19 +375,30 @@ namespace Pamac {
if (build_cancellable.is_cancelled ()) {
return false;
}
var aur_pkg = yield database.get_aur_pkg (pkgname);
if (aur_pkg.name == "") {
emit_error (dgettext (null, "target not found: %s").printf (pkgname), {});
return false;
File? clone_dir;
if (clone_build_files) {
var aur_pkg = yield database.get_aur_pkg (pkgname);
if (aur_pkg.name == "") {
emit_error (dgettext (null, "target not found: %s").printf (pkgname), {});
return false;
}
// clone build files
// use packagebase in case of split package
emit_action (dgettext (null, "Cloning %s build files".printf (pkgname)) + "...");
clone_dir = yield database.clone_build_files (aur_pkg.packagebase, false);
if (clone_dir == null) {
// error
return false;
}
} else {
clone_dir = File.new_for_path (Path.build_path ("/", database.config.aur_build_dir, pkgname));
if (!clone_dir.query_exists ()) {
// error
return false;
}
yield regenerate_srcinfo (pkgname);
}
// clone build files
emit_action (dgettext (null, "Checking %s dependencies".printf (pkgname)) + "...");
// use packagebase in case of split package
File? clone_dir = yield database.clone_build_files (aur_pkg.packagebase, false);
if (clone_dir == null) {
// error
return false;
}
var srcinfo = clone_dir.get_child (".SRCINFO");
try {
// read .SRCINFO
......@@ -538,10 +552,10 @@ namespace Pamac {
pkg = database.find_sync_satisfier (dep_string);
}
if (pkg.name == "") {
string dep_name = Alpm.Depend.from_string (dep_string).name;
string dep_name = database.get_alpm_dep_name (dep_string);
if (!(dep_name in already_checked_aur_dep)) {
already_checked_aur_dep.add (dep_name);
aur_pkg = yield database.get_aur_pkg (dep_name);
var aur_pkg = yield database.get_aur_pkg (dep_name);
if (aur_pkg.name != "") {
dep_to_check += (owned) dep_name;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment