# HG changeset patch # User Bob Rosenberg # Date 1277200797 -3600 # Node ID 9527bd30de645ca7065fcd808d7b9182fbf2549e # Parent e9d0240c3e6669232e18c69f9d6328ed373a5eaa updates to validation scripts and bugfixes for rootsysdef diff -r e9d0240c3e66 -r 9527bd30de64 sysdeftools/rootsysdef.pl --- a/sysdeftools/rootsysdef.pl Fri Jun 18 09:49:13 2010 +0100 +++ b/sysdeftools/rootsysdef.pl Tue Jun 22 10:59:57 2010 +0100 @@ -38,6 +38,7 @@ my %newNs; my $warning = "Error"; my $placeholders=0; +my $sysmodelname; my @tdOrder =("hb","se", "lo","dc", "vc" , "pr", "dm", "de", "mm", "ma" , "ui", "rt", "to" ); @@ -54,14 +55,16 @@ " -w [Note|Warning|Error]\tspecifies prefix text for any notifications. Defautls to Error\n\n", " -root [dir]\tspecifies the root directory of the filesystem. All globbing will be done relative to this path\n\n", - " -glob [wildcard path]\tThe wildcard search to look for pkgdef files. eg \"\*\*\package_definition.xml\". Can specify any number of these.\n", + " -glob [wildcard path]\tThe wildcard search to look for pkgdef files. eg \"\\*\\*\package_definition.xml\". Can specify any number of these.\n", " -placeholders [bool]\tif set, all packages not found in the template will be left in as empty placeholders\n"; + " -name [text]\tthe name in to use for the generated root sysdef. If not present, this will use the name from the templat\n"; exit(1); } GetOptions ( 'path=s' => \$path, + 'name=s' => \$sysmodelname, 'output=s' => \$output, 'w=s' => \$warning, 'root=s' => \@searchroots, @@ -83,7 +86,7 @@ #Example command lines: #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 #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 -if(!scalar $ARGV) {&help()}; +if(!scalar @ARGV && !scalar @searchpaths) {&help()}; my %replacefile; @@ -102,19 +105,27 @@ } } -my $sysdef = &abspath(shift); # resolve the location of the root sysdef - +my $parser = new XML::DOM::Parser; +my $sysdef; +my %rootmap; +my $sysdefdoc; +if(scalar @ARGV) + { + $sysdef = &abspath(shift); # resolve the location of the root sysdef -# rootmap is a mapping from the filesystem to the paths in the doc -my %rootmap = &rootMap($path,$sysdef); + # rootmap is a mapping from the filesystem to the paths in the doc + %rootmap = &rootMap($path,$sysdef); + + $sysdefdoc = $parser->parsefile ($sysdef); + } +else + { + $sysdefdoc = $parser->parse(''); + } + my %nsmap; my %urimap; - - -my $parser = new XML::DOM::Parser; -my $sysdefdoc = $parser->parsefile ($sysdef); - my $mapmeta; my $modpath; if($output eq '') @@ -368,9 +379,11 @@ elsif($tag eq 'systemModel' && $mapmeta) { # need absolute paths for all links $node->insertBefore ($mapmeta,$node->getFirstChild); + $sysmodelname eq '' || $node->setAttribute('name',$sysmodelname); } elsif($tag=~/^(SystemDefinition|systemModel)$/ ) { + ($sysmodelname ne '' && $tag eq 'systemModel') && $node->setAttribute('name',$sysmodelname); } elsif($tag eq 'unit') { diff -r e9d0240c3e66 -r 9527bd30de64 sysdeftools/validate/checklinks.pl --- a/sysdeftools/validate/checklinks.pl Fri Jun 18 09:49:13 2010 +0100 +++ b/sysdeftools/validate/checklinks.pl Tue Jun 22 10:59:57 2010 +0100 @@ -81,7 +81,14 @@ my %urimap; my $parser = new XML::DOM::Parser; -my $sysdefdoc = $parser->parsefile ($sysdef); +my $sysdefdoc; +eval { + $sysdefdoc = $parser->parsefile ($sysdef); +}; +if(!$sysdefdoc) { + die "ERROR: could not open $sysdef\n"; +} + my $maxschema = $sysdefdoc->getDocumentElement()->getAttribute('schema'); # don't check value, just store it. @@ -212,6 +219,7 @@ if($link ne '') { my $ok = 0; + my $trylink; if($link && !($link=~/^\//)) { $link= &abspath(File::Basename::dirname($file)."/$link"); @@ -231,7 +239,7 @@ { foreach my $a (keys %unitmap) { if($a eq substr($link,0,length($a))) { - my $trylink = $unitmap{$a}.substr($link,length($a)); + $trylink = $unitmap{$a}.substr($link,length($a)); if(-e "$trylink$ext") { $ok=1; $link = $trylink; @@ -242,7 +250,7 @@ } if(!$ok) { - print "Error: $atr not found in $link$filter\n"; + print "Error: $atr not found in ",($trylink ne '') ? $trylink : $link,"$filter\n"; } } } @@ -310,24 +318,20 @@ my $file = shift; my $getfromfile = &localfile($file); $getfromfile eq '' && return; # already raised warning, no need to repeat - my $doc = $parser->parsefile ($getfromfile); + my $doc; + eval { + $doc = $parser->parsefile ($getfromfile); + }; + if(!$doc) { + print "ERROR: could not open $getfromfile\n"; + return; + } my $item =&firstElement($doc->getDocumentElement); $item || die "badly formatted $file"; - &fixIDs($item); - my %up = &atts($node); - my %down = &atts($item); - $up{'id'} eq $down{'id'} || die "$up{id} differs from $down{id}"; - $node->removeAttribute('href'); - foreach my $v (keys %up) {delete $down{$v}} - foreach my $v (keys %down) - { - $node->setAttribute($v,$down{$v}) - } - foreach my $child (@{$item->getChildNodes}) - { - ©Into($node,$child); - } - &walk($file,$node); + my @upid = &getNamespaceAndValue($node,'id'); + my @downid = &getNamespaceAndValue($item,'id'); + (($upid[0] eq $downid[0]) && ($upid[1] eq $downid[1])) || die "$upid[1] ($upid[0]) differs from $downid[1] ($downid[0]) "; # make sure the link is valid + &walk($getfromfile,$item); } @@ -341,7 +345,6 @@ my $new; if($type==1) { - &fixIDs($item); $new = $doc->createElement($item->getTagName); my %down = &atts($item); foreach my $ordered ('id','name','bldFile','mrp','level','levels','introduced','deprecated','filter') @@ -375,6 +378,26 @@ } } + +sub getNamespaceAndValue + { + my $node = shift; + my $attr = shift || 'id'; + my $id = $node->getAttribute($attr); + if($id eq '') {return} + my $ns; + if($id=~s/^(.*)://) + { # it's got a ns, find out what it is + $ns=&getNs($node,$1); + } + else + { + $ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") || + $defaultns; + } + return ($ns,$id);; + } + sub getNs { # find the namespace URI that applies to the specified prefix. @@ -390,38 +413,6 @@ } -sub fixIDs - { - # translate the ID to use the root doc's namespaces - my $node = shift; - foreach my $id ('id','before') - { - &fixID($node,$id); - } -} - -sub fixID - { - # translate the ID to use the root doc's namespaces - my $node = shift; - my $attr = shift || 'id'; - my $id = $node->getAttribute($attr); - if($id eq '') {return} - my $ns; - if($id=~s/^(.*)://) - { # it's got a ns, find out what it is - my $pre = $1; - $ns=&getNs($node,$pre); - } - else - { - $ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") || - $defaultns; - } - $ns = $urimap{$ns}; - $id = ($ns eq '') ? $id : "$ns:$id"; - return $node->setAttribute($attr,$id); -} sub firstElement { # return the first element in this node diff -r e9d0240c3e66 -r 9527bd30de64 sysdeftools/validate/test-model.xsl --- a/sysdeftools/validate/test-model.xsl Fri Jun 18 09:49:13 2010 +0100 +++ b/sysdeftools/validate/test-model.xsl Tue Jun 22 10:59:57 2010 +0100 @@ -13,6 +13,7 @@ Module containing the validation logic for system definition 3.0.0 syntax --> + @@ -90,7 +91,7 @@ Attribute ="" is not valid for - + @@ -211,11 +212,12 @@ + - S60 Component "" has children. + S60 Component "" has units. - Component "" has children. + Component "" has units. @@ -280,7 +282,6 @@ - @@ -314,8 +315,6 @@ - - path "" should not end in / @@ -353,7 +352,7 @@ // - + Unexpected path for -> : "" @@ -403,13 +402,14 @@ - + Unexpected path for -> : "" + Unexpected path for -> : ""