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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [yp/] [create_yp] - Rev 130

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

eval 'exec `which perl` -S $0 ${1+"$@"}'
   if 0;

#/**********************************************************************/
#/*                                                                    */
#/*             -------                                                */
#/*            /   SOC  \                                              */
#/*           /    GEN   \                                             */
#/*          /    TOOL    \                                            */
#/*          ==============                                            */
#/*          |            |                                            */
#/*          |____________|                                            */
#/*                                                                    */
#/*  Traverse a socgen project and link it                             */
#/*                                                                    */
#/*                                                                    */
#/*  Author(s):                                                        */
#/*      - John Eaton, jt_eaton@opencores.org                          */
#/*                                                                    */
#/**********************************************************************/
#/*                                                                    */
#/*    Copyright (C) <2010-2011>  <Ouabache Design Works>              */
#/*                                                                    */
#/*  This source file may be used and distributed without              */
#/*  restriction provided that this copyright statement is not         */
#/*  removed from the file and that any derivative work contains       */
#/*  the original copyright notice and the associated disclaimer.      */
#/*                                                                    */
#/*  This source file is free software; you can redistribute it        */
#/*  and/or modify it under the terms of the GNU Lesser General        */
#/*  Public License as published by the Free Software Foundation;      */
#/*  either version 2.1 of the License, or (at your option) any        */
#/*  later version.                                                    */
#/*                                                                    */
#/*  This source is distributed in the hope that it will be            */
#/*  useful, but WITHOUT ANY WARRANTY; without even the implied        */
#/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR           */
#/*  PURPOSE.  See the GNU Lesser General Public License for more      */
#/*  details.                                                          */
#/*                                                                    */
#/*  You should have received a copy of the GNU Lesser General         */
#/*  Public License along with this source; if not, download it        */
#/*  from http://www.opencores.org/lgpl.shtml                          */
#/*                                                                    */
#/**********************************************************************/


############################################################################
# General PERL config
############################################################################
use Getopt::Long;
use English;
use File::Basename;
use Cwd;
use XML::LibXML;


$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.




############################################################################
### Process the options
############################################################################

Getopt::Long::config("require_order", "prefix=-");
GetOptions("h","help"
) || die "(use '$program_name -h' for help)";


##############################################################################
## Help option
##############################################################################
if ( $opt_h or $opt_help  ) 
   { 
   print "\n type create_yp\n";
   exit 1;
   }


##############################################################################
## 
##############################################################################

my $home                     = cwd();




my $projects_dir    = $ARGV[0];
chomp($projects_dir);
$projects_dir = "/${projects_dir}";




use BerkeleyDB;


$repo_db                  = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/repo.dbm',                  -Flags => DB_CREATE ) or die "Cannot open file: $!";
$component_db             = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/component.dbm',             -Flags => DB_CREATE ) or die "Cannot open file: $!";
$design_db                = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/design.dbm',                -Flags => DB_CREATE ) or die "Cannot open file: $!";
$busDefinition_db         = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/busDefinition.dbm',         -Flags => DB_CREATE ) or die "Cannot open file: $!";
$abstractionDefinition_db = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/abstractionDefinition.dbm', -Flags => DB_CREATE ) or die "Cannot open file: $!";
$libraryConfiguration_db  = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/libraryConfiguration.dbm',  -Flags => DB_CREATE ) or die "Cannot open file: $!";
$componentConfiguration_db  = new BerkeleyDB::Hash( -Filename => 'tools/yp/Berkeley/componentConfiguration.dbm',  -Flags => DB_CREATE ) or die "Cannot open file: $!";








   
#/*********************************************************************************************/
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/

my $parser = XML::LibXML->new();
$root = "${home}${projects_dir}";
&link_dir( "$root"  );



#/*********************************************************************************************/
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/

# recursively map directory information 

