Debian Codegraph @

solenv/bin/modules/par2script/check.pm

raw
1 #
2 # This file is part of the LibreOffice project.
3 #
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 #
8 # This file incorporates work covered by the following license notice:
9 #
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 #
18
19 package par2script::check;
20
21 use par2script::globals;
22
23 ################################
24 # Checks of the setup script
25 ################################
26
27 ########################################################
28 # Checking if all defined directories are needed
29 ########################################################
30
31 sub check_needed_directories
32 {
33 my $allfiles = $par2script::globals::definitions{'File'};
34 my $alldirs = $par2script::globals::definitions{'Directory'};
35
36 # checking if all defined directories are needed
37
38 my $dir;
39 foreach $dir ( keys %{$alldirs} )
40 {
41 # I. directory has create flag
42 if (( exists($alldirs->{$dir}->{'Styles'}) ) && ( $alldirs->{$dir}->{'Styles'} =~ /\bCREATE\b/ )) { next; }
43
44 # II. there is at least one file in the directory
45 my $fileinside = 0;
46 my $file;
47 foreach $file ( keys %{$allfiles} )
48 {
49 if (( $allfiles->{$file}->{'Dir'} eq $dir ) || ( $allfiles->{$file}->{'NetDir'} eq $dir ))
50 {
51 $fileinside = 1;
52 last;
53 }
54 }
55 if ( $fileinside ) { next; }
56
57 # III. the directory is parent for another directory
58 my $isparent = 0;
59 my $onedir;
60 foreach $onedir ( keys %{$alldirs} )
61 {
62 if ( $alldirs->{$onedir}->{'ParentID'} eq $dir )
63 {
64 $isparent = 1;
65 last;
66 }
67 }
68 if ( $isparent ) { next; }
69
70 # no condition is true -> directory definition is superfluous
71 my $infoline = "\tINFO: Directory definition $dir is superfluous\n";
72 # print $infoline;
73 push(@par2script::globals::logfileinfo, $infoline);
74 }
75 }
76
77 ##################################################
78 # Checking if the directories in the item
79 # definitions are defined.
80 ##################################################
81
82 sub check_directories_in_item_definitions
83 {
84 my $item;
85 foreach $item ( @par2script::globals::items_with_directories )
86 {
87 my $allitems = $par2script::globals::definitions{$item};
88
89 my $onegid;
90 foreach $onegid ( keys %{$allitems} )
91 {
92 if ( ! exists($allitems->{$onegid}->{'Dir'}) ) { die "\nERROR: No directory defined for item: $onegid!\n\n"; }
93 my $dir = $allitems->{$onegid}->{'Dir'};
94 if (( $dir eq "PD_PROGDIR" ) || ( $dir =~ /PREDEFINED_/ )) { next; }
95
96 # checking if this directoryid is defined
97 if ( ! exists($par2script::globals::definitions{'Directory'}->{$dir}) )
98 {
99 die "\nERROR: Directory $dir in item $onegid not defined!\n\n";
100 }
101 }
102 }
103 }
104
105 ########################################################
106 # Checking for all Items, that know their modules,
107 # whether these modules exist.
108 ########################################################
109
110 sub check_module_existence
111 {
112 my $item;
113 foreach $item ( @par2script::globals::items_with_moduleid )
114 {
115 my $allitems = $par2script::globals::definitions{$item};
116
117 my $onegid;
118 foreach $onegid ( keys %{$allitems} )
119 {
120 if ( ! exists($allitems->{$onegid}->{'ModuleID'}) ) { die "\nERROR: No ModuleID defined for item: $onegid!\n\n"; }
121 my $moduleid = $allitems->{$onegid}->{'ModuleID'};
122
123 # checking if this directoryid is defined
124 if ( ! exists($par2script::globals::definitions{'Module'}->{$moduleid}) )
125 {
126 die "\nERROR: ModuleID $moduleid in item $onegid not defined!\n\n";
127 }
128 }
129 }
130 }
131
132 ########################################################
133 # Every script has to contain exactly one root module.
134 # This module has no ParentID or an empty ParentID.
135 ########################################################
136
137 sub check_rootmodule
138 {
139 my $rootgid = "";
140 my $foundroot = 0;
141
142 my $allmodules = $par2script::globals::definitions{'Module'};
143
144 my $modulegid = "";
145 foreach $modulegid (keys %{$allmodules} )
146 {
147 if (( ! exists($allmodules->{$modulegid}->{'ParentID'}) ) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
148 {
149 if ( $foundroot )
150 {
151 die "\nERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).\n";
152 }
153 $rootgid = $modulegid;
154 $foundroot = 1;
155 }
156 }
157
158 if ( ! $foundroot )
159 {
160 die "\nERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.\n";
161 }
162
163 print " $rootgid\n" if $par2script::globals::verbose;
164
165 }
166
167 ########################################################
168 # File, Shortcut, Directory, Unixlink must not
169 # contain a ModuleID
170 ########################################################
171
172 sub check_moduleid_at_items
173 {
174 my $item;
175 foreach $item ( @par2script::globals::items_without_moduleid )
176 {
177 my $allitems = $par2script::globals::definitions{$item};
178
179 my $onegid;
180 foreach $onegid ( keys %{$allitems} )
181 {
182 if ( exists($allitems->{$onegid}->{'ModuleID'}) )
183 {
184 die "\nERROR: ModuleID assigned to $onegid! No module assignment to $item!\n\n";
185 }
186 }
187 }
188 }
189
190 ########################################################
191 # Controlling existence of multi assignments
192 ########################################################
193
194 sub check_multiple_assignments
195 {
196 my @multiassignments = ();
197 my $error;
198
199 my $topitem;
200 foreach $topitem ( keys %par2script::globals::assignedgids )
201 {
202 my $item;
203 foreach $item ( keys %{$par2script::globals::assignedgids{$topitem}} )
204 {
205 if ( $par2script::globals::assignedgids{$topitem}->{$item} > 1 )
206 {
207 $error = 1;
208 my $string = "\tGID: $item Assignments: $par2script::globals::assignedgids{$topitem}->{$item}";
209 push(@multiassignments, $string);
210 }
211 }
212 }
213
214 if ( $error ) { par2script::exiter::multiassignmenterror(\@multiassignments); }
215 }
216
217 ########################################################
218 # Check, if a defined directory has a flag CREATE
219 ########################################################
220
221 sub contains_create_flag
222 {
223 my ($gid) = @_;
224
225 my $createflag = 0;
226
227 if (( exists($par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'}) ) &&
228 ( $par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'} =~ /\bCREATE\b/ ))
229 {
230 $createflag = 1;
231 }
232
233 return $createflag;
234 }
235
236 ########################################################
237 # Controlling existence of definitions without
238 # any assignment
239 ########################################################
240
241 sub check_missing_assignments
242 {
243 # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
244 # this causes an error.
245 # Directories only have to be assigned, if they have the flag "CREATE".
246
247 my @missingassignments = ();
248 $error = 0;
249
250 my $item;
251 foreach $item ( @par2script::globals::items_assigned_at_modules )
252 {
253 my $assignedgids = $par2script::globals::assignedgids{$item};
254 my $definedgids = $par2script::globals::definitions{$item};
255
256 my $gid;
257 foreach $gid ( keys %{$definedgids} )
258 {
259 if ( $item eq "Directory" ) { if ( ! contains_create_flag($gid) ) { next; } }
260
261 if ( ! exists( $assignedgids->{$gid} ))
262 {
263 $error = 1;
264 push(@missingassignments, $gid);
265 }
266 }
267 }
268
269 if ( $error ) { par2script::exiter::missingassignmenterror(\@missingassignments); }
270 }
271
272 #############################################################
273 # Controlling if for all shortcuts with file assignment
274 # the file is defined. And for all shortcuts with
275 # shortcut assignment the shortcut has to be defined.
276 #############################################################
277
278 sub check_shortcut_assignments
279 {
280 my $allshortcuts = $par2script::globals::definitions{'Shortcut'};
281 my $allfiles = $par2script::globals::definitions{'File'};
282
283 my $shortcut;
284 foreach $shortcut ( keys %{$allshortcuts} )
285 {
286 if (( exists($allshortcuts->{$shortcut}->{'FileID'}) ) &&
287 ( ! exists($allfiles->{$allshortcuts->{$shortcut}->{'FileID'}}) ))
288 {
289 die "\nERROR: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n";
290 }
291
292 if (( exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
293 ( ! exists($allshortcuts->{$allshortcuts->{$shortcut}->{'ShortcutID'}}) ))
294 {
295 die "\nERROR: ShortcutID $allshortcuts->{$shortcut}->{'ShortcutID'} has no definition at shortcut $shortcut !\n";
296 }
297
298 if (( ! exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
299 ( ! exists($allshortcuts->{$shortcut}->{'FileID'}) ))
300 {
301 die "\nERROR: Shortcut requires assignment to \"ShortcutID\" or \"FileID\". Missing at shortcut $shortcut !\n";
302 }
303 }
304 }
305
306 #############################################################
307 # Controlling if for Modules and Directories, the parents
308 # are defined. If not, this can lead to a problem during
309 # script creation, because only recursively added
310 # Modules or Directories are added to the script.
311 #############################################################
312
313 sub check_missing_parents
314 {
315 my @parentitems = ("Module", "Directory");
316 my %rootparents = ("PREDEFINED_PROGDIR" => "1");
317
318 my $oneitem;
319 foreach $oneitem ( @parentitems )
320 {
321 my $alldefinitions = $par2script::globals::definitions{$oneitem};
322
323 my $onegid;
324 foreach $onegid ( keys %{$alldefinitions} )
325 {
326 # If there is a ParentID used, it must be defined
327 if (( exists($alldefinitions->{$onegid}->{'ParentID'}) ) &&
328 ( ! exists($alldefinitions->{$alldefinitions->{$onegid}->{'ParentID'}}) ) &&
329 ( ! exists($rootparents{$alldefinitions->{$onegid}->{'ParentID'}}) ))
330 {
331 die "\nERROR: Parent \"$alldefinitions->{$onegid}->{'ParentID'}\" at $oneitem \"$onegid\" is not defined!\n";
332 }
333 }
334 }
335 }
336
337 1;