Respresentation of a projects dependencies
The dependencies are stored in a simple array for now, this can be replaced with a binary-search tree or a hash table in the future.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=:), | public, | allocatable | :: | cache |
Cache file |
||
type(dependency_node_t), | public, | allocatable | :: | dep(:) |
Flattend list of all dependencies |
||
character(len=:), | public, | allocatable | :: | dep_dir |
Installation prefix for dependencies |
||
integer, | public | :: | ndep | = | 0 |
Number of currently registered dependencies |
|
integer, | public | :: | unit | = | output_unit |
Unit for IO |
|
integer, | public | :: | verbosity | = | 1 |
Verbosity of printout |
Overload procedure to add new dependencies to the tree
Add project dependencies, each depth level after each other.
We implement this algorithm in an interative rather than a recursive fashion as a choice of design.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(package_config_t), | intent(in) | :: | package |
Project configuration to add |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Add a project and its dependencies to the dependency tree Ensure allocation fits
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(package_config_t), | intent(in) | :: | package |
Project configuration to add |
||
character(len=*), | intent(in) | :: | root |
Current project root directory |
||
logical, | intent(in) | :: | main |
Is the main project |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Add a list of dependencies to the dependency tree Ensure allocation fits ndep
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(dependency_config_t), | intent(in) | :: | dependency(:) |
Dependency configuration to add |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Add a single dependency to the dependency tree
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(dependency_config_t), | intent(in) | :: | dependency |
Dependency configuration to add |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Add a single dependency node to the dependency tree Dependency nodes contain additional information (version, git, revision) Safety: reallocate if necessary
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(dependency_node_t), | intent(in) | :: | dependency |
Dependency configuration to add |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Dump dependency to toml table
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(srcfile_t), | intent(inout) | :: | self |
Instance of the serializable object |
||
type(toml_table), | intent(inout) | :: | table |
Data structure |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Write serializable object to file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(serializable_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | file |
File name |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
|
logical, | intent(in), | optional | :: | json |
Optional JSON format |
Write serializable object to a formatted Fortran unit
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(serializable_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
integer, | intent(in) | :: | unit |
Formatted unit |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
|
logical, | intent(in), | optional | :: | json |
Optional JSON format requested? |
Writing of dependency tree
Write dependency tree to file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | file |
File name |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Write dependency tree to file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
integer, | intent(in) | :: | unit |
Formatted unit |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Write dependency tree to TOML datastructure
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(toml_table), | intent(inout) | :: | table |
Data structure |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Dump dependency to toml table
Because dependencies are named, fallback if this has no name So, serialization will work regardless of size(self%dep) == self%ndep
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the serializable object |
||
type(toml_table), | intent(inout) | :: | table |
Data structure |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Find a dependency in the tree
Find a dependency in the dependency tree
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(in) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | name |
Dependency configuration to add |
Index of the dependency
Depedendncy resolution finished
Check if we are done with the dependency resolution
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(in) | :: | self |
Instance of the dependency tree |
All dependencies are updated
True if entity can be found
True if dependency is part of the tree
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(in) | :: | self |
Instance of the dependency tree |
||
class(dependency_node_t), | intent(in) | :: | dependency |
Dependency configuration to check |
Read dependency from toml table (no checks made at this stage)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(srcfile_t), | intent(inout) | :: | self |
Instance of the serializable object |
||
type(toml_table), | intent(inout) | :: | table |
Data structure |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Read dependency tree from file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(serializable_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | file |
File name |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
|
logical, | intent(in), | optional | :: | json |
Optional JSON format |
Read dependency tree from file init JSON interpreter Read object from TOML table
use default TOML parser
Read object from TOML table
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(serializable_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
integer, | intent(in) | :: | unit |
File name |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
|
logical, | intent(in), | optional | :: | json |
Optional JSON format |
Reading of dependency tree
Read dependency tree from file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | file |
File name |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Read dependency tree from file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
integer, | intent(in) | :: | unit |
File name |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Read dependency tree from TOML data structure
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(toml_table), | intent(inout) | :: | table |
Data structure |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Read dependency from toml table (no checks made at this stage)
Read all dependencies
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the serializable object |
||
type(toml_table), | intent(inout) | :: | table |
Data structure |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Check that two source files are equal All checks passed!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(srcfile_t), | intent(in) | :: | this | |||
class(serializable_t), | intent(in) | :: | that |
Resolve dependencies
Resolve all dependencies in the tree
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | root |
Current installation prefix |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Resolve a single dependency node
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(dependency_node_t), | intent(inout) | :: | dependency |
Dependency configuration to add |
||
type(fpm_global_settings), | intent(in) | :: | global_settings |
Global configuration settings. |
||
character(len=*), | intent(in) | :: | root |
Current installation prefix |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Serialization interface
Check that two dependency trees are equal All checks passed!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(in) | :: | this | |||
class(serializable_t), | intent(in) | :: | that |
Test load/write roundtrip
Test serialization of a serializable object Dump to scratch file Load from scratch file Check same
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(serializable_t), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | message | |||
type(error_t), | intent(out), | allocatable | :: | error |
Update dependency tree
Update dependency tree
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
character(len=*), | intent(in) | :: | name |
Name of the dependency to update |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
Update whole dependency tree
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dependency_tree_t), | intent(inout) | :: | self |
Instance of the dependency tree |
||
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
type, extends(serializable_t) :: dependency_tree_t !> Unit for IO integer :: unit = output_unit !> Verbosity of printout integer :: verbosity = 1 !> Installation prefix for dependencies character(len=:), allocatable :: dep_dir !> Number of currently registered dependencies integer :: ndep = 0 !> Flattend list of all dependencies type(dependency_node_t), allocatable :: dep(:) !> Cache file character(len=:), allocatable :: cache contains !> Overload procedure to add new dependencies to the tree generic :: add => add_project, add_project_dependencies, add_dependencies, & add_dependency, add_dependency_node !> Main entry point to add a project procedure, private :: add_project !> Add a project and its dependencies to the dependency tree procedure, private :: add_project_dependencies !> Add a list of dependencies to the dependency tree procedure, private :: add_dependencies !> Add a single dependency to the dependency tree procedure, private :: add_dependency !> Add a single dependency node to the dependency tree procedure, private :: add_dependency_node !> Resolve dependencies generic :: resolve => resolve_dependencies, resolve_dependency !> Resolve dependencies procedure, private :: resolve_dependencies !> Resolve dependency procedure, private :: resolve_dependency !> True if entity can be found generic :: has => has_dependency !> True if dependency is part of the tree procedure, private :: has_dependency !> Find a dependency in the tree generic :: find => find_name !> Find a dependency by its name procedure, private :: find_name !> Depedendncy resolution finished procedure :: finished !> Reading of dependency tree generic :: load_cache => load_cache_from_file, load_cache_from_unit, load_cache_from_toml !> Read dependency tree from file procedure, private :: load_cache_from_file !> Read dependency tree from formatted unit procedure, private :: load_cache_from_unit !> Read dependency tree from TOML data structure procedure, private :: load_cache_from_toml !> Writing of dependency tree generic :: dump_cache => dump_cache_to_file, dump_cache_to_unit, dump_cache_to_toml !> Write dependency tree to file procedure, private :: dump_cache_to_file !> Write dependency tree to formatted unit procedure, private :: dump_cache_to_unit !> Write dependency tree to TOML data structure procedure, private :: dump_cache_to_toml !> Update dependency tree generic :: update => update_dependency, update_tree !> Update a list of dependencies procedure, private :: update_dependency !> Update all dependencies in the tree procedure, private :: update_tree !> Serialization interface procedure :: serializable_is_same => dependency_tree_is_same procedure :: dump_to_toml => tree_dump_to_toml procedure :: load_from_toml => tree_load_from_toml end type dependency_tree_t