Warning, /sdk/kdesrc-build/kdesrc-build is written in an unsupported language. File is not indexed.

0001 #!/usr/bin/env perl
0002 
0003 # Script to handle building KDE from source code.
0004 #
0005 # Configuration is found in $XDG_CONFIG_HOME/kdesrc-buildrc,
0006 # with fallback at ~/.kdesrc-buildrc. $XDG_CONFIG_HOME normally ".config"
0007 #
0008 # Please also see the documentation that should be included with this program,
0009 # in the doc/ directory.
0010 #
0011 # Home page: https://apps.kde.org/kdesrc_build/
0012 #
0013 # Copyright © 2003 - 2022 Michael Pyne. <mpyne@kde.org>
0014 # Copyright © 2018 - 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
0015 # Copyright © 2005, 2006, 2008 - 2011 David Faure <faure@kde.org>
0016 # Copyright © 2005 Thiago Macieira <thiago@kde.org>
0017 # Copyright © 2006 Stephan Kulow <coolo@kde.org>
0018 # Copyright © 2006, 2008 Dirk Mueller <mueller@kde.org>
0019 # ... and possibly others. Check the git source repository for specifics.
0020 #
0021 # This program is free software; you can redistribute it and/or modify it under
0022 # the terms of the GNU General Public License as published by the Free Software
0023 # Foundation; either version 2 of the License, or (at your option) any later
0024 # version.
0025 #
0026 # This program is distributed in the hope that it will be useful, but WITHOUT
0027 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
0028 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
0029 # details.
0030 #
0031 # You should have received a copy of the GNU General Public License along with
0032 # this program; if not, write to the Free Software Foundation, Inc., 51
0033 # Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0034 
0035 # Adding an option? Grep for 'defaultGlobalOptions' in ksb::BuildContext --mpyne
0036 
0037 ####  Script start.  Step 1: Tell Perl where to find our 'ksb' modules in relation
0038 ####  to where we are at.
0039 
0040 use v5.26;
0041 use strict;
0042 use warnings;
0043 
0044 # On many container-based distros, even FindBin is missing to conserve space.
0045 # But we can use File::Spec to do nearly the same.
0046 my $RealBin;
0047 my $modPath;
0048 
0049 # The File::Spec calls have to run when parsing (i.e. in BEGIN) to make the
0050 # 'use lib' below work (which itself implicitly uses BEGIN { })
0051 BEGIN {
0052     use File::Spec;
0053 
0054     # resolve symlinks
0055     my $scriptPath = $0;
0056     for (1..16) {
0057         last unless -l $scriptPath;
0058         $scriptPath = readlink $scriptPath;
0059     }
0060     die "Too many symlinks followed looking for script" if -l $scriptPath;
0061 
0062     my ($volume, $directories, $script) = File::Spec->splitpath($scriptPath);
0063 
0064     $RealBin = File::Spec->catpath($volume, $directories, '');
0065     die "Couldn't find base directory!" unless $RealBin;
0066 
0067     # Use modules in git repo if running from git dir, otherwise assume
0068     # system install
0069     $modPath = File::Spec->rel2abs('modules', $RealBin);
0070     $modPath = ($RealBin =~ s,/bin/?$,/share/kdesrc-build/modules,r)
0071         unless -d $modPath;
0072 
0073     die "Couldn't find modules for kdesrc-build!" unless $modPath;
0074 }
0075 
0076 # We use third party embedded modules but we should prefer system versions if
0077 # available so add to the end of @INC rather than the beginning, this is why
0078 # we don't do "use lib '$modPath'"
0079 BEGIN {
0080     push @INC, "$modPath";
0081 }
0082 
0083 ####  Now that Perl can find our modules, load them and start processing command line arguments
0084 
0085 use ksb; # Enable boilerplate
0086 
0087 # When running in a limited environment, we might not be able to load
0088 # our modules although we can find them. In this case we should help user
0089 # by setting up system dependencies.
0090 eval {
0091     if (grep { $_ eq '--initial-setup' } @ARGV) {
0092         require ksb::FirstRun;
0093         require ksb::Debug;
0094         ksb::Debug::setColorfulOutput(1);
0095         exit ksb::FirstRun::setupUserSystem(File::Spec->rel2abs($RealBin));
0096     }
0097 };
0098 
0099 if ($@) {
0100     say STDERR <<DONE;
0101 * Unable to even load the simplistic initial setup support for some reason??
0102 
0103 $@
0104 
0105 You could:
0106  File a bug https://bugs.kde.org/enter_bug.cgi?product=kdesrc-build
0107  Ask for help on irc.libera.chat in the #kde channel
0108 DONE
0109     exit 1;
0110 }
0111 
0112 # Even though the flow of execution should not make it here unless the modules
0113 # we need are installed, we still cannot "use" the modules that might be
0114 # missing on first use since just trying to parse/compile the code is then
0115 # enough to cause errors.
0116 eval {
0117     require Carp;
0118     require ksb::Debug;
0119     require ksb::Util;
0120     require ksb::Version;
0121     require ksb::Application;
0122     require ksb::BuildException;
0123 };
0124 
0125 if ($@) {
0126     say STDERR <<DONE;
0127 Couldn't load the base platform for kdesrc-build!
0128 
0129 $@
0130 DONE
0131 
0132     # According to XDG spec, if $XDG_CONFIG_HOME is not set, then we should default
0133     # to ~/.config
0134     my $xdgConfigHome = $ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config";
0135     my @possibleConfigPaths = ("./kdesrc-buildrc",
0136                                "$xdgConfigHome/kdesrc-buildrc",
0137                                "$ENV{HOME}/.kdesrc-buildrc");
0138 
0139     if (!grep { -e $_ } (@possibleConfigPaths)) {
0140         say STDERR <<~DONE;
0141         It appears you've not run kdesrc-build before.
0142 
0143         Please run "kdesrc-build --initial-setup" and kdesrc-build will guide you
0144         through setting up required dependencies and environment setup.
0145         DONE
0146     } else {
0147         say STDERR <<~DONE;
0148         You could:
0149          File a bug https://bugs.kde.org/enter_bug.cgi?product=kdesrc-build
0150          Ask for help on irc.libera.chat in the #kde channel
0151         DONE
0152     }
0153     exit 1;
0154 }
0155 
0156 ksb::Debug->import();
0157 ksb::Util->import();
0158 ksb::BuildException->import();
0159 ksb::Version->import(qw(scriptVersion));
0160 ksb::Application->import();
0161 
0162 # Make Perl 'plain die' exceptions use Carp::confess instead of their core
0163 # support. This is not supported by the Perl 5 authors but assuming it works
0164 # will be better than the alternative backtrace we get (which is to say, none)
0165 $SIG{__DIE__} = \&Carp::confess;
0166 
0167 ksb::Version::setBasePath($RealBin);
0168 
0169 # Script starts.
0170 
0171 # Adding in a way to load all the functions without running the program to
0172 # enable some kind of automated QA testing.
0173 if (defined caller && caller eq 'test')
0174 {
0175     my $scriptVersion = scriptVersion();
0176     say "kdesrc-build being run from testing framework, BRING IT.";
0177     say "kdesrc-build is version $scriptVersion";
0178     return 1;
0179 }
0180 
0181 my $app;
0182 
0183 eval
0184 {
0185     $app = ksb::Application->new(@ARGV);
0186 
0187     my $result = $app->runAllModulePhases();
0188 
0189     $app->finish($result); # noreturn
0190 };
0191 
0192 if (my $err = $@)
0193 {
0194     if (had_an_exception()) {
0195         say <<~DONE;
0196         kdesrc-build encountered an exceptional error condition:
0197          ========
0198             $err
0199          ========
0200         Can't continue, so stopping now.
0201 
0202         DONE
0203 
0204         if ($err->{'exception_type'} eq 'Internal') {
0205             say "Please submit a bug against kdesrc-build on https://bugs.kde.org/";
0206         }
0207     } else {
0208         # We encountered some other kind of error that didn't raise a ksb::BuildException
0209         say <<~DONE;
0210         Encountered an error in the execution of the script.
0211         --> $err
0212         Please submit a bug against kdesrc-build on https://bugs.kde.org/
0213         DONE
0214     }
0215 
0216     $app->finish(99) if $app; # noreturn
0217     exit 99; # if $app couldn't be created
0218 }
0219 
0220 # vim: set et sw=4 ts=4 fdm=marker: