OpenCores
URL https://opencores.org/ocsvn/socgen/socgen/trunk

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [yp/] [create_yp] - Blame information for rev 130

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 117 jt_eaton
eval 'exec `which perl` -S $0 ${1+"$@"}'
2
   if 0;
3
 
4
#/**********************************************************************/
5
#/*                                                                    */
6
#/*             -------                                                */
7
#/*            /   SOC  \                                              */
8
#/*           /    GEN   \                                             */
9
#/*          /    TOOL    \                                            */
10
#/*          ==============                                            */
11
#/*          |            |                                            */
12
#/*          |____________|                                            */
13
#/*                                                                    */
14
#/*  Traverse a socgen project and link it                             */
15
#/*                                                                    */
16
#/*                                                                    */
17
#/*  Author(s):                                                        */
18
#/*      - John Eaton, jt_eaton@opencores.org                          */
19
#/*                                                                    */
20
#/**********************************************************************/
21
#/*                                                                    */
22
#/*    Copyright (C) <2010-2011>                */
23
#/*                                                                    */
24
#/*  This source file may be used and distributed without              */
25
#/*  restriction provided that this copyright statement is not         */
26
#/*  removed from the file and that any derivative work contains       */
27
#/*  the original copyright notice and the associated disclaimer.      */
28
#/*                                                                    */
29
#/*  This source file is free software; you can redistribute it        */
30
#/*  and/or modify it under the terms of the GNU Lesser General        */
31
#/*  Public License as published by the Free Software Foundation;      */
32
#/*  either version 2.1 of the License, or (at your option) any        */
33
#/*  later version.                                                    */
34
#/*                                                                    */
35
#/*  This source is distributed in the hope that it will be            */
36
#/*  useful, but WITHOUT ANY WARRANTY; without even the implied        */
37
#/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR           */
38
#/*  PURPOSE.  See the GNU Lesser General Public License for more      */
39
#/*  details.                                                          */
40
#/*                                                                    */
41
#/*  You should have received a copy of the GNU Lesser General         */
42
#/*  Public License along with this source; if not, download it        */
43
#/*  from http://www.opencores.org/lgpl.shtml                          */
44
#/*                                                                    */
45
#/**********************************************************************/
46
 
47
 
48
############################################################################
49
# General PERL config
50
############################################################################
51
use Getopt::Long;
52
use English;
53
use File::Basename;
54
use Cwd;
55
use XML::LibXML;
56
 
57
 
58
$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.
59
 
60
 
61
 
62
 
63
############################################################################
64
### Process the options
65
############################################################################
66
 
67
Getopt::Long::config("require_order", "prefix=-");
68
GetOptions("h","help"
69
) || die "(use '$program_name -h' for help)";
70
 
71
 
72
##############################################################################
73
## Help option
74
##############################################################################
75
if ( $opt_h or $opt_help  )
76
   {
77
   print "\n type create_yp\n";
78
   exit 1;
79
   }
80
 
81
 
82
##############################################################################
83
##
84
##############################################################################
85
 
86
my $home                     = cwd();
87
 
88 120 jt_eaton
 
89
 
90
 
91 130 jt_eaton
my $projects_dir    = $ARGV[0];
92
chomp($projects_dir);
93
$projects_dir = "/${projects_dir}";
94 120 jt_eaton
 
95 117 jt_eaton
 
96
 
97
 
98 130 jt_eaton
use BerkeleyDB;
99 117 jt_eaton
 
100
 
101 130 jt_eaton
$repo_db                  = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/repo.dbm',                  -Flags => DB_CREATE ) or die "Cannot open file: $!";
102
$component_db             = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/component.dbm',             -Flags => DB_CREATE ) or die "Cannot open file: $!";
103
$design_db                = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/design.dbm',                -Flags => DB_CREATE ) or die "Cannot open file: $!";
104
$busDefinition_db         = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/busDefinition.dbm',         -Flags => DB_CREATE ) or die "Cannot open file: $!";
105
$abstractionDefinition_db = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/abstractionDefinition.dbm', -Flags => DB_CREATE ) or die "Cannot open file: $!";
106
$libraryConfiguration_db  = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/libraryConfiguration.dbm',  -Flags => DB_CREATE ) or die "Cannot open file: $!";
107
$componentConfiguration_db  = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/componentConfiguration.dbm',  -Flags => DB_CREATE ) or die "Cannot open file: $!";
108 117 jt_eaton
 
109 130 jt_eaton
 
110
 
111
 
112
 
113
 
114
 
115
 
116 117 jt_eaton
 
117
#/*********************************************************************************************/
118
#/                                                                                            */
119
#/                                                                                            */
120
#/                                                                                            */
121
#/                                                                                            */
122
#/                                                                                            */
123
#/                                                                                            */
124
#/*********************************************************************************************/
125
 
