1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
#!/usr/bin/perl
#
# Purpose: This perl script needs to be executed from the
# git repository. It will copy all relevant files, including
# scripts, hbotStringFile, .list, .syms and .bin files needed for debug
# to the user specified directory.
#
# Author: CamVan Nguyen 07/07/2011
#
#
# Usage:
# cpFiles.pl <path>
#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
use strict;
use warnings;
use Cwd;
use File::Basename;
use File::Spec;
#------------------------------------------------------------------------------
# Forward Declaration
#------------------------------------------------------------------------------
sub printUsage;
#------------------------------------------------------------------------------
# Global arrays
#------------------------------------------------------------------------------
#List of files to copy. Path is relative to git repository.
my @files = ("src/build/tools/exthbdump.pl",
"src/build/trace/traceHB.py",
"img/hbotStringFile",
"img/hbicore.syms",
"img/hbicore_test.syms",
"img/hbicore.bin",
"img/hbicore_test.bin",
"img/hbicore.list",
"img/hbicore_test.list");
#Directories in base git repository
my @gitRepoDirs = ("img",
"obj",
"src");
#==============================================================================
# MAIN
#==============================================================================
#------------------------------------------------------------------------------
# Parse optional input argument
#------------------------------------------------------------------------------
my $numArgs = $#ARGV + 1;
#print "num args = $numArgs\n";
my $test = 0; #Flag to overwrite hbicore.<syms|bin|list> with the test versions
my $inDir = ""; #User specified directory to copy files to
if ($numArgs > 2)
{
#Print command line help
print ("ERROR: Too many arguments entered.\n");
printUsage();
exit (1);
}
else
{
foreach (@ARGV)
{
if ($_ eq "-help")
{
#Print command line help
printUsage();
exit (0);
}
elsif ($_ eq "-test")
{
#Set flag to copy hbicore_test.<syms|bin> to hbcore_test.<syms|bin>
$test = 1;
}
else
{
#Save user specified directory
$inDir = $_;
}
}
}
#------------------------------------------------------------------------------
# Initialize the paths to copy files to
#------------------------------------------------------------------------------
my $simicsDir = "";
my $imgDir = "";
my $sandbox = $ENV{'SANDBOXBASE'};
if ($inDir ne "")
{
$simicsDir = $inDir;
$imgDir = $inDir;
print "input dir = $inDir\n";
#If simics directory specified
if (basename($inDir) eq "simics")
{
#Check if img dir exists else will copy .bin files to simics dir
$imgDir = File::Spec->catdir($inDir, "../img");
unless (-d ($inDir."/../img"))
{
$imgDir = $inDir;
print "No img directory found in sandbox. Copying .bin files";
print " to simics directory\n";
}
}
}
elsif (defined ($sandbox))
{
unless ($sandbox ne "")
{
die ('ERROR: No path specified and env $SANBOXBASE = NULL'."\n");
}
print "sandbox = $sandbox\n";
#Check if simics and img dirs exist, else exit
$simicsDir = File::Spec->catdir($sandbox, "simics");
$imgDir = File::Spec->catdir($sandbox, "img");
print "simics dir = $simicsDir\n img dir = $imgDir\n";
unless ((-d $simicsDir) && (-d $imgDir))
{
die ("ERROR: simics and/or img directories not found in sandbox\n");
}
}
else
{
print 'ERROR: No path specified and env $SANDBBOXBASE not set.'."\n";
printUsage();
exit(1);
}
#------------------------------------------------------------------------------
# Get the base dir of the git repository
#------------------------------------------------------------------------------
my $cwd = getcwd();
my @paths = File::Spec->splitdir($cwd);
#print "@paths\n";
my @list;
my $data;
foreach $data (@paths)
{
last if grep { $_ eq $data } @gitRepoDirs;
push @list, $data;
}
#print "@list\n";
my $gitRepo = File::Spec->catdir(@list);
#print "$gitRepo\n";
#------------------------------------------------------------------------------
# Copy files to user specified directory or to sandbox
# Use unix command vs perl's File::Copy to preserve file attributes
#------------------------------------------------------------------------------
my $command = "";
my $copyDir = "";
chdir $gitRepo;
#print "cwd: ", getcwd()."\n";
foreach (@files)
{
$command = "";
my($filename, $directories, $suffix) = fileparse($_, qr{\..*});
#print "$filename, $directories, $suffix\n";
#Copy .bin to the img dir
if ($suffix eq ".bin")
{
$copyDir = $imgDir;
}
else
{
$copyDir = $simicsDir;
}
#Check if user wants to copy test versions to hbicore.<syms|bin|list>
if ($test == 1)
{
#Copy test versions to hbicore.<syms|bin|list>
if ($filename eq "hbicore_test")
{
$command = sprintf("cp %s %s", $_, $copyDir."/hbicore".$suffix);
}
elsif ($filename ne "hbicore")
{
$command = sprintf("cp %s %s", $_, $copyDir);
}
}
else
{
$command = sprintf("cp %s %s", $_, $copyDir);
}
# Copy the file
if ($command ne "")
{
print "$command\n";
`$command`;
}
}
chdir $cwd;
#print "cwd: ", getcwd()."\n";
#==============================================================================
# SUBROUTINES
#==============================================================================
#------------------------------------------------------------------------------
# Print command line help
#------------------------------------------------------------------------------
sub printUsage()
{
print ("\nUsage: cpFiles.pl [-help] | [<path>] [-test]\n\n");
print (" This program needs to be executed from the git repository.\n");
print (" It will copy all relevant files, scripts, hbotStringFile,\n");
print (" .list, .syms and .bin files needed for debug to one of two\n");
print (" locations:\n");
print (" 1. <path> if one is specified by the user\n");
print (" 2. if <path> is not specified, then the files will be\n");
print (' copied to the path specified by env variable $SANDBOXBASE'."\n");
print (" if it is defined.\n\n");
print (" -help: prints usage information\n");
print (" -test: Copy hbicore_test.<syms|bin|list> to hbicore.<syms|bin|list>\n");
}
|