Gentoo Archives: gentoo-commits

From: Ettore Di Giacinto <mudler@××××××××××××.org>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoo-mate:master commit in: scripts/
Date: Thu, 13 Oct 2016 16:03:31
Message-Id: 1476374224.adb7a5cf8ebd6d3f102bbd46315373288edee0fc.mudler@gentoo
1 commit: adb7a5cf8ebd6d3f102bbd46315373288edee0fc
2 Author: mudler <mudler <AT> sabayon <DOT> org>
3 AuthorDate: Thu Oct 13 15:56:41 2016 +0000
4 Commit: Ettore Di Giacinto <mudler <AT> sabayonlinux <DOT> org>
5 CommitDate: Thu Oct 13 15:57:04 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoo-mate.git/commit/?id=adb7a5cf
7
8 scripts: Adding keyword-helper script to help out in KEYWORDS manipulations
9
10 scripts/keyword-helper | 122 +++++++++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 122 insertions(+)
12
13 diff --git a/scripts/keyword-helper b/scripts/keyword-helper
14 new file mode 100755
15 index 0000000..d5768a1
16 --- /dev/null
17 +++ b/scripts/keyword-helper
18 @@ -0,0 +1,122 @@
19 +#!/usr/bin/perl
20 +# keyword-helper - utility to ekeyword packages
21 +# Usage: from the root of the overlay
22 +# keyword-helper app-foo/bar-1.2 app-foo/baz-1.2
23 +# <mudler@×××××××.org>
24 +
25 +use Cwd;
26 +
27 +my $TARGET_KEYWORD = $ENV{TARGET_KEYWORD} // "amd64 x86"
28 + ; # KEYWORD changes, arguments are given directly to ekeyword
29 +my $BUGZ =
30 + $ENV{BUGZ}; # Bug reference. Mandatory if no COMMIT_MSG is specified
31 +my $COMMIT_MSG = $ENV{COMMIT_MSG}; # Git commit message
32 +
33 +my @KEYWORD_PACKAGES = @ARGV; # Packages that we want to manipulate
34 +my $CWD = getcwd;
35 +
36 +sub strip_pvr { s/-[0-9]{1,}.*$//; }
37 +
38 +sub package_has_pvr { /-[0-9]{1,}.*$/; }
39 +
40 +# print helpers
41 +
42 +sub say { print join( "\n", @_ ) . "\n"; }
43 +
44 +sub err { say "\e[31m ", @_, " \e[0m"; }
45 +
46 +sub fatal { err @_; exit 1; }
47 +
48 +sub ok { say "\e[1;34m ", @_, " \e[0m"; }
49 +
50 +sub info { say "\e[1;37m ", @_, " \e[0m"; }
51 +
52 +# deadly checks
53 +
54 +if ( !@ARGV or $ARGV[0] eq "-h" or $ARGV[0] eq "--help" ) {
55 + say "You must feed me with at least a package version", "",
56 + "e.g. $0 package", "",
57 + "ENV variables options:", "",
58 + " COMMIT_MSG \t\t default commit message",
59 + " BUGZ \t\t Gentoo Bugzilla id, e.g. 596998",
60 + " TARGET_KEYWORD \t the keyword(s) to set separated by a space. e.g. TARGET_KEYWORD='amd64 x86'";
61 + exit 1;
62 +}
63 +
64 +if ( -e "${CWD}/Manifest" ) {
65 + fatal "You are running me from the wrong folder, don't you?",
66 + "I need to be executed from the root of the overlay!";
67 +}
68 +
69 +fatal "You should supply a bug id with the BUGZ environment variable or",
70 + "a custom commit message with COMMIT_MSG at least"
71 + if ( !$BUGZ and !$COMMIT_MSG );
72 +
73 +# Split TARGET_KEYWORD by space and put into an array
74 +my @ARCHES = split( /\s/, $TARGET_KEYWORD );
75 +
76 +# Cycle packages that need to be manipulated
77 +# Here it's being used $_, that contains strings in the following format: category/package, contains package version and revision too
78 +for (@KEYWORD_PACKAGES) {
79 + fatal
80 + "You must feed me with package versions, not atoms or whatever!",
81 + "bailing out since you are using me in the WRONG way, fix yourself first"
82 + unless package_has_pvr;
83 + my $local_package =
84 + (/\/(.*)$/)[0]
85 + . ".ebuild"
86 + ; # Extract the package name and version, included of revision if any
87 + info "Keywording $TARGET_KEYWORD on $_ [$local_package]";
88 + strip_pvr(); # stripping PVR
89 +
90 + if ( -d $_ ) {
91 + chdir($_); # entering in the directory
92 + }
93 + else {
94 + fatal "$_ directory doesn't exists";
95 + }
96 +
97 + # Checking if ebuild we want to keyword is there
98 + if ( -e $local_package ) {
99 +
100 + # Do magic with the ebuild, since it exists
101 + foreach my $arch (@ARCHES) {
102 + my $LOCAL_COMMIT_MSG = $COMMIT_MSG;
103 +
104 + # if no COMMIT_MSG is supplied, we generate it
105 + if ( !$COMMIT_MSG ) {
106 + my ( $keyword_symbol, $clean_arch ) =
107 + ( $arch =~ /^(\^|\~|)(.*)$/ )
108 + ; # Getting the first character of a arch, it can be ~, ^ or "" to use it with ekeyword
109 + my $prefix_msg;
110 + if ( $keyword_symbol eq '^' ) {
111 + $prefix_msg = "Drop $clean_arch keyword ";
112 + }
113 + elsif ( $keyword_symbol eq '~' ) {
114 + $prefix_msg = "Added $arch keyword ";
115 + }
116 + elsif ( $keyword_symbol eq "" ) {
117 + $prefix_msg = "Stable on $clean_arch keyword ";
118 + }
119 + $LOCAL_COMMIT_MSG = $prefix_msg . "wrt \#${BUGZ}";
120 + }
121 +
122 + system("ekeyword $arch $local_package");
123 + system("git add $local_package");
124 + system("repoman commit -m '$_: $LOCAL_COMMIT_MSG'");
125 + if ( $? >> 8 != 0 ) {
126 + fatal
127 + "Meh. we got errors. before going on, i want you to fix those by hand.";
128 + }
129 + else {
130 + ok "Done for $_ [$local_package]";
131 + }
132 + }
133 +
134 + }
135 + else {
136 + # errors, the ebuild cannot be found
137 + fatal "/!\\ $local_package not found in $_ keywording failed!";
138 + }
139 + chdir($CWD);
140 +}