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

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

cms2build begins to export

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