| 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::Build; |
|---|
| 24 | use base qw{FCM::Class::HASH}; |
|---|
| 25 | |
|---|
| 26 | use FCM::Context::Make; |
|---|
| 27 | |
|---|
| 28 | use constant { |
|---|
| 29 | CTX_SOURCE => 'FCM::Context::Make::Build::Source', |
|---|
| 30 | CTX_TARGET => 'FCM::Context::Make::Build::Target', |
|---|
| 31 | ID_OF_CLASS => 'build', |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | my $ST_UNKNOWN = FCM::Context::Make->ST_UNKNOWN; |
|---|
| 35 | |
|---|
| 36 | __PACKAGE__->class( |
|---|
| 37 | { dest => '$', |
|---|
| 38 | dests => '@', |
|---|
| 39 | id => {isa => '$' , default => ID_OF_CLASS}, |
|---|
| 40 | id_of_class => {isa => '$' , default => ID_OF_CLASS}, |
|---|
| 41 | input_ns_excl => '@', |
|---|
| 42 | input_ns_incl => '@', |
|---|
| 43 | input_source_of => '%', |
|---|
| 44 | prop_of => '%', |
|---|
| 45 | source_of => '%', |
|---|
| 46 | status => {isa => '$' , default => $ST_UNKNOWN}, |
|---|
| 47 | target_of => '%', |
|---|
| 48 | target_key_of => '%', |
|---|
| 49 | target_select_by => '%', |
|---|
| 50 | }, |
|---|
| 51 | ); |
|---|
| 52 | |
|---|
| 53 | # ------------------------------------------------------------------------------ |
|---|
| 54 | package FCM::Context::Make::Build::Source; |
|---|
| 55 | use base qw{FCM::Class::HASH}; |
|---|
| 56 | |
|---|
| 57 | __PACKAGE__->class({ |
|---|
| 58 | checksum => '$', |
|---|
| 59 | deps => '@', |
|---|
| 60 | info_of => '%', |
|---|
| 61 | ns => '$', |
|---|
| 62 | path => '$', |
|---|
| 63 | prop_of => '%', |
|---|
| 64 | type => '$', |
|---|
| 65 | up_to_date => '$', |
|---|
| 66 | }); |
|---|
| 67 | |
|---|
| 68 | # ------------------------------------------------------------------------------ |
|---|
| 69 | package FCM::Context::Make::Build::Target; |
|---|
| 70 | use base qw{FCM::Class::HASH}; |
|---|
| 71 | |
|---|
| 72 | use constant { |
|---|
| 73 | CT_BIN => 'bin', |
|---|
| 74 | CT_ETC => 'etc', |
|---|
| 75 | CT_INCLUDE => 'include', |
|---|
| 76 | CT_LIB => 'lib', |
|---|
| 77 | CT_O => 'o', |
|---|
| 78 | CT_SRC => 'src', |
|---|
| 79 | POLICY_CAPTURE => 'POLICY_CAPTURE', |
|---|
| 80 | POLICY_FILTER => 'POLICY_FILTER', |
|---|
| 81 | POLICY_FILTER_IMMEDIATE => 'POLICY_FILTER_IMMEDIATE', |
|---|
| 82 | ST_FAILED => 'ST_FAILED', |
|---|
| 83 | ST_MODIFIED => 'ST_MODIFIED', |
|---|
| 84 | ST_OOD => 'ST_OOD', |
|---|
| 85 | ST_UNCHANGED => 'ST_UNCHANGED', |
|---|
| 86 | ST_UNKNOWN => 'ST_UNKNOWN', |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | __PACKAGE__->class( |
|---|
| 90 | { category => '$', |
|---|
| 91 | checksum => '$', |
|---|
| 92 | deps => '@', |
|---|
| 93 | dep_policy_of => '%', |
|---|
| 94 | failed_by => '@', |
|---|
| 95 | info_of => '%', |
|---|
| 96 | key => '$', |
|---|
| 97 | ns => '$', |
|---|
| 98 | path => '$', |
|---|
| 99 | path_of_prev => '$', |
|---|
| 100 | path_of_source => '$', |
|---|
| 101 | prop_of => '%', |
|---|
| 102 | prop_of_prev_of => '%', |
|---|
| 103 | status => {isa => '$', default => ST_UNKNOWN}, |
|---|
| 104 | status_of => '%', |
|---|
| 105 | task => '$', |
|---|
| 106 | triggers => '@', |
|---|
| 107 | type => '$', |
|---|
| 108 | }, |
|---|
| 109 | ); |
|---|
| 110 | |
|---|
| 111 | # Returns true if target has a usable dest status. |
|---|
| 112 | sub can_be_source { |
|---|
| 113 | $_[0]->get_category() && $_[0]->get_category() eq CT_SRC; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | # Returns true if target has an OK status. |
|---|
| 117 | sub is_ok { |
|---|
| 118 | $_[0]->get_status() eq ST_MODIFIED || $_[0]->get_status() eq ST_UNCHANGED; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | # Returns true if target has a failed status. |
|---|
| 122 | sub is_failed { |
|---|
| 123 | $_[0]->get_status() eq ST_FAILED; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | # Shorthand for $target->get_status() eq $target->ST_MODIFIED. |
|---|
| 127 | sub is_modified { |
|---|
| 128 | $_[0]->get_status() eq ST_MODIFIED; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | # Shorthand for $target->get_status() eq $target->ST_UNCHANGED. |
|---|
| 132 | sub is_unchanged { |
|---|
| 133 | $_[0]->get_status() eq ST_UNCHANGED; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | # ------------------------------------------------------------------------------ |
|---|
| 137 | 1; |
|---|
| 138 | __END__ |
|---|
| 139 | |
|---|
| 140 | =head1 NAME |
|---|
| 141 | |
|---|
| 142 | FCM::Context::Make::Build |
|---|
| 143 | |
|---|
| 144 | =head1 SYNOPSIS |
|---|
| 145 | |
|---|
| 146 | use FCM::Context::Make::Build; |
|---|
| 147 | my $ctx = FCM::Context::Make::Build->new(); |
|---|
| 148 | |
|---|
| 149 | =head1 DESCRIPTION |
|---|
| 150 | |
|---|
| 151 | Provides a context object for the FCM build system. All the classes described |
|---|
| 152 | below are sub-classes of L<FCM::Class::HASH|FCM::Class::HASH>. |
|---|
| 153 | |
|---|
| 154 | =head1 OBJECTS |
|---|
| 155 | |
|---|
| 156 | =head2 FCM::Context::Make::Build |
|---|
| 157 | |
|---|
| 158 | An instance of this class represents a build. It has the following |
|---|
| 159 | attributes: |
|---|
| 160 | |
|---|
| 161 | =over 4 |
|---|
| 162 | |
|---|
| 163 | =item dest |
|---|
| 164 | |
|---|
| 165 | The destination of the build. |
|---|
| 166 | |
|---|
| 167 | =item dests |
|---|
| 168 | |
|---|
| 169 | An ARRAY containing the path for searching items in the current build. |
|---|
| 170 | |
|---|
| 171 | =item id |
|---|
| 172 | |
|---|
| 173 | The ID of the context. (default="build") |
|---|
| 174 | |
|---|
| 175 | =item id_of_class |
|---|
| 176 | |
|---|
| 177 | The class ID of the context. (default="build") |
|---|
| 178 | |
|---|
| 179 | =item input_source_of |
|---|
| 180 | |
|---|
| 181 | A HASH to map a name space to its ARRAY of input sources. |
|---|
| 182 | |
|---|
| 183 | =item input_ns_excl |
|---|
| 184 | |
|---|
| 185 | An ARRAY of source name-spaces to exclude. |
|---|
| 186 | |
|---|
| 187 | =item input_ns_incl |
|---|
| 188 | |
|---|
| 189 | An ARRAY of source name-spaces to include. |
|---|
| 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 prop_of_prev_of |
|---|
| 198 | |
|---|
| 199 | A HASH containing the named properties (i.e. options and settings of named |
|---|
| 200 | external tools) in the latest successful update of this target. Expects a value |
|---|
| 201 | to be an instance of |
|---|
| 202 | L<FCM::Context::Make::Share::Property|FCM::Context::Make::Share::Property>. |
|---|
| 203 | |
|---|
| 204 | =item source_of |
|---|
| 205 | |
|---|
| 206 | A HASH to map the namespace to the source contexts. Each element is expected to |
|---|
| 207 | be an L</FCM::Context::Make::Build::Source> object. |
|---|
| 208 | |
|---|
| 209 | =item status |
|---|
| 210 | |
|---|
| 211 | The status of this context. See L<FCM::Context::Make|FCM::Context::Make> for the |
|---|
| 212 | status constants. |
|---|
| 213 | |
|---|
| 214 | =item target_of |
|---|
| 215 | |
|---|
| 216 | A HASH to map the namespace to the target contexts. Each element is expected to |
|---|
| 217 | be an L</FCM::Context::Make::Build::Target> object. |
|---|
| 218 | |
|---|
| 219 | =item target_key_of |
|---|
| 220 | |
|---|
| 221 | A HASH to map the automatic key of targets to their desired key. |
|---|
| 222 | |
|---|
| 223 | =item target_select_by |
|---|
| 224 | |
|---|
| 225 | A HASH to allow users to specify how to select from all the targets. The key can |
|---|
| 226 | be "category", "key", "ns" or "task". Each value should be a HASH that |
|---|
| 227 | represents the set of criteria. |
|---|
| 228 | |
|---|
| 229 | =back |
|---|
| 230 | |
|---|
| 231 | =head2 FCM::Context::Make::Build::Source |
|---|
| 232 | |
|---|
| 233 | An instance of this class represents an actual source of the build. It has the |
|---|
| 234 | following attributes: |
|---|
| 235 | |
|---|
| 236 | =over 4 |
|---|
| 237 | |
|---|
| 238 | =item checksum |
|---|
| 239 | |
|---|
| 240 | The checksum of the source file. |
|---|
| 241 | |
|---|
| 242 | =item deps |
|---|
| 243 | |
|---|
| 244 | An ARRAY to contain the dependencies of the source file. Each element of the |
|---|
| 245 | ARRAY is expected to be a reference to a two-element ARRAY [$name, $type] where |
|---|
| 246 | $name is the name of the dependency and $type is its type. |
|---|
| 247 | |
|---|
| 248 | =item info_of |
|---|
| 249 | |
|---|
| 250 | A HASH to contain the extra information of the source file. E.g. If the {main} |
|---|
| 251 | element is true, the source contains a main program. If the {symbols} element |
|---|
| 252 | is defined, it contains a reference to an ARRAY of program unit symbols that has |
|---|
| 253 | been found in the source file. |
|---|
| 254 | |
|---|
| 255 | =item ns |
|---|
| 256 | |
|---|
| 257 | The name-space of the source file. |
|---|
| 258 | |
|---|
| 259 | =item path |
|---|
| 260 | |
|---|
| 261 | The path in the file system pointing to the source file. |
|---|
| 262 | |
|---|
| 263 | =item prop_of |
|---|
| 264 | |
|---|
| 265 | A HASH containing the keys and the values of the build properties (mainly on |
|---|
| 266 | dependency settings) of the source. |
|---|
| 267 | |
|---|
| 268 | =item type |
|---|
| 269 | |
|---|
| 270 | The file type of the source file. |
|---|
| 271 | |
|---|
| 272 | =item up_to_date |
|---|
| 273 | |
|---|
| 274 | A flag to indicate whether the source file is up to date, compared with a |
|---|
| 275 | previous build or the nearest inherited build. |
|---|
| 276 | |
|---|
| 277 | =back |
|---|
| 278 | |
|---|
| 279 | =head2 FCM::Context::Make::Build::Target |
|---|
| 280 | |
|---|
| 281 | An instance of this class represents a target of the build. It has the following |
|---|
| 282 | attributes: |
|---|
| 283 | |
|---|
| 284 | =over 4 |
|---|
| 285 | |
|---|
| 286 | =item category |
|---|
| 287 | |
|---|
| 288 | The target category, e.g. bin, etc, include, lib, o, src |
|---|
| 289 | |
|---|
| 290 | =item checksum |
|---|
| 291 | |
|---|
| 292 | The checksum of the target. |
|---|
| 293 | |
|---|
| 294 | =item deps |
|---|
| 295 | |
|---|
| 296 | An ARRAY containing the dependencies of the target. Each element of the |
|---|
| 297 | ARRAY is expected to be a reference to a two-element ARRAY [$name, $type] where |
|---|
| 298 | $name is the name of the dependency and $type is its type. |
|---|
| 299 | |
|---|
| 300 | =item dep_policy_of |
|---|
| 301 | |
|---|
| 302 | A HASH to contain a map between each relevant dependency type of this target and |
|---|
| 303 | its policy to apply to the dependency type. The policy should take the value of |
|---|
| 304 | POLICY_CAPTURE, POLICY_FILTER or POLICY_FILTER_IMMEDIATE. |
|---|
| 305 | |
|---|
| 306 | =item failed_by |
|---|
| 307 | |
|---|
| 308 | On failure, set to an ARRAY containing the names of the targets that cause the |
|---|
| 309 | failure of this target. |
|---|
| 310 | |
|---|
| 311 | =item info_of |
|---|
| 312 | |
|---|
| 313 | A HASH to contain the extra information of the target. E.g. The {paths} => ARRAY |
|---|
| 314 | reference of include/object search paths for the compile, link and preprocess |
|---|
| 315 | tasks; and {deps}{o} => ARRAY reference and {deps}{o.special} => ARRAY |
|---|
| 316 | reference of object dependency for the link tasks. |
|---|
| 317 | |
|---|
| 318 | =item key |
|---|
| 319 | |
|---|
| 320 | The key (i.e. the base name) of the target. |
|---|
| 321 | |
|---|
| 322 | =item ns |
|---|
| 323 | |
|---|
| 324 | The name-space (of the source file) associated with this target. |
|---|
| 325 | |
|---|
| 326 | =item path |
|---|
| 327 | |
|---|
| 328 | The path in the file system where the target can be located. |
|---|
| 329 | |
|---|
| 330 | =item path_of_prev |
|---|
| 331 | |
|---|
| 332 | The path in the file system where the target in a previous or inherited build |
|---|
| 333 | can be located. |
|---|
| 334 | |
|---|
| 335 | =item path_of_source |
|---|
| 336 | |
|---|
| 337 | The path in the file system where the source file associated with the target can |
|---|
| 338 | be located. |
|---|
| 339 | |
|---|
| 340 | =item prop_of |
|---|
| 341 | |
|---|
| 342 | A HASH containing the keys and the values of the build properties of the target. |
|---|
| 343 | |
|---|
| 344 | =item status |
|---|
| 345 | |
|---|
| 346 | The status of the target. |
|---|
| 347 | |
|---|
| 348 | =item status_of |
|---|
| 349 | |
|---|
| 350 | A HASH containing the status of dependency types that may be relevant to targets |
|---|
| 351 | higher up in the dependency tree. |
|---|
| 352 | |
|---|
| 353 | =item task |
|---|
| 354 | |
|---|
| 355 | The target type, (i.e. the name of the task to update with the target). |
|---|
| 356 | |
|---|
| 357 | =item triggers |
|---|
| 358 | |
|---|
| 359 | An ARRAY reference of the keys of targets that should be automatically triggered |
|---|
| 360 | by this target. |
|---|
| 361 | |
|---|
| 362 | =item type |
|---|
| 363 | |
|---|
| 364 | The type of the source that gives this target. |
|---|
| 365 | |
|---|
| 366 | =back |
|---|
| 367 | |
|---|
| 368 | In addition, an instance of FCM::Context::Make::Extract::Target has the |
|---|
| 369 | following methods: |
|---|
| 370 | |
|---|
| 371 | =over 4 |
|---|
| 372 | |
|---|
| 373 | =item $target->can_be_source() |
|---|
| 374 | |
|---|
| 375 | Returns true if the destination status indicates that the target is usable as a |
|---|
| 376 | source file of a subsequent a make (step). |
|---|
| 377 | |
|---|
| 378 | =item $target->is_ok() |
|---|
| 379 | |
|---|
| 380 | Returns true if the target has a OK destination status. |
|---|
| 381 | |
|---|
| 382 | =item $target->is_failed() |
|---|
| 383 | |
|---|
| 384 | Returns true if the target has a failed destination status. |
|---|
| 385 | |
|---|
| 386 | =item $target->is_modified() |
|---|
| 387 | |
|---|
| 388 | Shorthand for $target->get_status() eq $target->ST_MODIFIED. |
|---|
| 389 | |
|---|
| 390 | =item $target->is_unchanged() |
|---|
| 391 | |
|---|
| 392 | Shorthand for $target->get_status() eq $target->ST_UNCHANGED. |
|---|
| 393 | |
|---|
| 394 | =back |
|---|
| 395 | |
|---|
| 396 | =head1 CONSTANTS |
|---|
| 397 | |
|---|
| 398 | The following is a list of constants: |
|---|
| 399 | |
|---|
| 400 | =over 4 |
|---|
| 401 | |
|---|
| 402 | =item FCM::Context::Make::Build->CTX_INPUT |
|---|
| 403 | |
|---|
| 404 | Alias of FCM::Context::Make::Build::Input. |
|---|
| 405 | |
|---|
| 406 | =item FCM::Context::Make::Build->CTX_SOURCE |
|---|
| 407 | |
|---|
| 408 | Alias of FCM::Context::Make::Build::Source. |
|---|
| 409 | |
|---|
| 410 | =item FCM::Context::Make::Build->ID_OF_CLASS |
|---|
| 411 | |
|---|
| 412 | The default value of the "id" attribute (of an instance), and the ID of the |
|---|
| 413 | functional class. ("build") |
|---|
| 414 | |
|---|
| 415 | =item FCM::Context::Make::Build::Target->CT_BIN |
|---|
| 416 | |
|---|
| 417 | Target category, "bin", executable. |
|---|
| 418 | |
|---|
| 419 | =item FCM::Context::Make::Build::Target->CT_ETC |
|---|
| 420 | |
|---|
| 421 | Target category, "etc", data and misc file. |
|---|
| 422 | |
|---|
| 423 | =item FCM::Context::Make::Build::Target->CT_INCLUDE |
|---|
| 424 | |
|---|
| 425 | Target category, "include", include file. |
|---|
| 426 | |
|---|
| 427 | =item FCM::Context::Make::Build::Target->CT_LIB |
|---|
| 428 | |
|---|
| 429 | Target category, "lib", program library. |
|---|
| 430 | |
|---|
| 431 | =item FCM::Context::Make::Build::Target->CT_O |
|---|
| 432 | |
|---|
| 433 | Target category, "o", compiled object file. |
|---|
| 434 | |
|---|
| 435 | =item FCM::Context::Make::Build::Target->CT_SRC |
|---|
| 436 | |
|---|
| 437 | Target category, "src", generated source file. |
|---|
| 438 | |
|---|
| 439 | =item FCM::Context::Make::Build::Target->POLICY_CAPTURE |
|---|
| 440 | |
|---|
| 441 | Indicates that the dependency type is relevant to the target, and the build |
|---|
| 442 | engine should stop floating the dependency target up the dependency tree. |
|---|
| 443 | |
|---|
| 444 | =item FCM::Context::Make::Build::Target->POLICY_FILTER |
|---|
| 445 | |
|---|
| 446 | Indicates that the dependency type is relevant to the target, and the build |
|---|
| 447 | engine may float the dependency target up the dependency tree as well. |
|---|
| 448 | |
|---|
| 449 | =item FCM::Context::Make::Build::Target->POLICY_FILTER_IMMEDIATE |
|---|
| 450 | |
|---|
| 451 | Indicates that the dependency type is relevant to the target but only if the |
|---|
| 452 | dependency target is an immediate dependency of this target, and the build |
|---|
| 453 | engine may float the dependency target up the dependency tree as well. |
|---|
| 454 | |
|---|
| 455 | =item FCM::Context::Make::Build::Target->ST_FAILED |
|---|
| 456 | |
|---|
| 457 | Indicates that the build has failed to update the target. |
|---|
| 458 | |
|---|
| 459 | =item FCM::Context::Make::Build::Target->ST_MODIFIED |
|---|
| 460 | |
|---|
| 461 | Indicates that the target is out of date and has been modified by the build. |
|---|
| 462 | |
|---|
| 463 | =item FCM::Context::Make::Build::Target->ST_OOD |
|---|
| 464 | |
|---|
| 465 | Indicates that the target is out of date. |
|---|
| 466 | |
|---|
| 467 | =item FCM::Context::Make::Build::Target->ST_UNCHANGED |
|---|
| 468 | |
|---|
| 469 | Indicates that the target is up to date and unchanged by the build. |
|---|
| 470 | |
|---|
| 471 | =item FCM::Context::Make::Build::Target->ST_UNKNOWN |
|---|
| 472 | |
|---|
| 473 | Indicates an unknown target status. |
|---|
| 474 | |
|---|
| 475 | =back |
|---|
| 476 | |
|---|
| 477 | =head1 COPYRIGHT |
|---|
| 478 | |
|---|
| 479 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
|---|
| 480 | |
|---|
| 481 | =cut |
|---|