summaryrefslogtreecommitdiffstats
path: root/src/build/tools/perl.modules/ToolInit.pm
blob: 381acaabb80679fc0485f1d727a4abb43dfac2ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/tools/perl.modules/ToolInit.pm $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2015
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG

package ToolInit;

use strict;
use Getopt::Long qw(:config pass_through);
use Switch;
# Allow platform scripts to use init_globals
use Exporter 'import';
our @EXPORT = qw(init_globals $debug $help $module_script MASTER FETCH_HEAD);

# Globals
our $debug = 0;
our $help = 0;
our $module_script = "";
my %globals = ( branch => "master");

# Projects that use ToolInit
use constant {
    MASTER => "master",
    FETCH_HEAD => "FETCH_HEAD",
    EKB => "EKB",
};

# Global options for all infrastructure scripts/modules
GetOptions("debug!" => \$debug,
           "help" => \$help,
           "module-script:s" => \$module_script,
           "branch:s" => \$globals{branch});

# sub init_globals
#
# Export global variables to all scripts/modules that need them
#
# @return hash - variables needed for infrastructure scripts
#
sub init_globals
{
    $globals{project_name} = $ENV{'PROJECT_NAME'};
    $globals{remote_server} = $ENV{'GERRIT_SRV'};

    if ($globals{project_name} eq "")
    {
        print "Environment not setup properly...\n\tRun 'source env.bash' or ";
        print "'./$module_script workon' based on your current environment\n";
        print "\tFor more info run './$module_script --help'\n";
        die ();
    }
    project_settings();

    return %globals;
}

# sub project_settings
#
# Set project specific settings for tools on any platform.
# Project names are found via env variable set (e.g.in env.bash)
# If project is not supported this fails, as supported must be added.
#
sub project_settings
{
    switch ($globals{project_name})
    {
        case (EKB)
        {
            $globals{gerrit_project} = "hw/ekb";
        }
        else
        {
            die "Project => $module_script not supported";
        }
    }
}
OpenPOWER on IntegriCloud