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