| 1 | # ------------------------------------------------------------------------------ |
|---|
| 2 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
|---|
| 3 | # |
|---|
| 4 | # This file is part of FCM, tools for managing and building source code. |
|---|
| 5 | # |
|---|
| 6 | # FCM is free software: you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # FCM is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | # ------------------------------------------------------------------------------ |
|---|
| 19 | use strict; |
|---|
| 20 | use warnings; |
|---|
| 21 | |
|---|
| 22 | # ------------------------------------------------------------------------------ |
|---|
| 23 | package FCM::Context::Make::Extract; |
|---|
| 24 | use base qw{FCM::Class::HASH}; |
|---|
| 25 | |
|---|
| 26 | use FCM::Context::Make; |
|---|
| 27 | |
|---|
| 28 | use constant { |
|---|
| 29 | CTX_PROJECT => 'FCM::Context::Make::Extract::Project', |
|---|
| 30 | CTX_SOURCE => 'FCM::Context::Make::Extract::Source', |
|---|
| 31 | CTX_TARGET => 'FCM::Context::Make::Extract::Target', |
|---|
| 32 | CTX_TREE => 'FCM::Context::Make::Extract::Tree', |
|---|
| 33 | ID_OF_CLASS => 'extract', |
|---|
| 34 | MIRROR => 1, |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | __PACKAGE__->class({ |
|---|
| 38 | dest => '$', |
|---|
| 39 | id => {isa => '$', default => ID_OF_CLASS}, |
|---|
| 40 | id_of_class => {isa => '$', default => ID_OF_CLASS}, |
|---|
| 41 | ns_list => '@', |
|---|
| 42 | project_of => '%', |
|---|
| 43 | status => {isa => '$', default => FCM::Context::Make->ST_UNKNOWN}, |
|---|
| 44 | target_of => '%', |
|---|
| 45 | prop_of => '%', |
|---|
| 46 | }); |
|---|
| 47 | |
|---|
| 48 | # ------------------------------------------------------------------------------ |
|---|
| 49 | package FCM::Context::Make::Extract::Project; |
|---|
| 50 | use base qw{FCM::Class::HASH}; |
|---|
| 51 | |
|---|
| 52 | __PACKAGE__->class({ |
|---|
| 53 | cache => '$', |
|---|
| 54 | inherited => '$', |
|---|
| 55 | locator => 'FCM::Context::Locator', |
|---|
| 56 | ns => '$', |
|---|
| 57 | path_excl => '@', |
|---|
| 58 | path_incl => '@', |
|---|
| 59 | path_root => {isa => '$', default => q{}}, |
|---|
| 60 | trees => '@', |
|---|
| 61 | }); |
|---|
| 62 | |
|---|
| 63 | # ------------------------------------------------------------------------------ |
|---|
| 64 | package FCM::Context::Make::Extract::Tree; |
|---|
| 65 | use base qw{FCM::Class::HASH}; |
|---|
| 66 | |
|---|
| 67 | __PACKAGE__->class({ |
|---|
| 68 | cache => '$', |
|---|
| 69 | inherited => '$', |
|---|
| 70 | key => '$', |
|---|
| 71 | locator => 'FCM::Context::Locator', |
|---|
| 72 | ns => '$', |
|---|
| 73 | sources => '@', |
|---|
| 74 | }); |
|---|
| 75 | |
|---|
| 76 | # ------------------------------------------------------------------------------ |
|---|
| 77 | package FCM::Context::Make::Extract::Source; |
|---|
| 78 | use base qw{FCM::Class::HASH}; |
|---|
| 79 | |
|---|
| 80 | use constant { |
|---|
| 81 | ST_NORMAL => 'ST_NORMAL', |
|---|
| 82 | ST_UNCHANGED => 'ST_UNCHANGED', |
|---|
| 83 | ST_MISSING => 'ST_MISSING', |
|---|
| 84 | }; |
|---|
| 85 | |
|---|
| 86 | __PACKAGE__->class({ |
|---|
| 87 | cache => '$', |
|---|
| 88 | key_of_tree => '$', |
|---|
| 89 | locator => 'FCM::Context::Locator', |
|---|
| 90 | ns => '$', |
|---|
| 91 | ns_in_tree => '$', |
|---|
| 92 | status => {isa => '$', default => ST_NORMAL}, |
|---|
| 93 | }); |
|---|
| 94 | |
|---|
| 95 | # Shorthand for $source->get_status() eq $source->ST_MISSING. |
|---|
| 96 | sub is_missing { |
|---|
| 97 | $_[0]->get_status() eq ST_MISSING; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | # Shorthand for $source->get_status() eq $source->ST_UNCHANGED. |
|---|
| 101 | sub is_unchanged { |
|---|
| 102 | $_[0]->get_status() eq ST_UNCHANGED; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | # ------------------------------------------------------------------------------ |
|---|
| 106 | package FCM::Context::Make::Extract::Target; |
|---|
| 107 | use base qw{FCM::Class::HASH}; |
|---|
| 108 | |
|---|
| 109 | use constant { |
|---|
| 110 | ST_ADDED => 'ST_ADDED', |
|---|
| 111 | ST_DELETED => 'ST_DELETED', |
|---|
| 112 | ST_MERGED => 'ST_MERGED', |
|---|
| 113 | ST_MODIFIED => 'ST_MODIFIED', |
|---|
| 114 | ST_O_ADDED => 'ST_O_ADDED', |
|---|
| 115 | ST_O_DELETED => 'ST_O_DELETED', |
|---|
| 116 | ST_UNCHANGED => 'ST_UNCHANGED', |
|---|
| 117 | ST_UNKNOWN => 'ST_UNKNOWN', |
|---|
| 118 | can_be_source => 1, |
|---|
| 119 | }; |
|---|
| 120 | |
|---|
| 121 | __PACKAGE__->class({ |
|---|
| 122 | dests => '@', |
|---|
| 123 | ns => '$', |
|---|
| 124 | path => '$', |
|---|
| 125 | source_of => '%', |
|---|
| 126 | status => {isa => '$', default => ST_UNKNOWN}, |
|---|
| 127 | status_of_source => {isa => '$', default => ST_UNKNOWN}, |
|---|
| 128 | }); |
|---|
| 129 | |
|---|
| 130 | # Returns true if target has an OK status. |
|---|
| 131 | sub is_ok { |
|---|
| 132 | my ($self) = @_; |
|---|
| 133 | my $status = $self->get_status(); |
|---|
| 134 | grep {$_ eq $status} |
|---|
| 135 | (ST_ADDED, ST_MERGED, ST_MODIFIED, ST_O_ADDED, ST_UNCHANGED); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | # Shorthand for $target->get_status() eq $target->ST_UNCHANGED. |
|---|
| 139 | sub is_unchanged { |
|---|
| 140 | $_[0]->get_status() eq ST_UNCHANGED; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | # ------------------------------------------------------------------------------ |
|---|
| 144 | 1; |
|---|
| 145 | __END__ |
|---|
| 146 | |
|---|
| 147 | =head1 NAME |
|---|
| 148 | |
|---|
| 149 | FCM::Context::Make::Extract |
|---|
| 150 | |
|---|
| 151 | =head1 SYNOPSIS |
|---|
| 152 | |
|---|
| 153 | use FCM::Context::Make::Extract; |
|---|
| 154 | my $ctx = FCM::Context::Make::Extract->new(); |
|---|
| 155 | |
|---|
| 156 | =head1 DESCRIPTION |
|---|
| 157 | |
|---|
| 158 | Provides a context object for the FCM extract system. All the classes described |
|---|
| 159 | below are sub-classes of L<FCM::Class::HASH|FCM::Class::HASH>. |
|---|
| 160 | |
|---|
| 161 | =head1 OBJECTS |
|---|
| 162 | |
|---|
| 163 | =head2 FCM::Context::Make::Extract |
|---|
| 164 | |
|---|
| 165 | An instance of this class represents an extract. It has the following |
|---|
| 166 | attributes: |
|---|
| 167 | |
|---|
| 168 | =over 4 |
|---|
| 169 | |
|---|
| 170 | =item dest |
|---|
| 171 | |
|---|
| 172 | The destination of the extract. |
|---|
| 173 | |
|---|
| 174 | =item id |
|---|
| 175 | |
|---|
| 176 | The ID of the current context. (default="extract") |
|---|
| 177 | |
|---|
| 178 | =item id_of_class |
|---|
| 179 | |
|---|
| 180 | The class ID of the current context. (default="extract") |
|---|
| 181 | |
|---|
| 182 | =item ns_list |
|---|
| 183 | |
|---|
| 184 | An ARRAY of name-spaces of the projects to extract. |
|---|
| 185 | |
|---|
| 186 | =item project_of |
|---|
| 187 | |
|---|
| 188 | A HASH to map (key) the name-spaces of the projects in this extract to (value) |
|---|
| 189 | their corresponding contexts. |
|---|
| 190 | |
|---|
| 191 | =item prop_of |
|---|
| 192 | |
|---|
| 193 | A HASH containing the named properties (i.e. options and settings of named |
|---|
| 194 | external tools). Expects a value to be an instance of |
|---|
| 195 | L<FCM::Context::Make::Share::Property|FCM::Context::Make::Share::Property>. |
|---|
| 196 | |
|---|
| 197 | =item status |
|---|
| 198 | |
|---|
| 199 | The status of the extract. See L<FCM::Context::Make|FCM::Context::Make> for the |
|---|
| 200 | status constants. |
|---|
| 201 | |
|---|
| 202 | =item target_of |
|---|
| 203 | |
|---|
| 204 | A HASH to map (key) the name-spaces of the targets in this extract to (value) |
|---|
| 205 | their corresponding contexts. |
|---|
| 206 | |
|---|
| 207 | =back |
|---|
| 208 | |
|---|
| 209 | =head2 FCM::Context::Make::Extract::Project |
|---|
| 210 | |
|---|
| 211 | An instance of this class represents a project in an extract. It has the |
|---|
| 212 | following attributes: |
|---|
| 213 | |
|---|
| 214 | =over 4 |
|---|
| 215 | |
|---|
| 216 | =item cache |
|---|
| 217 | |
|---|
| 218 | The file system location (cache) of this project. |
|---|
| 219 | |
|---|
| 220 | =item inherited |
|---|
| 221 | |
|---|
| 222 | This project is inherited? |
|---|
| 223 | |
|---|
| 224 | =item locator |
|---|
| 225 | |
|---|
| 226 | An instance of L<FCM::Context::Locator|FCM::Context::Locator> that represents |
|---|
| 227 | the locator of this project. |
|---|
| 228 | |
|---|
| 229 | =item ns |
|---|
| 230 | |
|---|
| 231 | The name-space of this project. |
|---|
| 232 | |
|---|
| 233 | =item path_excl |
|---|
| 234 | |
|---|
| 235 | An ARRAY of patterns to match the names of the paths that will be excluded in |
|---|
| 236 | this project. |
|---|
| 237 | |
|---|
| 238 | =item path_incl |
|---|
| 239 | |
|---|
| 240 | An ARRAY of patterns to match the names of the paths that will always be |
|---|
| 241 | included in this project. |
|---|
| 242 | |
|---|
| 243 | =item path_root |
|---|
| 244 | |
|---|
| 245 | The relative path in a project tree for the root name-space. If this is |
|---|
| 246 | specified, the system will extract only files under this path, and their |
|---|
| 247 | name-spaces will be adjusted to be relative to this path. |
|---|
| 248 | |
|---|
| 249 | =item trees |
|---|
| 250 | |
|---|
| 251 | An ARRAY of the tree contexts in this project. By convention, the 0th element is |
|---|
| 252 | the base tree. |
|---|
| 253 | |
|---|
| 254 | =back |
|---|
| 255 | |
|---|
| 256 | =head2 FCM::Context::Make::Extract::Tree |
|---|
| 257 | |
|---|
| 258 | An instance of this class represents a tree in a project. It has the following |
|---|
| 259 | attributes: |
|---|
| 260 | |
|---|
| 261 | =over 4 |
|---|
| 262 | |
|---|
| 263 | =item cache |
|---|
| 264 | |
|---|
| 265 | The file system location (cache) of this tree. |
|---|
| 266 | |
|---|
| 267 | =item inherited |
|---|
| 268 | |
|---|
| 269 | A flag to indicate whether this tree is provided by an inherited extract. |
|---|
| 270 | |
|---|
| 271 | =item key |
|---|
| 272 | |
|---|
| 273 | The key of this tree. By convention, the base tree is the 0th key. |
|---|
| 274 | |
|---|
| 275 | =item locator |
|---|
| 276 | |
|---|
| 277 | An instance of L<FCM::Context::Locator|FCM::Context::Locator> that represents |
|---|
| 278 | the locator of this tree. |
|---|
| 279 | |
|---|
| 280 | =item ns |
|---|
| 281 | |
|---|
| 282 | The name-space of the project in which this tree belongs. |
|---|
| 283 | |
|---|
| 284 | =item sources |
|---|
| 285 | |
|---|
| 286 | An ARRAY of source file contexts provided by this tree. |
|---|
| 287 | |
|---|
| 288 | =back |
|---|
| 289 | |
|---|
| 290 | =head2 FCM::Context::Make::Extract::Source |
|---|
| 291 | |
|---|
| 292 | An instance of this class represents a source file provided by a project tree. |
|---|
| 293 | It has the following attributes: |
|---|
| 294 | |
|---|
| 295 | =over 4 |
|---|
| 296 | |
|---|
| 297 | =item cache |
|---|
| 298 | |
|---|
| 299 | The file system location (cache) of this source file. |
|---|
| 300 | |
|---|
| 301 | =item key_of_tree |
|---|
| 302 | |
|---|
| 303 | The key of the tree that provides this source file. |
|---|
| 304 | |
|---|
| 305 | =item locator |
|---|
| 306 | |
|---|
| 307 | An instance of L<FCM::Context::Locator|FCM::Context::Locator> that represents |
|---|
| 308 | the locator of the source file. |
|---|
| 309 | |
|---|
| 310 | =item ns |
|---|
| 311 | |
|---|
| 312 | The full (mapped) name-space of the source file, (including the leading project |
|---|
| 313 | name-space). |
|---|
| 314 | |
|---|
| 315 | =item ns_in_tree |
|---|
| 316 | |
|---|
| 317 | The original name-space of the source file, relative to its path in the tree. |
|---|
| 318 | |
|---|
| 319 | =item status |
|---|
| 320 | |
|---|
| 321 | The status of the source file. It can take the value of one of the |
|---|
| 322 | FCM::Context::Make::Extract::Source->ST_* constants. See </CONSTANTS> for detail. |
|---|
| 323 | |
|---|
| 324 | =back |
|---|
| 325 | |
|---|
| 326 | In addition, an instance of FCM::Context::Make::Extract::Source has the |
|---|
| 327 | following methods: |
|---|
| 328 | |
|---|
| 329 | =over 4 |
|---|
| 330 | |
|---|
| 331 | =item $source->is_missing() |
|---|
| 332 | |
|---|
| 333 | Shorthand for $source->get_status() eq $source->ST_MISSING. |
|---|
| 334 | |
|---|
| 335 | =item $source->is_unchanged() |
|---|
| 336 | |
|---|
| 337 | Shorthand for $source->get_status() eq $source->ST_UNCHANGED. |
|---|
| 338 | |
|---|
| 339 | =back |
|---|
| 340 | |
|---|
| 341 | =head2 FCM::Context::Make::Extract::Target |
|---|
| 342 | |
|---|
| 343 | An instance of this class represents an extract target. It has the following |
|---|
| 344 | attributes: |
|---|
| 345 | |
|---|
| 346 | =over 4 |
|---|
| 347 | |
|---|
| 348 | =item dests |
|---|
| 349 | |
|---|
| 350 | An ARRAY containing the destination search path of this target. The first |
|---|
| 351 | element is the path to the destination of the current extract, and the rest are |
|---|
| 352 | destinations to inherited extracts. |
|---|
| 353 | |
|---|
| 354 | =item ns |
|---|
| 355 | |
|---|
| 356 | The full name-space of this target. |
|---|
| 357 | |
|---|
| 358 | =item path |
|---|
| 359 | |
|---|
| 360 | Returns the actual destination path of this target. |
|---|
| 361 | |
|---|
| 362 | =item source_of |
|---|
| 363 | |
|---|
| 364 | A HASH for mapping (key) the keys of the trees to (value) the corresponding |
|---|
| 365 | contexts of the source files provided by the trees to this target. |
|---|
| 366 | |
|---|
| 367 | =item status |
|---|
| 368 | |
|---|
| 369 | The status of the target destination. It can take the value of one of the |
|---|
| 370 | FCM::Context::Make::Extract::Target->ST_* constants. See </CONSTANTS> for detail. |
|---|
| 371 | |
|---|
| 372 | =item status_of_source |
|---|
| 373 | |
|---|
| 374 | The status of the target, with respect to its sources. It can take the value of |
|---|
| 375 | one of the FCM::Context::Make::Extract::Target->ST_* constants. See </CONSTANTS> |
|---|
| 376 | for detail. |
|---|
| 377 | |
|---|
| 378 | =back |
|---|
| 379 | |
|---|
| 380 | In addition, an instance of FCM::Context::Make::Extract::Target has the |
|---|
| 381 | following methods: |
|---|
| 382 | |
|---|
| 383 | =over 4 |
|---|
| 384 | |
|---|
| 385 | =item $target->can_be_source() |
|---|
| 386 | |
|---|
| 387 | Returns true if the destination status indicates that the target is usable as a |
|---|
| 388 | source file of a subsequent a make (step). |
|---|
| 389 | |
|---|
| 390 | =item $target->is_ok() |
|---|
| 391 | |
|---|
| 392 | Returns true if the target has a OK destination status. |
|---|
| 393 | |
|---|
| 394 | =item $target->is_unchanged() |
|---|
| 395 | |
|---|
| 396 | Shorthand for $target->get_status() eq $target->ST_UNCHANGED. |
|---|
| 397 | |
|---|
| 398 | =back |
|---|
| 399 | |
|---|
| 400 | =head1 CONSTANTS |
|---|
| 401 | |
|---|
| 402 | The following is a list of constants: |
|---|
| 403 | |
|---|
| 404 | =over 4 |
|---|
| 405 | |
|---|
| 406 | =item FCM::Context::Make::Extract->CTX_PROJECT |
|---|
| 407 | |
|---|
| 408 | An alias to FCM::Context::Make::Extract::Project. |
|---|
| 409 | |
|---|
| 410 | =item FCM::Context::Make::Extract->CTX_SOURCE |
|---|
| 411 | |
|---|
| 412 | An alias to FCM::Context::Make::Extract::Source. |
|---|
| 413 | |
|---|
| 414 | =item FCM::Context::Make::Extract->CTX_TARGET |
|---|
| 415 | |
|---|
| 416 | An alias to FCM::Context::Make::Extract::Target. |
|---|
| 417 | |
|---|
| 418 | =item FCM::Context::Make::Extract->CTX_TREE |
|---|
| 419 | |
|---|
| 420 | An alias to FCM::Context::Make::Extract::Tree. |
|---|
| 421 | |
|---|
| 422 | =item FCM::Context::Make::Extract->ID_OF_CLASS |
|---|
| 423 | |
|---|
| 424 | The default value of the "id" attribute (of an instance), and the ID of the |
|---|
| 425 | functional class. ("extract") |
|---|
| 426 | |
|---|
| 427 | =item FCM::Context::Make::Extract->MIRROR |
|---|
| 428 | |
|---|
| 429 | A flag to tell the mirror sub-system that the targets of this context can be |
|---|
| 430 | used as inputs sources to subsequent steps for the configuration file in the |
|---|
| 431 | mirror destination. |
|---|
| 432 | |
|---|
| 433 | =item FCM::Context::Make::Extract::Source->ST_NORMAL |
|---|
| 434 | |
|---|
| 435 | Source status: normal. |
|---|
| 436 | |
|---|
| 437 | =item FCM::Context::Make::Extract::Source->ST_UNCHANGED |
|---|
| 438 | |
|---|
| 439 | Source status: source is unchanged (against base). |
|---|
| 440 | |
|---|
| 441 | =item FCM::Context::Make::Extract::Source->ST_MISSING |
|---|
| 442 | |
|---|
| 443 | Source status: source is a placeholder in a target. It does not actually exist |
|---|
| 444 | in the source tree. |
|---|
| 445 | |
|---|
| 446 | =item FCM::Context::Make::Extract::Target->ST_ADDED |
|---|
| 447 | |
|---|
| 448 | As destination status: new file in the target destination. As source status: |
|---|
| 449 | added by a source in a diff tree. |
|---|
| 450 | |
|---|
| 451 | =item FCM::Context::Make::Extract::Target->ST_DELETED |
|---|
| 452 | |
|---|
| 453 | As destination status: file removed from the target destination. As source |
|---|
| 454 | status: target removed by a diff tree. |
|---|
| 455 | |
|---|
| 456 | =item FCM::Context::Make::Extract::Target->ST_MERGED |
|---|
| 457 | |
|---|
| 458 | As source status: modified by 2 or more diff trees. |
|---|
| 459 | |
|---|
| 460 | =item FCM::Context::Make::Extract::Target->ST_MODIFIED |
|---|
| 461 | |
|---|
| 462 | As destination status: target destination is modified. As source status: |
|---|
| 463 | modified by 1 diff tree. |
|---|
| 464 | |
|---|
| 465 | =item FCM::Context::Make::Extract::Target->ST_O_ADDED |
|---|
| 466 | |
|---|
| 467 | As destination status: new file in the target destination, overriding a file in |
|---|
| 468 | an inherited destination. |
|---|
| 469 | |
|---|
| 470 | =item FCM::Context::Make::Extract::Target->ST_O_DELETED |
|---|
| 471 | |
|---|
| 472 | As destination status: target destination should be removed, but there is still |
|---|
| 473 | a file in an inherited destination. |
|---|
| 474 | |
|---|
| 475 | =item FCM::Context::Make::Extract::Target->ST_UNCHANGED |
|---|
| 476 | |
|---|
| 477 | As destination status: target destination is unchanged. As source status: |
|---|
| 478 | unchanged by a diff tree. |
|---|
| 479 | |
|---|
| 480 | =item FCM::Context::Make::Extract::Target->ST_UNKNOWN |
|---|
| 481 | |
|---|
| 482 | Status is unknown. |
|---|
| 483 | |
|---|
| 484 | =back |
|---|
| 485 | |
|---|
| 486 | =head1 SEE ALSO |
|---|
| 487 | |
|---|
| 488 | L<FCM::System::Make::Extract|FCM::System::Make::Extract> |
|---|
| 489 | |
|---|
| 490 | =head1 COPYRIGHT |
|---|
| 491 | |
|---|
| 492 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
|---|
| 493 | |
|---|
| 494 | =cut |
|---|