1 ###############################################################################
2 # Copyright (c) 2000-2014 Ericsson Telecom AB
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Eclipse Public License v1.0
5 # which accompanies this distribution, and is available at
6 # http://www.eclipse.org/legal/epl-v10.html
7 ###############################################################################
9 ###############################################################################
10 # This script is intended to archive the project hierarchy from a TPD file structure
11 ###############################################################################
18 my $ttcn3_dir = $ENV{'TTCN3_DIR'};
19 my $bindir = $ttcn3_dir . "/bin";
21 my @list = readFile
();
22 my $tpd = getTPDFileName
(\
@list);
24 if (-l
$tpd) #get the path if it is a symlink
26 $tpd = `readlink $tpd`;
29 my $root = getPathToRootDir
(\
@list); # get the workspace directory of the OS
31 chdir ($root) or die "cannot change: $!\n";
32 my $cutstring = cwd
; # this is string generated from the the absolut path to the workspace
33 my $archiveDir = getArchiveDir
(\
@list); #directory to place the archive
34 $archiveDir = $home . "/" . $archiveDir;
36 my $createDir = "mkdir -p " . $archiveDir;
37 my $res = system($createDir);
38 my $backupFileName = createBackupFileName
();
39 my $backupfile = $archiveDir . "/" . $backupFileName;
40 if ($res != 0) { die (" creating directory " . $archiveDir ." failed\n"); }
41 my $archive = $bindir . "/" . "ttcn3_makefilegen" ." -V -P " . $cutstring . " -t " . $tpd . " | xargs tar cfz ". $archiveDir . "/" . $backupFileName . " 2> /dev/null";
42 system($archive); #running it
43 if (-e
$backupfile) { print ("archiving succeeded\n"); }
44 else { print ("archiving failed\n"); }
45 chdir ($home) or die "cannot change: $!\n";
46 ############################################################
49 my $makefile = "Makefile";
50 open ( FILE
, "<", $makefile ) or die ( "failed to open file: $home\/$makefile\n" );
55 ############################################################
56 sub getPathToRootDir
#get the relative path to OS workspace
59 my $search = qr/^ROOT_DIR =/s;
62 for my $i ( 0 .. $#list )
64 if ( $list[$i] =~ $search )
68 $offset = index($list[$i], $dot);
72 if ($offset == 0) { die ( "no ROOT_DIR variable was found in the Makefile\n" ); }
73 my $path = substr $line, $offset;
76 ############################################################
77 sub getTPDFileName
# TPD filename what the Makefile is created from
80 my $search = qr/^TPD =/s;
83 for my $i ( 0 .. $#list )
85 if ( $list[$i] =~ $search )
89 $offset = index($list[$i], $assign);
93 if ($offset == 0) { die ( "no TPD variable was found in the Makefile\n" ); }
94 my $file = substr $line, $offset + 1;
95 $file =~ s/^\s+|\s+$//; # remove heading and traling whitespaces
98 ############################################################
99 sub getArchiveDir
# the name of the archive directory
102 my $search = qr/^ARCHIVE_DIR =/s;
105 for my $i ( 0 .. $#list )
107 if ( $list[$i] =~ $search )
111 $offset = index($list[$i], $assign);
115 if ($offset == 0) { die ( "no ARCHIVE_DIR variable was found in the Makefile\n" ); }
116 my $dir = substr $line, $offset + 1;
117 $dir =~ s/^\s+|\s+$//; # remove heading and trailing whitespaces
120 ############################################################
121 sub getExecutableName
# the name of the target executable
124 my $search = qr/^EXECUTABLE =/s;
127 for my $i ( 0 .. $#list )
129 if ( $list[$i] =~ $search )
133 $offset = index($list[$i], $assign);
137 if ($offset == 0) { die ( "no EXCUTABLE variable was found in the Makefile\n" ); }
138 my $exec = substr $line, $offset + 1;
139 $exec =~ s/^\s+|\s+$//; # remove heading and trailing whitespaces
142 ############################################################
143 sub createBackupFileName
145 my $backupFile = getExecutableName
(\
@list);
147 my $result = index($backupFile, $dot);
150 $backupFile = substr $backupFile, 0, $result;
153 my $date = `date '+%y%m%d-%H%M'`;
155 my $baseName = $backupFile . "-" . $date . ".tgz";
159 ############################################################
This page took 0.118877 seconds and 5 git commands to generate.