Files
rocm-systems/tests/hit/parser
T

96 строки
3.0 KiB
Perl
Исходник Обычный вид История

#!/usr/bin/perl -w
use 5.006; use v5.10.1;
use File::Basename;
use File::Spec;
# Scan input file for HIT information
sub parse_file {
my $file = shift;
(my $exe = $file) =~ s/\.[^.]+$//g;
2016-09-27 17:22:23 +05:30
my (@buildCMDs, @runCMDs, @runNamedCMDs);
if (open (SOURCE, '<:encoding(UTF-8)', "$file")) {
while (<SOURCE>) {
my $line=$_;
# Look for BUILD instructions
if ($line =~ /^ \* BUILD:/) {
2016-09-27 17:22:23 +05:30
$line =~ s/^ \* BUILD: //g; # Remove " * BUILD: "
$line =~ s/%s/$file/g; # Substitute %s -> filename
$line =~ s/%t/$exe/g; # Substitute %t -> targetname
$line =~ s/\R//g; # Remove line endings
push @buildCMDs, $line;
}
# Look for RUN instructions
if ($line =~ /^ \* RUN:/) {
2016-09-27 17:22:23 +05:30
$line =~ s/^ \* RUN: //g; # Remove " * RUN: "
$line =~ s/%s/$file/g; # Substitute %s -> filename
$line =~ s/%t/$exe/g; # Subsitute %t -> targetname
$line =~ s/\R//g; # Remove line endings
push @runCMDs, $line;
}
2016-09-27 17:22:23 +05:30
# Look for RUN_NAMED instructions
if ($line =~ /^ \* RUN_NAMED:/) {
$line =~ s/^ \* RUN_NAMED: //g; # Remove " * RUN_NAMED: "
$line =~ s/%s/$file/g; # Substitute %s -> filename
$line =~ s/%t/$exe/g; # Subsitute %t -> targetname
$line =~ s/\R//g; # Remove line endings
push @runNamedCMDs, $line;
}
}
close(SOURCE);
}
2016-09-27 17:22:23 +05:30
return (\@buildCMDs, \@runCMDs, \@runNamedCMDs);
}
# Exit if no arguments specified
if(scalar @ARGV == 0){
print "No Arguments passed, exiting ...\n";
exit(-1);
}
# Parse command
my @options = ();
my $retBuildCMDs = 0;
my $retRunCMDs = 0;
2016-09-27 17:22:23 +05:30
my $retRunNamedCMDs = 0;
foreach $arg (@ARGV) {
2016-09-27 17:22:23 +05:30
if ($retBuildCMDs or $retRunCMDs or $retRunNamedCMDs) {
push (@options, $arg);
}
if ($arg eq '--buildCMDs') {
$retBuildCMDs = 1;
}
if ($arg eq '--runCMDs') {
$retRunCMDs = 1;
}
2016-09-27 17:22:23 +05:30
if ($arg eq '--runNamedCMDs') {
$retRunNamedCMDs = 1;
}
}
# Atleast one command needs to be specified
2016-09-27 17:22:23 +05:30
if (($retBuildCMDs eq 0) and ($retRunCMDs eq 0) and ($retRunNamedCMDs eq 0)) {
die "Usage: $0 <--buildCMDs|--runCMDs|--runNamedCMDs> FILENAMEs\n";
}
# Iterate over input files
foreach $file (@options) {
# Convert absolute path to path relative to working directory
my $relfile = File::Spec->abs2rel($file);
2016-09-27 17:22:23 +05:30
my ($buildCMDs, $runCMDs, $runNamedCMDs) = parse_file("$relfile");
if ($retBuildCMDs) {
# print "BuildCMDs:\n";
print "$_\n" for @$buildCMDs;
}
if ($retRunCMDs) {
# print "RunCMDs:\n";
print "$_\n" for @$runCMDs;
}
2016-09-27 17:22:23 +05:30
if ($retRunNamedCMDs) {
# print "RunNamedCMDs:\n";
print "$_\n" for @$runNamedCMDs;
}
}
# vim: ts=4:sw=4:expandtab:smartindent