sysdeftools/rootsysdef.pl
branchHighFidelityModel
changeset 312 9527bd30de64
parent 206 eccc98839441
equal deleted inserted replaced
311:e9d0240c3e66 312:9527bd30de64
    36 my %additional;
    36 my %additional;
    37 my %add;
    37 my %add;
    38 my %newNs;
    38 my %newNs;
    39 my $warning = "Error";
    39 my $warning = "Error";
    40 my $placeholders=0;
    40 my $placeholders=0;
       
    41 my $sysmodelname;
    41 
    42 
    42 my @tdOrder =("hb","se", "lo","dc", "vc" , "pr", "dm", "de", "mm", "ma" , "ui",  "rt", "to" );
    43 my @tdOrder =("hb","se", "lo","dc", "vc" , "pr", "dm", "de", "mm", "ma" , "ui",  "rt", "to" );
    43 
    44 
    44 sub help
    45 sub help
    45 	{
    46 	{
    52 		"  -output [file]\tspecifies the file to save the output to. If set, all hrefs will set to be relative to this location. If not specified all href will be absolute file URIs and this will write to stdout\n\n",
    53 		"  -output [file]\tspecifies the file to save the output to. If set, all hrefs will set to be relative to this location. If not specified all href will be absolute file URIs and this will write to stdout\n\n",
    53 
    54 
    54 		"  -w [Note|Warning|Error]\tspecifies prefix text for any notifications. Defautls to Error\n\n",
    55 		"  -w [Note|Warning|Error]\tspecifies prefix text for any notifications. Defautls to Error\n\n",
    55 		"  -root [dir]\tspecifies the root directory of the filesystem. All globbing will be done relative to this path\n\n",
    56 		"  -root [dir]\tspecifies the root directory of the filesystem. All globbing will be done relative to this path\n\n",
    56 
    57 
    57 		"  -glob [wildcard path]\tThe wildcard search to look for pkgdef files. eg  \"\*\*\package_definition.xml\". Can specify any number of these.\n",
    58 		"  -glob [wildcard path]\tThe wildcard search to look for pkgdef files. eg  \"\\*\\*\package_definition.xml\". Can specify any number of these.\n",
    58 		"  -placeholders [bool]\tif set, all packages not found in the template will be left in as empty placeholders\n";
    59 		"  -placeholders [bool]\tif set, all packages not found in the template will be left in as empty placeholders\n";
       
    60 		"  -name [text]\tthe name in <systemModel> to use for the generated root sysdef. If not present, this will use the name from the templat\n";
    59 	exit(1);
    61 	exit(1);
    60 	}
    62 	}
    61 
    63 
    62 GetOptions
    64 GetOptions
    63 	(
    65 	(
    64 	 'path=s' => \$path,
    66 	 'path=s' => \$path,
       
    67 	 'name=s' => \$sysmodelname,
    65 	'output=s' => \$output,
    68 	'output=s' => \$output,
    66 	'w=s' => \$warning,
    69 	'w=s' => \$warning,
    67 	'root=s' => \@searchroots,
    70 	'root=s' => \@searchroots,
    68 	'glob=s' => \@searchpaths,
    71 	'glob=s' => \@searchpaths,
    69 	'placeholders=s' => \$placeholders
    72 	'placeholders=s' => \$placeholders
    81 # glob = -glob "\*\*\package_definition.xml"
    84 # glob = -glob "\*\*\package_definition.xml"
    82 
    85 
    83 #Example command lines:
    86 #Example command lines:
    84 #rootsysdef.pl -root F:\sftest\mcl\sf  -glob "\*\*\package_definition.xml"  -output  F:\sftest\mcl\build\system_definition.sf.xml   F:\sftest\mcl\sf\os\deviceplatformrelease\foundation_system\system_model\system_definition.xml
    87 #rootsysdef.pl -root F:\sftest\mcl\sf  -glob "\*\*\package_definition.xml"  -output  F:\sftest\mcl\build\system_definition.sf.xml   F:\sftest\mcl\sf\os\deviceplatformrelease\foundation_system\system_model\system_definition.xml
    85 #rootsysdef.pl -root F:\sftest\mcl\sf  -glob "\*\*\*\*\package_definition.xml"  -output  F:\sftest\mcl\build\system_definition.mine.xml   F:\sftest\mcl\sf\os\deviceplatformrelease\foundation_system\system_model\system_definition.xml
    88 #rootsysdef.pl -root F:\sftest\mcl\sf  -glob "\*\*\*\*\package_definition.xml"  -output  F:\sftest\mcl\build\system_definition.mine.xml   F:\sftest\mcl\sf\os\deviceplatformrelease\foundation_system\system_model\system_definition.xml
    86 if(!scalar $ARGV) {&help()};
    89 if(!scalar @ARGV && !scalar @searchpaths) {&help()};
    87 
    90 
    88 
    91 
    89 my %replacefile;
    92 my %replacefile;
    90 my $dir;
    93 my $dir;
    91 foreach(@searchpaths)
    94 foreach(@searchpaths)
   100 		$replacefile{&abspath($file)}=$map;
   103 		$replacefile{&abspath($file)}=$map;
   101 		$add{&abspath($file)}=1;
   104 		$add{&abspath($file)}=1;
   102 		}
   105 		}
   103 	}
   106 	}
   104 
   107 
   105 my $sysdef = &abspath(shift);	# resolve the location of the root sysdef
   108 my $parser = new XML::DOM::Parser;
   106 
   109 my $sysdef;
   107 
   110 my %rootmap;
   108 # rootmap is a mapping from the filesystem to the paths in the doc
   111 my  $sysdefdoc;
   109 my %rootmap = &rootMap($path,$sysdef);	
   112 if(scalar @ARGV)
       
   113 	{
       
   114 	$sysdef = &abspath(shift);	# resolve the location of the root sysdef
       
   115 
       
   116 	# rootmap is a mapping from the filesystem to the paths in the doc
       
   117 	%rootmap = &rootMap($path,$sysdef);	
       
   118 
       
   119 	$sysdefdoc = $parser->parsefile ($sysdef);
       
   120 	}
       
   121 else 
       
   122 	{
       
   123 	$sysdefdoc = $parser->parse('<SystemDefinition schema="3.0.1"><systemModel name="System Model"/></SystemDefinition>');
       
   124 	}
       
   125 
   110 my %nsmap;
   126 my %nsmap;
   111 my %urimap;
   127 my %urimap;
   112 
       
   113 
       
   114 
       
   115 my $parser = new XML::DOM::Parser;
       
   116 my   $sysdefdoc = $parser->parsefile ($sysdef);
       
   117 
   128 
   118 my $mapmeta;
   129 my $mapmeta;
   119 my $modpath;
   130 my $modpath;
   120 if($output eq '')
   131 if($output eq '')
   121 	{ #figure out mapping path
   132 	{ #figure out mapping path
   366 			}
   377 			}
   367 		}
   378 		}
   368 	elsif($tag eq 'systemModel' && $mapmeta)
   379 	elsif($tag eq 'systemModel' && $mapmeta)
   369 		{ # need absolute paths for all links
   380 		{ # need absolute paths for all links
   370 		$node->insertBefore ($mapmeta,$node->getFirstChild);
   381 		$node->insertBefore ($mapmeta,$node->getFirstChild);
       
   382 		$sysmodelname eq '' || $node->setAttribute('name',$sysmodelname);
   371 		}
   383 		}
   372 	elsif($tag=~/^(SystemDefinition|systemModel)$/ )
   384 	elsif($tag=~/^(SystemDefinition|systemModel)$/ )
   373 		{
   385 		{
       
   386 		($sysmodelname ne '' && $tag eq 'systemModel') && $node->setAttribute('name',$sysmodelname);
   374 		}
   387 		}
   375 	elsif($tag eq 'unit')
   388 	elsif($tag eq 'unit')
   376 		{
   389 		{
   377 		foreach my $atr ('bldFile','mrp','base','proFile')
   390 		foreach my $atr ('bldFile','mrp','base','proFile')
   378 			{
   391 			{