aef646beef0216afbadf706ffa7c82e9be169064
[deliverable/titan.core.git] / etc / scripts / ttcn3_archive
1 #!/usr/bin/perl
2 ###############################################################################
3 # Copyright (c) 2000-2016 Ericsson Telecom AB
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Eclipse Public License v1.0
6 # which accompanies this distribution, and is available at
7 # http://www.eclipse.org/legal/epl-v10.html
8 #
9 # Contributors:
10 # Baji, Laszlo
11 # Balasko, Jeno
12 #
13 ###############################################################################
14 ###############################################################################
15 # This script is intended to archive the project hierarchy from a TPD file structure
16 ###############################################################################
17 use 5.010;
18 use strict;
19 use warnings;
20 use Cwd;
21 use File::Copy;
22
23 my $ttcn3_dir = $ENV{'TTCN3_DIR'};
24 my $bindir = $ttcn3_dir . "/bin";
25 my $home = cwd();
26 my @list = readFile();
27 my $tpd = getTPDFileName(\@list);
28 chomp ($tpd);
29 if (-l $tpd) #get the path if it is a symlink
30 {
31 $tpd = `readlink $tpd`;
32 chomp ($tpd);
33 }
34 my $root = getPathToRootDir(\@list); # get the workspace directory of the OS
35 chomp ($root);
36 chdir ($root) or die "cannot change: $!\n";
37 my $cutstring = cwd; # this is string generated from the the absolute path to the workspace
38 my $archiveDir = getArchiveDir(\@list); #directory to place the archive
39 $archiveDir = $home . "/" . $archiveDir;
40 chomp ($archiveDir);
41 my $createDir = "mkdir -p " . $archiveDir;
42 my $res = system($createDir);
43 my $backupFileName = createBackupFileName();
44 my $backupfile = $archiveDir . "/" . $backupFileName;
45 if ($res != 0) { die (" creating directory " . $archiveDir ." failed\n"); }
46 my $archive = $bindir . "/" . "ttcn3_makefilegen" ." -V -P " . $cutstring . " -t " . $tpd . " | xargs tar cfz ". $archiveDir . "/" . $backupFileName . " 2> /dev/null";
47 system($archive); #running it
48 if (-e $backupfile) { print ("archiving succeeded\n"); }
49 else { print ("archiving failed\n"); }
50 chdir ($home) or die "cannot change: $!\n";
51 ############################################################
52 sub readFile
53 {
54 my $makefile = "Makefile";
55 open ( FILE, "<", $makefile ) or die ( "failed to open file: $home\/$makefile\n" );
56 my @lines = <FILE>;
57 close FILE;
58 return @lines;
59 }
60 ############################################################
61 sub getPathToRootDir #get the relative path to OS workspace
62 {
63 my @list = @{$_[0]};
64 my $search = qr/^ROOT_DIR =/s;
65 my $offset = 0;
66 my $line;
67 for my $i ( 0 .. $#list )
68 {
69 if ( $list[$i] =~ $search )
70 {
71 $line = $list[$i];
72 my $dot = '.';
73 $offset = index($list[$i], $dot);
74 last;
75 }
76 }
77 if ($offset == 0) { die ( "no ROOT_DIR variable was found in the Makefile\n" ); }
78 my $path = substr $line, $offset;
79 return $path;
80 }
81 ############################################################
82 sub getTPDFileName # TPD filename what the Makefile is created from
83 {
84 my @list = @{$_[0]};
85 my $search = qr/^TPD =/s;
86 my $offset = 0;
87 my $line;
88 for my $i ( 0 .. $#list )
89 {
90 if ( $list[$i] =~ $search )
91 {
92 $line = $list[$i];
93 my $assign = '=';
94 $offset = index($list[$i], $assign);
95 last;
96 }
97 }
98 if ($offset == 0) { die ( "no TPD variable was found in the Makefile\n" ); }
99 my $file = substr $line, $offset + 1;
100 $file =~ s/^\s+|\s+$//; # remove heading and traling whitespaces
101 return $file;
102 }
103 ############################################################
104 sub getArchiveDir # the name of the archive directory
105 {
106 my @list = @{$_[0]};
107 my $search = qr/^ARCHIVE_DIR =/s;
108 my $offset = 0;
109 my $line;
110 for my $i ( 0 .. $#list )
111 {
112 if ( $list[$i] =~ $search )
113 {
114 $line = $list[$i];
115 my $assign = '=';
116 $offset = index($list[$i], $assign);
117 last;
118 }
119 }
120 if ($offset == 0) { die ( "no ARCHIVE_DIR variable was found in the Makefile\n" ); }
121 my $dir = substr $line, $offset + 1;
122 $dir =~ s/^\s+|\s+$//; # remove heading and trailing whitespaces
123 return $dir;
124 }
125 ############################################################
126 sub getExecutableName # the name of the target executable
127 {
128 my @list = @{$_[0]};
129 my $search = qr/^EXECUTABLE =/s;
130 my $offset = 0;
131 my $line;
132 for my $i ( 0 .. $#list )
133 {
134 if ( $list[$i] =~ $search )
135 {
136 $line = $list[$i];
137 my $assign = '=';
138 $offset = index($list[$i], $assign);
139 last;
140 }
141 }
142 if ($offset == 0) { die ( "no EXCUTABLE variable was found in the Makefile\n" ); }
143 my $exec = substr $line, $offset + 1;
144 $exec =~ s/^\s+|\s+$//; # remove heading and trailing whitespaces
145 return $exec;
146 }
147 ############################################################
148 sub createBackupFileName
149 {
150 my $backupFile = getExecutableName(\@list);
151 my $dot = '.';
152 my $result = index($backupFile, $dot);
153 if ($result > -1)
154 {
155 $backupFile = substr $backupFile, 0, $result;
156 }
157 chomp ($backupFile);
158 my $date = `date '+%y%m%d-%H%M'`;
159 chomp ($date);
160 my $baseName = $backupFile . "-" . $date . ".tgz";
161 chomp ($baseName);
162 return $baseName;
163 }
This page took 0.062625 seconds and 4 git commands to generate.