Skip to content

Commit b880b86

Browse files
committed
Enhance enum checker to include meta header files
Signed-off-by: Tejaswini Chadaga <tchadaga@microsoft.com>
1 parent 1f3abf9 commit b880b86

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed

meta/ancestry.pl

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,27 @@
3636

3737
my %options = ();
3838

39-
getopts("dsASlDH:", \%options);
39+
use Getopt::Long qw(GetOptions Configure);
40+
Configure(qw(no_ignore_case));
4041

41-
our $optionPrintDebug = 1 if defined $options{d};
42-
our $optionDisableAspell = 1 if defined $options{A};
43-
our $optionUseXmlSimple = 1 if defined $options{s};
44-
our $optionDisableStyleCheck = 1 if defined $options{S};
45-
our $optionShowLogCaller = 1 if defined $options{l};
46-
our $optionDumpHistoryFile = 1 if defined $options{D};
47-
our $optionHistoryFile = $options{H} if defined $options{H};
42+
my ($optionPrintDebug, $optionDisableAspell, $optionUseXmlSimple,
43+
$optionDisableStyleCheck, $optionShowLogCaller, $optionDumpHistoryFile,
44+
$optionHistoryFile, $mydir);
45+
46+
my @mycommits;
47+
48+
GetOptions(
49+
'd|debug' => \$optionPrintDebug,
50+
'A|no-aspell' => \$optionDisableAspell,
51+
's|xmlsimple' => \$optionUseXmlSimple,
52+
'S|no-style' => \$optionDisableStyleCheck,
53+
'l|show-caller' => \$optionShowLogCaller,
54+
'D|dump-history' => \$optionDumpHistoryFile,
55+
'H|history-file=s' => \$optionHistoryFile,
56+
57+
'dir=s' => \$mydir, # Directory to process, e.g. inc or meta (default: inc)
58+
'commits=s{,}' => \@mycommits, # --commits c1 c2 c3 ...
59+
) or die "Usage: $0 [opts] --dir <dir> --commits <c1> [c2 ...]\n";
4860

4961
$SIG{__DIE__} = sub
5062
{
@@ -127,13 +139,15 @@ sub ProcessHeaders
127139
{
128140
my $commit = shift;
129141

130-
my @headers = GetHeaderFiles("temp/commit-$commit/inc");
142+
my $dir = defined($mydir) ? $mydir : 'inc';
143+
my $path = "temp/commit-$commit/$dir";
144+
145+
my @headers = GetHeaderFiles($path);
131146

132147
for my $header (@headers)
133148
{
134-
LogDebug "Processing $header";
135-
136-
ProcessSingleHeader "temp/commit-$commit/inc/$header";
149+
LogDebug "Processing $path/$header";
150+
ProcessSingleHeader "$path/$header";
137151
}
138152
}
139153

@@ -245,7 +259,7 @@ sub CleanData
245259
LogInfo "loaded history from $optionHistoryFile";
246260
}
247261

