source: ProjectBuilder/devel/pb/lib/common.pm@ 18

Last change on this file since 18 was 18, checked in by Bruno Cornec, 17 years ago

cms2build roughly working

  • Property svn:executable set to *
File size: 2.2 KB
RevLine 
[2]1#!/usr/bin/perl -w
2#
3# Creates common environment
4#
5# $Id$
6#
7
[18]8use strict;
[5]9use lib qw (lib);
[6]10use pb qw (pb_init);
[2]11use File::Basename;
[9]12use File::Path;
[2]13use File::Temp qw /tempdir/;
[8]14use Data::Dumper;
[2]15
[13]16$ENV{'PBETC'} = "/etc/pb";
[5]17
[9]18sub env_init {
[2]19
[5]20my $proj=shift;
21my $ver;
22my $tag;
[2]23
[8]24#
[5]25# Check project name
[8]26#
[5]27if ((defined $ENV{'PBPROJ'}) &&
28 (not (defined $proj))) {
29 $proj = $ENV{'PBPROJ'};
30}
31die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
[2]32
[8]33#
[5]34# Use project configuration file
[8]35#
[13]36pb_init("$ENV{'PBETC'}/$proj.pb");
[2]37
[8]38#
[5]39# Check content
[8]40#
[18]41if (not defined $confparam{"pbroot"}) {
42 die "confparam pbroot doesn't exist in $ENV{'PBETC'}/$proj.pb";
[17]43} else {
[18]44 $ENV{'PBROOT'} = $confparam{"pbroot"};
[17]45}
[18]46if (defined $confparam{"cvsroot"}) {
47 $ENV{'CVSROOT'} = $confparam{"cvsroot"};
[17]48}
49
[13]50die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
[5]51
[8]52#
[5]53# Set temp directory
[8]54#
[7]55if (not defined $ENV{'TMPDIR'}) {
[2]56 $ENV{'TMPDIR'}="/tmp";
57}
[5]58$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
[2]59
[8]60#
61# Check pb conf compliance
62#
[11]63$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
64die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
[8]65
66#
[5]67# Get global VERSION
[8]68#
[11]69open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
[5]70$ver = <VER>;
71chomp($ver);
[8]72#print Dumper(%version);
73die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
[5]74$ENV{'PBVER'}=$ver;
75close(VER);
76
[8]77#
[5]78#Get global TAG
[8]79#
[11]80open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
[5]81$tag = <TAG>;
82chomp($tag);
[8]83die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
[5]84$ENV{'PBTAG'}=$tag;
85close(TAG);
86
[8]87#
[5]88# Adapt to your needs
89# Set delivery directory
[8]90#
[5]91$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
[9]92$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
93pbrm_rf($ENV{'PBDESTDIR'}) if (-d "$ENV{'PBDESTDIR'}");
94pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
[5]95
[8]96umask 0022;
97return($proj);
[2]98}
[9]99
100sub pbmkdir_p {
101 my @dir = @_;
102 my $ret = mkpath(@dir, 0, 0755);
103 return($ret);
104}
105
106sub pbrm_rf {
107 my @dir = @_;
108 my $ret = rmtree(@dir, 0, 0);
109 return($ret);
110}
111
[2]1121;
Note: See TracBrowser for help on using the repository browser.