126
my $parser = XML::LibXML->new();
127 130 jt_eaton
$root = "${home}${projects_dir}";
128 117 jt_eaton
&link_dir( "$root"  );
129
 
130
 
131
 
132
#/*********************************************************************************************/
133
#/                                                                                            */
134
#/                                                                                            */
135
#/                                                                                            */
136
#/                                                                                            */
137
#/                                                                                            */
138
#/                                                                                            */
139
#/*********************************************************************************************/
140
 
141
# recursively map directory information
142
 
143
sub link_dir {
144
    my $src  = shift;
145
    return unless( -e $src );
146
 
147
    if( -d $src )
148
        {
149
        my @contents = (  );
150
        opendir( DIR, $src );
151
        while( my $item = readdir( DIR ))
152
            {
153
            next if( $item eq '.' or $item eq '..'   or $item eq '.svn'    );
154
            push( @contents, $item );
155
            }
156
        closedir( DIR );
157
 
158
        # recurse on items in the directory
159
        foreach my $item ( @contents )
160
          {
161
          $_ = $item;
162 124 jt_eaton
          if(/(\S+)\.xml/)
163 117 jt_eaton
             {
164
             my $t_name                = $1;
165 120 jt_eaton
             $_ = $src;
166
             if(/${home}(\S+)/) { $t_local = $1; }
167 117 jt_eaton
 
168 124 jt_eaton
             my    $xml_file    = $parser->parse_file("${home}${t_local}/${t_name}.xml");
169
             eval {$xml_file->  findnodes('//socgen:componentConfiguration');};  #/ check for socgen namespace
170 125 jt_eaton
 
171 130 jt_eaton
 
172 124 jt_eaton
 
173
             if($@)             #/ Nope, must be spirit  namespace
174
               {
175
               foreach my $comp ($xml_file->findnodes('//spirit:component'))
176
                  {
177
                  $vendor   = $comp->findnodes('./spirit:vendor/text()')->to_literal ;
178
                  $library  = $comp->findnodes('./spirit:library/text()')->to_literal ;
179
                  $type     = "spirit:component";
180
                  $name     = $comp->findnodes('./spirit:name/text()')->to_literal ;
181
                  $version  = $comp->findnodes('./spirit:version/text()')->to_literal ;
182
                  }
183
 
184
 
185
               foreach my $design ($xml_file->findnodes('//spirit:design'))
186
                  {
187
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
188
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
189
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
190
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
191
                  $type     = "spirit:design";
192
 
193
                  }
194
 
195
 
196
 
197
 
198
 
199
               foreach my $design ($xml_file->findnodes('//spirit:abstractionDefinition'))
200
                  {
201
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
202
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
203
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
204
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
205
                  $type     = "spirit:abstractionDefinition";
206
                  }
207
 
208
 
209
               foreach my $design ($xml_file->findnodes('//spirit:busDefinition'))
210
                  {
211
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
212
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
213
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
214
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
215
                  $type     = "spirit:busDefinition";
216
                  }
217
               }
218
 
219
               else               #/  socgen  namespace
220
 
221
               {
222
 
223
 
224
               foreach my $design ($xml_file->findnodes('//socgen:componentConfiguration'))
225
                  {
226
                  $vendor   = $design->findnodes('./socgen:vendor/text()')->to_literal ;
227
                  $library  = $design->findnodes('./socgen:library/text()')->to_literal ;
228
                  $name     = $design->findnodes('./socgen:component/text()')->to_literal ;
229
                  $version  = "";
230
                  $type     = "socgen:componentConfiguration";
231
                  }
232
 
233
 
234
               foreach my $design ($xml_file->findnodes('//socgen:libraryConfiguration'))
235
                  {
236
                  $vendor   = $design->findnodes('./socgen:vendor/text()')->to_literal ;
237
                  $library  = $design->findnodes('./socgen:name/text()')->to_literal ;
238
                  $name     = "";
239
                  $version  = "";
240
                  $type     = "socgen:libraryConfiguration";
241
                  }
242 125 jt_eaton
 
243
               foreach my $comp ($xml_file->findnodes('//spirit:component'))
244
                  {
245
                  $vendor   = $comp->findnodes('./spirit:vendor/text()')->to_literal ;
246
                  $library  = $comp->findnodes('./spirit:library/text()')->to_literal ;
247
                  $type     = "spirit:component";
248
                  $name     = $comp->findnodes('./spirit:name/text()')->to_literal ;
249
                  $version  = $comp->findnodes('./spirit:version/text()')->to_literal ;
250
                  }
251
 
252
 
253
               foreach my $design ($xml_file->findnodes('//spirit:design'))
254
                  {
255
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
256
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
257
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
258
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
259
                  $type     = "spirit:design";
260
 
261
                  }
262
 
263
 
264
 
265
 
266
 
267
               foreach my $design ($xml_file->findnodes('//spirit:abstractionDefinition'))
268
                  {
269
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
270
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
271
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
272
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
273
                  $type     = "spirit:abstractionDefinition";
274
                  }
275
 
276
 
277
               foreach my $design ($xml_file->findnodes('//spirit:busDefinition'))
278
                  {
279
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
280
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
281
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
282
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
283
                  $type     = "spirit:busDefinition";
284
                  }
285
 
286
 
287
 
288 124 jt_eaton
               }
289 117 jt_eaton
 
290
 
291 124 jt_eaton
             $vendor_match = "/${vendor}/";
292
             $library_match = "/${library}/";
293
             $name_match = "/${name}/";
294
 
295
             $_ = $t_local;
296
             if(/\S+($vendor_match)(\S+)/)                     { $vendor_path      = $2; }
297
             else                                              { $vendor_path      = ""; }
298
             if(/\S+($library_match)(\S+)/)                    { $library_path     = $2; }
299
             else                                              { $library_path     = ""; }
300 130 jt_eaton
             if(/\S+($library_match)(\S+)($name_match)(\S+)/)  { $lib_comp_sep     = "/${2}/"; }
301
             else                                              { $lib_comp_sep     = "/"; }
302
             if(/(\S+)($name_match)(\S+)/)
303
               {
304
               $component_path   = "/${3}";
305
               $environment_path = $1;
306
               }
307
             else                                              { $component_path   = "/"; }
308 117 jt_eaton
 
309
 
310
 
311 120 jt_eaton
 
312 130 jt_eaton
 
313
               $V_L_N_V  = "${vendor}__${library}_${name}_${version}"    ;
314
 
315
 
316
 
317
             if($type eq "spirit:component")
318
               {
319
 
320
               my $V = "${vendor}"    ;
321
               my @repo_info  = ("vendor","$vendor","$vendor_path" );
322
               $repo_db->db_put( $V, join(':', @repo_info) );
323
 
324
 
325
               my $V_L = "${vendor}__${library}"    ;
326
               @repo_info  = ("library","$library","$library_path" );
327
               $repo_db->db_put( $V_L, join(':', @repo_info) );
328
 
329
 
330
 
331
               my $V_L_N = "${vendor}__${library}_${name}"    ;
332
               @repo_info  = ("component","$name","$lib_comp_sep" );
333
               $repo_db->db_put( $V_L_N, join(':', @repo_info) );
334
 
335
 
336
 
337
               my @comp_info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
338
               $component_db->db_put( $V_L_N_V, join(':', @comp_info) );
339
 
340
#               print "${vendor}__${library}_${name}_${version} \n";
341
#               print " .${t_local}/${t_name}.xml , ${component_path}                     \n  ";
342
 
343
 
344
               }
345
 
346
 
347
               $V_L_N_V  = "${vendor}__${library}_${name}_${version}"    ;
348
 
349
 
350
 
351
             if($type eq "spirit:design")
352
               {
353
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
354
               $design_db->db_put( $V_L_N_V, join(':', @info) );
355
               }
356
 
357
 
358
             elsif($type eq "spirit:abstractionDefinition")
359
               {
360
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
361
               $abstractionDefinition_db->db_put( $V_L_N_V, join(':', @info) );
362
               }
363
 
364
 
365
             elsif($type eq "spirit:busDefinition")
366
               {
367
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
368
               $busDefinition_db->db_put( $V_L_N_V, join(':', @info) );
369
               }
370
 
371
 
372
             if($type eq "socgen:libraryConfiguration")
373
               {
374
               $V_L  = "${vendor}__${library}"    ;
375
               @info  = (".${t_local}/${t_name}.xml" );
376
               $libraryConfiguration_db->db_put( $V_L, join(':', @info) );
377
               }
378
 
379
 
380
             if($type eq "socgen:componentConfiguration")
381
               {
382
               my $V_L_N = "${vendor}__${library}_${name}"    ;
383
               @info  = (".${t_local}/${t_name}.xml" );
384
               $componentConfiguration_db->db_put( $V_L_N, join(':', @info) );
385
               }
386
 
387
 
388
 
389
 
390
 
391
 
392
 
393
 
394 117 jt_eaton
             }
395
 
396
          &link_dir("$src/$item" );
397
          }
398
 
399
     }
400
 
401
}
402
 
403
 
404
 
405 130 jt_eaton
 
406
 
407
 
408
$repo_db->db_close();
409
$component_db->db_close();
410
$design_db->db_close();
411
$abstractionDefinition_db->db_close();
412
$busDefinition_db->db_close();
413
$libraryConfiguration_db->db_close();
414
$componentConfiguration_db->db_close();

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.