248-
for my $commit (@ARGV)
262+
for my $commit (@mycommits)
249263
{
250264
# reset
251265

@@ -264,15 +278,15 @@ sub CleanData
264278

265279
ExitOnErrorsOrWarnings();
266280

267-
if (defined $optionDumpHistoryFile and (scalar @ARGV > 0))
281+
if (defined $optionDumpHistoryFile and (scalar @mycommits > 0))
268282
{
269283
$Data::Dumper::Indent = 0;
270284

271285
my $history = Data::Dumper->Dump([\%HISTORY],[qw/*HISTORY/]);
272286

273287
$history =~ s/ //g;
274288

275-
my $lastCommit = $ARGV[-1];
289+
my $lastCommit = $mycommits[-1];
276290

277291
WriteFile("ancestry.$lastCommit.history", $history);
278292

meta/checkancestry.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,18 @@ function create_temp_dir()
7676

7777
function checkout_inc_directories()
7878
{
79-
echo "git checkout work tree commits:" $LIST
79+
echo "git checkout work tree commits:" $LIST_INC
8080

81-
for commit in $LIST
81+
for commit in $LIST_INC
8282
do
8383
#echo working on commit $commit
8484

8585
mkdir temp/commit-$commit
8686
mkdir temp/commit-$commit/inc
87+
mkdir temp/commit-$commit/meta
8788

8889
git --work-tree=temp/commit-$commit checkout $commit inc 2>/dev/null
90+
git --work-tree=temp/commit-$commit checkout $commit meta 2>/dev/null
8991

9092
done
9193
}
@@ -101,12 +103,21 @@ function create_commit_list()
101103

102104
echo "git rev list from $begin to $end"
103105

104-
LIST=$(git rev-list --ancestry-path ${begin}^..${end} | xargs -n 1 git rev-parse --short | tac)
106+
local FULL_LIST=$(git rev-list --ancestry-path ${begin}^..${end} | xargs -n 1 git rev-parse --short | tac)
107+
108+
local skip_begin=$3
109+
local skip_end=$4
110+
local SKIP_LIST=$(git rev-list --ancestry-path ${skip_begin}^..${skip_end} | xargs -n 1 git rev-parse --short | tac)
111+
112+
LIST_INC=$FULL_LIST
113+
LIST_META=$(grep -vxFf <(echo "$SKIP_LIST") <<< "$FULL_LIST")
114+
105115
}
106116

107117
function check_enum_history()
108118
{
109-
perl ancestry.pl -H "ancestry.1f2bca1.history" $LIST
119+
perl ancestry.pl -H "ancestry.1f2bca1.history" --dir "inc" --commits $LIST_INC
120+
perl ancestry.pl -H "ancestry.1f2bca1.history" --dir "meta" --commits $LIST_META
110121
}
111122

112123
#
@@ -123,11 +134,17 @@ function check_enum_history()
123134

124135
BEGIN_COMMIT=3132018 # from this commit we are backward compatible
125136
BEGIN_COMMIT=1f2bca1 # to this commit we have history file
137+
138+
# commits from skip_begin to skip_end are skipped from backward compatibility check
139+
# due to a regression in meta directory which was earlier excluded from this check
140+
SKIP_BEGIN=401bd1f
141+
SKIP_END=77578c8
142+
126143
END_COMMIT=HEAD
127144

128145
clean_temp_dir
129146
create_temp_dir
130-
create_commit_list $BEGIN_COMMIT $END_COMMIT
147+
create_commit_list $BEGIN_COMMIT $END_COMMIT $SKIP_BEGIN $SKIP_END
131148
checkout_inc_directories
132149
check_enum_history
133150
clean_temp_dir

meta/checkenumlock.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ rm -rf $TEMP_DIR
3737

3838
mkdir $TEMP_DIR
3939

40-
git --work-tree=$TEMP_DIR/ checkout origin/master inc experimental
40+
git --work-tree=$TEMP_DIR/ checkout origin/master inc experimental meta
4141

4242
echo "Checking for possible enum values shift (current branch vs origin/master) ..."
4343

4444
./checkheaders.pl -s ../inc/ $TEMP_DIR/inc/
4545

46+
./checkheaders.pl -s ../meta/ $TEMP_DIR/meta/
47+
48+
./checkheaders.pl -s ../experimental/ $TEMP_DIR/experimental/
49+
4650
rm -rf $TEMP_DIR

meta/checkheaders.pl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ sub GetEnums
104104

105105
for my $file (@files)
106106
{
107+
next if $file eq "saimetadata.h";
108+
107109
my $data = ReadHeaderFile("$dir/$file");
108110

109111
my %en = FilterEnums($data, "$dir/$file");
@@ -122,7 +124,21 @@ sub ConstructSource
122124

123125
my $source = "#include <stdio.h>\n";
124126

125-
$source .= "#include \"$dir/sai.h\"\n";
127+
$source .= "#include \"$dir/../inc/sai.h\"\n";
128+
129+
if( ! -e "$dir/sai.h") {
130+
131+
my @files = GetHeaderFiles $dir;
132+
133+
for my $file (@files)
134+
{
135+
if ($file =~ /\.h$/)
136+
{
137+
$source .= "#include \"$dir/$file\"\n";
138+
}
139+
}
140+
}
141+
126142
$source .="int main() { ";
127143

128144
for my $en (sort keys %enums)
@@ -149,7 +165,7 @@ sub GetValues
149165

150166
my ($fhb, $bin) = tempfile( SUFFIX => '.bin', UNLINK => 1 );
151167

152-
system("gcc $src -I. -I '$dir'/../experimental -I '$dir/../custom/' -I '$dir' -o $bin") == 0 or die "gcc failed! $!";
168+
system("gcc $src -I. -I '$dir'/../experimental -I '$dir/../custom/' -I '$dir/../inc/' -I '$dir' -o $bin") == 0 or die "gcc failed! $!";
153169

154170
close $fhs;
155171
close $fhb;

0 commit comments

Comments
 (0)