Advertisement
Guest User

snippet1

a guest
May 7th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # Script to handle building KDE from source code.
  4. #
  5. # Configuration is found in $XDG_CONFIG_HOME/kdesrc-buildrc,
  6. # with fallback at ~/.kdesrc-buildrc. $XDG_CONFIG_HOME normally ".config"
  7. #
  8. # Please also see the documentation that should be included with this program,
  9. # in the doc/ directory.
  10. #
  11. # Home page: https://apps.kde.org/kdesrc_build/
  12. #
  13. # Copyright © 2003 - 2022 Michael Pyne. <mpyne@kde.org>
  14. # Copyright © 2018 - 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
  15. # Copyright © 2005, 2006, 2008 - 2011 David Faure <faure@kde.org>
  16. # Copyright © 2005 Thiago Macieira <thiago@kde.org>
  17. # Copyright © 2006 Stephan Kulow <coolo@kde.org>
  18. # Copyright © 2006, 2008 Dirk Mueller <mueller@kde.org>
  19. # ... and possibly others. Check the git source repository for specifics.
  20. #
  21. # This program is free software; you can redistribute it and/or modify it under
  22. # the terms of the GNU General Public License as published by the Free Software
  23. # Foundation; either version 2 of the License, or (at your option) any later
  24. # version.
  25. #
  26. # This program is distributed in the hope that it will be useful, but WITHOUT
  27. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  28. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  29. # details.
  30. #
  31. # You should have received a copy of the GNU General Public License along with
  32. # this program; if not, write to the Free Software Foundation, Inc., 51
  33. # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  34.  
  35. # Adding an option? Grep for 'defaultGlobalOptions' in ksb::BuildContext --mpyne
  36.  
  37. #### Script start. Step 1: Tell Perl where to find our 'ksb' modules in relation
  38. #### to where we are at.
  39.  
  40. use v5.26;
  41. use strict;
  42. use warnings;
  43.  
  44. # On many container-based distros, even FindBin is missing to conserve space.
  45. # But we can use File::Spec to do nearly the same.
  46. my $RealBin;
  47. my $modPath;
  48.  
  49. # The File::Spec calls have to run when parsing (i.e. in BEGIN) to make the
  50. # 'use lib' below work (which itself implicitly uses BEGIN { })
  51. BEGIN {
  52. use File::Spec;
  53.  
  54. # resolve symlinks
  55. my $scriptPath = $0;
  56. for (1..16) {
  57. last unless -l $scriptPath;
  58. $scriptPath = readlink $scriptPath;
  59. }
  60. die "Too many symlinks followed looking for script" if -l $scriptPath;
  61.  
  62. my ($volume, $directories, $script) = File::Spec->splitpath($scriptPath);
  63.  
  64. $RealBin = File::Spec->catpath($volume, $directories, '');
  65. die "Couldn't find base directory!" unless $RealBin;
  66.  
  67. # Use modules in git repo if running from git dir, otherwise assume
  68. # system install
  69. $modPath = File::Spec->rel2abs('modules', $RealBin);
  70. $modPath = ($RealBin =~ s,/bin/?$,/share/kdesrc-build/modules,r)
  71. unless -d $modPath;
  72.  
  73. die "Couldn't find modules for kdesrc-build!" unless $modPath;
  74. }
  75.  
  76. # We use third party embedded modules but we should prefer system versions if
  77. # available so add to the end of @INC rather than the beginning, this is why
  78. # we don't do "use lib '$modPath'"
  79. BEGIN {
  80. push @INC, "$modPath";
  81. }
  82.  
  83. #### Now that Perl can find our modules, load them and start processing command line arguments
  84.  
  85. use ksb; # Enable boilerplate
  86.  
  87. # When running in a limited environment, we might not be able to load
  88. # our modules although we can find them. In this case we should help user
  89. # by setting up system dependencies.
  90. eval {
  91. if (grep { $_ eq '--initial-setup' } @ARGV) {
  92. require ksb::FirstRun;
  93. require ksb::Debug;
  94. ksb::Debug::setColorfulOutput(1);
  95. exit ksb::FirstRun::setupUserSystem(File::Spec->rel2abs($RealBin));
  96. }
  97. };
  98.  
  99. if ($@) {
  100. say STDERR <<DONE;
  101. * Unable to even load the simplistic initial setup support for some reason??
  102.  
  103. $@
  104.  
  105. You could:
  106. File a bug https://bugs.kde.org/enter_bug.cgi?product=kdesrc-build
  107. Ask for help on irc.libera.chat in the #kde channel
  108. DONE
  109. exit 1;
  110. }
  111.  
  112. # Even though the flow of execution should not make it here unless the modules
  113. # we need are installed, we still cannot "use" the modules that might be
  114. # missing on first use since just trying to parse/compile the code is then
  115. # enough to cause errors.
  116. eval {
  117. require Carp;
  118. require ksb::Debug;
  119. require ksb::Util;
  120. require ksb::Version;
  121. require ksb::Application;
  122. require ksb::BuildException;
  123. };
  124.  
  125. if ($@) {
  126. say STDERR <<DONE;
  127. Couldn't load the base platform for kdesrc-build!
  128.  
  129. $@
  130. DONE
  131.  
  132. # According to XDG spec, if $XDG_CONFIG_HOME is not set, then we should default
  133. # to ~/.config
  134. my $xdgConfigHome = $ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config";
  135. my @possibleConfigPaths = ("./kdesrc-buildrc",
  136. "$xdgConfigHome/kdesrc-buildrc",
  137. "$ENV{HOME}/.kdesrc-buildrc");
  138.  
  139. if (!grep { -e $_ } (@possibleConfigPaths)) {
  140. say STDERR <<~DONE;
  141. It appears you've not run kdesrc-build before.
  142.  
  143. Please run "kdesrc-build --initial-setup" and kdesrc-build will guide you
  144. through setting up required dependencies and environment setup.
  145. DONE
  146. } else {
  147. say STDERR <<~DONE;
  148. You could:
  149. File a bug https://bugs.kde.org/enter_bug.cgi?product=kdesrc-build
  150. Ask for help on irc.libera.chat in the #kde channel
  151. DONE
  152. }
  153. exit 1;
  154. }
  155.  
  156. ksb::Debug->import();
  157. ksb::Util->import();
  158. ksb::BuildException->import();
  159. ksb::Version->import(qw(scriptVersion));
  160. ksb::Application->import();
  161.  
  162. # Make Perl 'plain die' exceptions use Carp::confess instead of their core
  163. # support. This is not supported by the Perl 5 authors but assuming it works
  164. # will be better than the alternative backtrace we get (which is to say, none)
  165. $SIG{__DIE__} = \&Carp::confess;
  166.  
  167. ksb::Version::setBasePath($RealBin);
  168.  
  169. # Script starts.
  170.  
  171. # Adding in a way to load all the functions without running the program to
  172. # enable some kind of automated QA testing.
  173. if (defined caller && caller eq 'test')
  174. {
  175. my $scriptVersion = scriptVersion();
  176. say "kdesrc-build being run from testing framework, BRING IT.";
  177. say "kdesrc-build is version $scriptVersion";
  178. return 1;
  179. }
  180.  
  181. my $app;
  182.  
  183. eval
  184. {
  185. $app = ksb::Application->new(@ARGV);
  186.  
  187. my $result = $app->runAllModulePhases();
  188.  
  189. $app->finish($result); # noreturn
  190. };
  191.  
  192. if (my $err = $@)
  193. {
  194. if (had_an_exception()) {
  195. say <<~DONE;
  196. kdesrc-build encountered an exceptional error condition:
  197. ========
  198. $err
  199. ========
  200. Can't continue, so stopping now.
  201.  
  202. DONE
  203.  
  204. if ($err->{'exception_type'} eq 'Internal') {
  205. say "Please submit a bug against kdesrc-build on https://bugs.kde.org/";
  206. }
  207. } else {
  208. # We encountered some other kind of error that didn't raise a ksb::BuildException
  209. say <<~DONE;
  210. Encountered an error in the execution of the script.
  211. --> $err
  212. Please submit a bug against kdesrc-build on https://bugs.kde.org/
  213. DONE
  214. }
  215.  
  216. $app->finish(99) if $app; # noreturn
  217. exit 99; # if $app couldn't be created
  218. }
  219.  
  220. # vim: set et sw=4 ts=4 fdm=marker:
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement