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

Subversion Repositories socgen

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

Compare with Previous | Blame | View Log

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

#/****************************************************************************/
#/*                                                                          */
#/*   SOCGEN Design for Reuse toolset                                        */
#/*                                                                          */
#/*   Version 1.0.0                                                          */
#/*                                                                          */
#/*   Author(s):                                                             */
#/*      - John Eaton, z3qmtr45@gmail.com                                    */
#/*                                                                          */
#/****************************************************************************/
#/*                                                                          */
#/*                                                                          */
#/*             Copyright 2016 John T Eaton                                  */ 
#/*                                                                          */
#/* Licensed under the Apache License, Version 2.0 (the "License");          */
#/* you may not use this file except in compliance with the License.         */
#/* You may obtain a copy of the License at                                  */
#/*                                                                          */
#/*    http://www.apache.org/licenses/LICENSE-2.0                            */
#/*                                                                          */
#/* Unless required by applicable law or agreed to in writing, software      */
#/* distributed under the License is distributed on an "AS IS" BASIS,        */
#/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
#/* See the License for the specific language governing permissions and      */
#/* limitations under the License.                                           */
#/*                                                                          */
#/*                                                                          */
#/****************************************************************************/

############################################################################
# General PERL config
############################################################################
use Getopt::Long;
use English;
use File::Basename;
use Cwd;
use XML::LibXML;
use lib './tools';
use sys::lib;
use BerkeleyDB;


$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  $path  \n";
   exit 1;
   }


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

my $home           = cwd();
my $path           = $ARGV[0];

mkdir $path,0755   unless( -e $path );


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



my $parser = XML::LibXML->new();



my    $workspace    = $parser->parse_file("${home}/workspace.xml"); 









my @repos =();
my $repo;


foreach my $repo ($workspace->findnodes('//socgen:workspace/socgen:external/socgen:repo')) 
                  {
                  my $repo_name  = $repo->findnodes('./socgen:name/text()')->to_literal ;
                  my $repo_path  = $repo->findnodes('./socgen:path/text()')->to_literal ;
                  print "Linking $repo_name   $repo_path \n";
                  if(-e  $repo_name)
                   {
                   print "Removing $repo_name  \n";
                   my $cmd = "rm -r $repo_name  \n";
                   if(system($cmd)){};
                   }

                  my $cmd = "mkdir $repo_name ;lndir -silent  $repo_path  $repo_name;";
                  if(system($cmd)){};



                  }




foreach my $repo ($workspace->findnodes('//socgen:workspace/socgen:repos/socgen:repo')) 
                  {
                  my $repo_name  = $repo->findnodes('./socgen:name/text()')->to_literal ;
                  push  @repos,$repo_name;                   
                  }

my $repos_dir ;



foreach $repos_dir (@repos)
{
print "Project_dir  $repos_dir  \n";




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


$root = "${home}${repos_dir}";
&link_dir( "$root","$repos_dir"  );



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

# recursively map directory information 

sub link_dir {
    my $src  = shift;
    my $repos_dir  = 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; }
      #       print "creat_yp: Parsing ${home}${t_local}/${t_name}.xml \n";
             
             my    $xml_file    = $parser->parse_file("${home}${t_local}/${t_name}.xml"); 

#             print "creat_yp: Parsed \n";

            if(${t_name} eq "libraryCfg"  )
               {
               foreach my $design ($xml_file->findnodes('//socgen:libraryConfiguration')) 
                  {
#                 print "creat_yp: Parsed socgen \n";
                  $vendor   = $design->findnodes('./socgen:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./socgen:name/text()')->to_literal ;
                  $name     = "";
                  $version  = "";
                  $type     = "socgen:libraryConfiguration";
                  }
                }
             elsif(${t_name} eq "componentCfg"  )
              {
              foreach my $design ($xml_file->findnodes('//socgen:componentConfiguration')) 
                  {
#                                 print "creat_yp: Parsed socgen \n";
                  $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";
                  }
              } 

             else
             {
#                                 print "creat_yp: Parsing spirit \n";
               foreach my $comp ($xml_file->findnodes('//ipxact:component')) 
                  {
#                                                 print "creat_yp: Parsed spirit \n";
                  $vendor   = $comp->findnodes('./ipxact:vendor/text()')->to_literal ;
                  $library  = $comp->findnodes('./ipxact:library/text()')->to_literal ;
                  $type     = "ipxact:component";
                  $name     = $comp->findnodes('./ipxact:name/text()')->to_literal ;
                  $version  = $comp->findnodes('./ipxact:version/text()')->to_literal ;
                  }
               
               
               foreach my $design ($xml_file->findnodes('//ipxact:design')) 
                  {
                  $vendor   = $design->findnodes('./ipxact:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./ipxact:library/text()')->to_literal ;
                  $name     = $design->findnodes('./ipxact:name/text()')->to_literal ;
                  $version  = $design->findnodes('./ipxact:version/text()')->to_literal ;
                  $type     = "ipxact:design";
                  }


               foreach my $design ($xml_file->findnodes('//ipxact:designConfiguration')) 
                  {
                  $vendor   = $design->findnodes('./ipxact:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./ipxact:library/text()')->to_literal ;
                  $name     = $design->findnodes('./ipxact:name/text()')->to_literal ;
                  $version  = $design->findnodes('./ipxact:version/text()')->to_literal ;
                  $type     = "ipxact:designConfiguration";
                  }

                                    
               
               foreach my $design ($xml_file->findnodes('//ipxact:abstractionDefinition')) 
                  {
                  $vendor   = $design->findnodes('./ipxact:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./ipxact:library/text()')->to_literal ;
                  $name     = $design->findnodes('./ipxact:name/text()')->to_literal ;
                  $version  = $design->findnodes('./ipxact:version/text()')->to_literal ;
                  $type     = "ipxact:abstractionDefinition";
                  }
               
               
               foreach my $design ($xml_file->findnodes('//ipxact:busDefinition')) 
                  {
                  $vendor   = $design->findnodes('./ipxact:vendor/text()')->to_literal ;
                  $library  = $design->findnodes('./ipxact:library/text()')->to_literal ;
                  $name     = $design->findnodes('./ipxact:name/text()')->to_literal ;
                  $version  = $design->findnodes('./ipxact:version/text()')->to_literal ;
                  $type     = "ipxact: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   = "/"; }



             
#               print "${vendor}__${library}_${name}_${version}   $type  ---  $t_local  $library_match  $lib_comp_sep  $name_match    \n";
               $V_L_N_V  = "${vendor}__${library}_${name}_${version}"    ;



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

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


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



               my $V_L_N = "${vendor}__${library}_${name}"    ;
               @repo_info  = ("component","$name","$lib_comp_sep","$repos_dir" );
               $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 " .${t_local}/${t_name}.xml , ${component_path}                     \n  ";


               }


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



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

             elsif($type eq "ipxact:designConfiguration")
               {
               @info  = (".${t_local}/${t_name}.xml","${component_path}","${version}","${name}","${library}","${vendor}"         );
               $designConfiguration_db->db_put( $V_L_N_V, join(':', @info) );
               }


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


             elsif($type eq "ipxact: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) );
               }


my $uplift_data;
$repo_db->db_get("log_name", $uplift_data );




             }

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

}



}


$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();

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.