1 |
commit: 046e0b873ec163012780176597e6510ce026a16e |
2 |
Author: Sven Eden <yamakuzure <AT> gmx <DOT> net> |
3 |
AuthorDate: Tue Feb 25 07:03:54 2014 +0000 |
4 |
Commit: Sven Eden <sven.eden <AT> gmx <DOT> de> |
5 |
CommitDate: Tue Feb 25 07:03:54 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=046e0b87 |
7 |
|
8 |
Portage.pm: Changed determination of PORTDIR and PORTDIR_OVERLAY to use eix if available with portageq get_repo(s|_path) as a fallback. |
9 |
|
10 |
--- |
11 |
Portage.pm | 85 ++++++++++++++++++++++++++++++++++++++++++++++---------------- |
12 |
1 file changed, 63 insertions(+), 22 deletions(-) |
13 |
|
14 |
diff --git a/Portage.pm b/Portage.pm |
15 |
index fc8ddd7..6eed5e2 100644 |
16 |
--- a/Portage.pm |
17 |
+++ b/Portage.pm |
18 |
@@ -93,6 +93,8 @@ my $_use_template = { |
19 |
"package" => 0, |
20 |
pkguse => 0 |
21 |
}; |
22 |
+my $_has_eix = 0; # Set to 1 by INIT if eix can be found. |
23 |
+my $_eix_cmd = ""; |
24 |
|
25 |
# --- public methods --- |
26 |
sub debugMsg; |
27 |
@@ -126,6 +128,15 @@ sub _remove_expands; |
28 |
# --- Package initialization --- |
29 |
INIT { |
30 |
$_environment{$_} = {} for qw{USE USE_EXPAND USE_EXPAND_HIDDEN}; |
31 |
+ |
32 |
+ # See if eix is available |
33 |
+ $_eix_cmd = qx{which eix 2>/dev/null}; |
34 |
+ defined($_eix_cmd) |
35 |
+ and chomp $_eix_cmd |
36 |
+ and -x $_eix_cmd |
37 |
+ and $_has_eix = 1; |
38 |
+ |
39 |
+ # Initialize basics |
40 |
_determine_eprefix_portdir; |
41 |
_determine_make_conf; |
42 |
_determine_profiles; |
43 |
@@ -264,34 +275,57 @@ sub _add_temp |
44 |
} |
45 |
|
46 |
|
47 |
-# Determine the values for EPREFIX, PORTDIR |
48 |
-# and PORTDIR_OVERLAY. These are saved in |
49 |
-# $_EPREFIX, $_PORTDIR and $_PORTDIR_OVERLAY. |
50 |
-# This is done using 'portageq'. |
51 |
-# Other output from portageq is printed on |
52 |
-# STDERR. |
53 |
+# Determine the values for EPREFIX, PORTDIR and PORTDIR_OVERLAY. These are |
54 |
+# saved in $_EPREFIX, $_PORTDIR and $_PORTDIR_OVERLAY. |
55 |
+# This is done using 'eix' with 'portageq' as a fallback. |
56 |
+# Other output from portageq is printed on STDERR. |
57 |
# No parameters accepted. |
58 |
sub _determine_eprefix_portdir { |
59 |
my $tmp = "/tmp/ufed_$$.tmp"; |
60 |
- my @res = map { |
61 |
- my $x = $_; |
62 |
- chomp $x; |
63 |
- $x =~ s/'//g; |
64 |
- $x |
65 |
- } qx{portageq envvar -v EPREFIX PORTDIR PORTDIR_OVERLAY 2>$tmp}; |
66 |
+ |
67 |
+ $_EPREFIX = qx{portageq envvar EPREFIX 2>$tmp}; |
68 |
+ defined($_EPREFIX) and chomp $_EPREFIX or $_EPREFIX=""; |
69 |
|
70 |
- while (my $res = shift @res) { |
71 |
- if ($res =~ /^(.*)=(.*)$/) { |
72 |
- "EPREFIX" eq $1 and $_EPREFIX = $2; |
73 |
- "PORTDIR" eq $1 and $_PORTDIR = $2; |
74 |
- "PORTDIR_OVERLAY" eq $1 and $_PORTDIR_OVERLAY = $2; |
75 |
- } |
76 |
- debugMsg("EPREFIX='${_EPREFIX}'"); |
77 |
- debugMsg("PORTDIR='${_PORTDIR}'"); |
78 |
- debugMsg("PORTDIR_OVERLAY='${_PORTDIR_OVERLAY}'"); |
79 |
+ # Prefer eix over portageq if it is available |
80 |
+ if ($_has_eix) { |
81 |
+ debugMsg("Using eix..."); |
82 |
+ |
83 |
+ local $ENV{PRINT_APPEND}=''; |
84 |
+ $_PORTDIR = qx{$_eix_cmd --print PORTDIR 2>>$tmp}; |
85 |
+ $_PORTDIR_OVERLAY = qx{$_eix_cmd --print PORTDIR_OVERLAY 2>>$tmp}; |
86 |
+ |
87 |
+ # eix ends PORTDIR with a slash that must be removed |
88 |
+ $_PORTDIR =~ s,/+$,,; |
89 |
+ } else { |
90 |
+ debugMsg("Using portageq fallback..."); |
91 |
+ |
92 |
+ my $eroot = qx{portageq envvar EROOT 2>>$tmp}; |
93 |
+ defined($eroot) and chomp $eroot or $eroot="/"; |
94 |
+ |
95 |
+ # Remove 'gentoo', this is PORTDIR, the others are PORTDIR_OVERLAY. |
96 |
+ my $repos = join(' ', map { |
97 |
+ my $x = $_; |
98 |
+ $x =~ s/^gentoo$//; |
99 |
+ $x |
100 |
+ } split(' ', qx{portageq get_repos $eroot 2>>$tmp}) ); |
101 |
+ chomp $repos; |
102 |
+ |
103 |
+ # Now the paths can be determined: |
104 |
+ $_PORTDIR = qx{portageq get_repo_path $eroot gentoo 2>>$tmp}; |
105 |
+ $_PORTDIR_OVERLAY = join(' ', map { |
106 |
+ my $x = $_; |
107 |
+ $x =~ s/^\s*(\S+)\s*$/$1/mg; |
108 |
+ $x |
109 |
+ } split('\n', qx{portageq get_repo_path $eroot $repos 2>>$tmp} )); |
110 |
+ defined($_PORTDIR) and chomp $_PORTDIR; |
111 |
+ defined($_PORTDIR_OVERLAY) and chomp $_PORTDIR_OVERLAY; |
112 |
} |
113 |
- die "Couldn't determine EPREFIX and PORTDIR from Portage" if $? != 0; |
114 |
+ |
115 |
+ debugMsg("EPREFIX='${_EPREFIX}'"); |
116 |
+ debugMsg("PORTDIR='${_PORTDIR}'"); |
117 |
+ debugMsg("PORTDIR_OVERLAY='${_PORTDIR_OVERLAY}'"); |
118 |
|
119 |
+ # Print error messages if any: |
120 |
if ( -s $tmp ) { |
121 |
if (open (my $fTmp, "<", $tmp)) { |
122 |
print STDERR "$_" while (<$fTmp>); |
123 |
@@ -300,6 +334,13 @@ sub _determine_eprefix_portdir { |
124 |
} |
125 |
-e $tmp and unlink $tmp; |
126 |
|
127 |
+ # Die unless this is sane |
128 |
+ defined($_EPREFIX) |
129 |
+ and defined($_PORTDIR) |
130 |
+ and length($_PORTDIR) |
131 |
+ and defined($_PORTDIR_OVERLAY) |
132 |
+ or die "\nCouldn't determine EPREFIX and PORTDIR from Portage\n"; |
133 |
+ |
134 |
return; |
135 |
} |