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