sub link_dir {
    my $src  = shift;
    return unless( -e $src );

    if( -d $src ) 
        {
        my @contents = (  );
        opendir( DIR, $src );
        while( my $item = readdir( DIR )) 
            {
            next if( $item eq '.' or $item eq '..'   or $item eq '.svn'    );
            push( @contents, $item );
            }
        closedir( DIR );
 
        # recurse on items in the directory
        foreach my $item ( @contents )          
          {
          $_ = $item;
          if(/(\S+)\.xml/) 
             { 
             my $t_name                = $1;
             $_ = $src;
             if(/${home}(\S+)/) { $t_local = $1; }

             my    $xml_file    = $parser->parse_file("${home}${t_local}/${t_name}.xml"); 
             eval {$xml_file->  findnodes('//socgen:componentConfiguration');};  #/ check for socgen namespace


 
             if($@)             #/ Nope, must be spirit  namespace
               {
               foreach my $comp ($xml_file->findnodes('//spirit:component')) 
                  {
                  $vendor   = $comp->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $comp->findnodes('./spirit:library/text()')->to_literal ;
                  $type     = "spirit:component";
                  $name     = $comp->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $comp->findnodes('./spirit:version/text()')->to_literal ;
                  }
               
               
               foreach my $design ($xml_file->findnodes('//spirit:design')) 
                  {
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
                  $type     = "spirit:design";
               
                  }
               
               
               
               
               
               foreach my $design ($xml_file->findnodes('//spirit:abstractionDefinition')) 
                  {
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
                  $type     = "spirit:abstractionDefinition";
                  }
               
               
               foreach my $design ($xml_file->findnodes('//spirit:busDefinition')) 
                  {
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
                  $type     = "spirit:busDefinition";
                  }
               }
               
               else               #/  socgen  namespace
               
               {
               
               
               foreach my $design ($xml_file->findnodes('//socgen:componentConfiguration')) 
                  {
                  $vendor   = $design->findnodes('./socgen:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./socgen:library/text()')->to_literal ;
                  $name     = $design->findnodes('./socgen:component/text()')->to_literal ;
                  $version  = "";
                  $type     = "socgen:componentConfiguration";
                  }
               
               
               foreach my $design ($xml_file->findnodes('//socgen:libraryConfiguration')) 
                  {
                  $vendor   = $design->findnodes('./socgen:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./socgen:name/text()')->to_literal ;
                  $name     = "";
                  $version  = "";
                  $type     = "socgen:libraryConfiguration";
                  }

               foreach my $comp ($xml_file->findnodes('//spirit:component')) 
                  {
                  $vendor   = $comp->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $comp->findnodes('./spirit:library/text()')->to_literal ;
                  $type     = "spirit:component";
                  $name     = $comp->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $comp->findnodes('./spirit:version/text()')->to_literal ;
                  }
               
               
               foreach my $design ($xml_file->findnodes('//spirit:design')) 
                  {
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
                  $type     = "spirit:design";
               
                  }
               
               
               
               
               
               foreach my $design ($xml_file->findnodes('//spirit:abstractionDefinition')) 
                  {
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
                  $type     = "spirit:abstractionDefinition";
                  }
               
               
               foreach my $design ($xml_file->findnodes('//spirit:busDefinition')) 
                  {
                  $vendor   = $design->findnodes('./spirit:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./spirit:library/text()')->to_literal ;
                  $name     = $design->findnodes('./spirit:name/text()')->to_literal ;
                  $version  = $design->findnodes('./spirit:version/text()')->to_literal ;
                  $type     = "spirit:busDefinition";
                  }



               } 


             $vendor_match = "/${vendor}/";
             $library_match = "/${library}/";
             $name_match = "/${name}/";
   
             $_ = $t_local;
             if(/\S+($vendor_match)(\S+)/)                     { $vendor_path      = $2; }
             else                                              { $vendor_path      = ""; }
             if(/\S+($library_match)(\S+)/)                    { $library_path     = $2; }
             else                                              { $library_path     = ""; }
             if(/\S+($library_match)(\S+)($name_match)(\S+)/)  { $lib_comp_sep     = "/${2}/"; }
             else                                              { $lib_comp_sep     = "/"; }
             if(/(\S+)($name_match)(\S+)/)                       
               { 
               $component_path   = "/${3}"; 
               $environment_path = $1;
               }
             else                                              { $component_path   = "/"; }





               $V_L_N_V  = "${vendor}__${library}_${name}_${version}"    ;



             if($type eq "spirit:component")
               {

               my $V = "${vendor}"    ;
               my @repo_info  = ("vendor","$vendor","$vendor_path" );
               $repo_db->db_put( $V, join(':', @repo_info) );


               my $V_L = "${vendor}__${library}"    ;
               @repo_info  = ("library","$library","$library_path" );
               $repo_db->db_put( $V_L, join(':', @repo_info) );



               my $V_L_N = "${vendor}__${library}_${name}"    ;
               @repo_info  = ("component","$name","$lib_comp_sep" );
               $repo_db->db_put( $V_L_N, join(':', @repo_info) );



               my @comp_info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
               $component_db->db_put( $V_L_N_V, join(':', @comp_info) );

#               print "${vendor}__${library}_${name}_${version} \n";
#               print " .${t_local}/${t_name}.xml , ${component_path}                     \n  ";


               }


               $V_L_N_V  = "${vendor}__${library}_${name}_${version}"    ;



             if($type eq "spirit:design")
               {
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
               $design_db->db_put( $V_L_N_V, join(':', @info) );
               }


             elsif($type eq "spirit:abstractionDefinition")
               {
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
               $abstractionDefinition_db->db_put( $V_L_N_V, join(':', @info) );
               }


             elsif($type eq "spirit:busDefinition")
               {
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}" );
               $busDefinition_db->db_put( $V_L_N_V, join(':', @info) );
               }


             if($type eq "socgen:libraryConfiguration")
               {
               $V_L  = "${vendor}__${library}"    ;
               @info  = (".${t_local}/${t_name}.xml" );
               $libraryConfiguration_db->db_put( $V_L, join(':', @info) );
               }


             if($type eq "socgen:componentConfiguration")
               {
               my $V_L_N = "${vendor}__${library}_${name}"    ;
               @info  = (".${t_local}/${t_name}.xml" );
               $componentConfiguration_db->db_put( $V_L_N, join(':', @info) );
               }








             }

          &link_dir("$src/$item" );
          } 
      
     }

}






$repo_db->db_close();
$component_db->db_close();
$design_db->db_close();
$abstractionDefinition_db->db_close();
$busDefinition_db->db_close();
$libraryConfiguration_db->db_close();
$componentConfiguration_db->db_close();

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

powered by: WebSVN 2.1.0

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