comparison g23m/system/busyb/tools/gen_optionSet.pl @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 #!perl -w
2 use strict;
3
4 # import some modules
5 use File::Spec;
6
7 # define global variables
8 my $inputDir=$ARGV[0];
9 my $outOptionSetFile=$ARGV[1];
10 my $pathSetDir=$ARGV[2];
11 my $cfgFilesDir=$ARGV[3];
12
13 my %Symbols;
14 my @AoA_Pathes;
15 my %Conditions;
16
17 if ($#ARGV < 0) {
18 print "usage: gen_optionSet <inputDir> <outputFile> <pathSetDir> <cfgFilesDir>\n";
19 print "example: gen_optionSet busyb_integration busyb_integration/osFragment.xml x:/g23m/system/busyb x:/g23m/__out__/ssa_config\n";
20 exit;
21 }
22
23 # Find the target set files
24 #
25 my @osFiles = glob("$inputDir/*.os");
26 $#osFiles >= 0 || die "No *.os files found\n";
27
28 # open the output files
29 #
30 open (OUT,">$outOptionSetFile")||die "can't open $outOptionSetFile \n";
31
32
33 foreach (@osFiles) {
34 my $condition = calcConditionFromFileName($_);
35
36 my $condString = $_;
37 $condString =~ /((\w|-)+)\.os/;
38 $condString = "config_$1";
39
40 # open the input file
41 #
42 open (IN,"<$_")||die "can't open $_ \n";
43
44 # read the input file
45 #
46 my $line;
47 while(defined($line = <IN>))
48 {
49 # remove trailing \n
50 chomp($line);
51 if ($line =~ /^\[(\w+)\]\s*/) {
52 my @dirNames = split(/\s+/,$');
53 foreach (@dirNames) {
54 my $dirName = calcRelativePathFromPathset ($_, $pathSetDir);
55 $Symbols{$1} .= "<condValue path=\"$dirName\" require=\"$condition\"/>\n";
56 }
57 }
58 }
59 $Conditions{$condition} = $condString;
60 }
61
62
63
64
65
66 # print the optionSet fragment
67 #
68 print OUT "<!-- This is a generated file! Do not change ! -->\n\n";
69 print OUT "<!-- It's output is based on the information in the following files:\n";
70 foreach (@osFiles) {
71 print OUT "\t$_\n";
72 }
73 print OUT "\n<!-- All of it must be placed somewhere in a optionSet document! -->\n\n\n";
74
75
76 #print OUT "<optionDef description=\"auto generated options - SSA_WCP_INCLUDES\" name=\"SSA_WCP_INCLUDES\">\n";
77 #print OUT "<condOption name=\"include\">\n";
78 #foreach (sort(keys (%Symbols))) {
79 # print OUT "<condValue valRef=\"$_.include\"/>\n";
80 #}
81 #print OUT "</condOption></optionDef>\n";
82
83 print OUT "<optionDef description=\"auto generated options - CFG_INCLUDES\" name=\"CFG_INCLUDES\">\n";
84 print OUT "<condOption name=\"include\">\n";
85 foreach (keys (%Conditions)) {
86 my $path = calcRelativePathFromPathset($cfgFilesDir, $pathSetDir) . "\\" . $Conditions{$_};
87 print OUT "<condValue path=\"$path\" require=\"$_\"/>\n";
88 }
89 print OUT "</condOption></optionDef>\n\n";
90
91
92 foreach (sort(keys (%Symbols))) {
93 print OUT "<optionDef description=\"auto generated options - $_\" name=\"$_\">\n";
94 print OUT "<condOption name=\"include\">\n";
95 print OUT "$Symbols{$_}";
96 print OUT "</condOption></optionDef>\n\n";
97 }
98
99
100 # close the files
101 #
102 close IN;
103 close OUT;
104
105
106 ###########################################
107 # calculate the condition from the filename
108 # make aaa==1 &#38 bbb==2 from aaa1_bbb2.ts
109 #
110 sub calcConditionFromFileName
111 {
112 my $condition = "";
113 my @cond;
114 my $i = 0;
115
116 # remove directory part
117 my ($drive,$directories,$file);
118 ($drive,$directories,$file) = File::Spec->splitpath($_[0]);
119
120 # now remove file extension
121 $file =~ /\.\w*/;
122
123 # now split the name into sub conditions e.g. aaa1 bbb2
124 @cond = split(/_/,$`);
125
126 foreach (@cond) {
127 while (s/([a-zA-Z0-9]+)-(\d+)//) {
128 $condition = $condition . "(" . $1 . "==" . $2 .")";
129 defined($cond[++$i]) && ($condition = $condition . " &#38;&#38; ");
130 }
131 }
132 $condition =~ s/ &#38;&#38; $//;
133 return $condition;
134 }
135 ###########################################
136
137 ########################################################
138 # correct obscure behavior of File::Spec->abs2rel,
139 # which inserts a drive letter befor a relative path !!!
140 #
141 sub calcRelativePathFromPathset
142 {
143 my ($drive,$directories,$file);
144
145 ($drive,$directories,$file) = File::Spec->splitpath( File::Spec->abs2rel ($_[0], $_[1]) );
146
147 return File::Spec->catpath("",$directories,$file);
148 }
149 ########################################################