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

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

/etc/pb/proj now contains the strict minimum
rest is under pbconf/proj.pb

  • Property svn:executable set to *
File size: 3.1 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#
36my $pbroot=pb_init("$ENV{'PBETC'}/$proj");
37
38if (not defined $pbroot) {
39 die "pbroot doesn't exist in $ENV{'PBETC'}/$proj";
40} else {
41 $ENV{'PBROOT'} = $pbroot;
42}
43
44pb_conf_init("$ENV{'PBROOT'}/pbconf/$proj.pb");
45
46#
47# Check content
48#
49if (defined $confparam{"cvsroot"}) {
50 $ENV{'CVSROOT'} = $confparam{"cvsroot"};
51}
52
53die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
54
55#
56# Set temp directory
57#
58if (not defined $ENV{'TMPDIR'}) {
59 $ENV{'TMPDIR'}="/tmp";
60}
61$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
62
63#
64# Check pb conf compliance
65#
66$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
67die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
68
69#
70# Get global VERSION
71#
72open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
73$ver = <VER>;
74chomp($ver);
75#print Dumper(%version);
76die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
77$ENV{'PBVER'}=$ver;
78close(VER);
79
80#
81#Get global TAG
82#
83open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
84$tag = <TAG>;
85chomp($tag);
86die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
87$ENV{'PBTAG'}=$tag;
88close(TAG);
89
90#
91# Adapt to your needs
92# Set delivery directory
93#
94chdir "$ENV{'PBROOT'}/..";
95my $path = `pwd`;
96chomp($path);
97$ENV{'PBTOPDIR'}=$path."/delivery";
98$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
99if (-d $ENV{'PBDESTDIR'}) {
100 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
101 foreach my $d (readdir(DIR)) {
102 next if ($d =~ /^\./);
103 pbrm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
104 }
105 closedir(DIR);
106}
107if (! -d "$ENV{'PBDESTDIR'}") {
108 pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
109}
110
111#
112# Set build directory
113#
114$ENV{'PBBUILDDIR'}=$path."/build";
115pbrm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
116pbmkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
117
118umask 0022;
119return($proj);
120}
121
122sub pbmkdir_p {
123my @dir = @_;
124my $ret = mkpath(@dir, 0, 0755);
125return($ret);
126}
127
128sub pbrm_rf {
129my @dir = @_;
130my $ret = rmtree(@dir, 0, 0);
131return($ret);
132}
133
134sub pbsystem {
135
136my $cmd=shift;
137my $cmt=shift || $cmd;
138
139print $LOG "$cmt... ";
140system("$cmd");
141if ($? == -1) {
142 print $LOG "failed to execute: $!\n" if ($debug >= 0);
143} elsif ($? & 127) {
144 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
145} else {
146 print $LOG "OK\n" if ($debug >= 0);
147}
148}
1491;
Note: See TracBrowser for help on using the repository browser.