summaryrefslogtreecommitdiff
path: root/modules/atoms/macros/atoms_internals/atomsPackageIsCompatible.sci
blob: 2107038e3a7aae38ab8aa02b36cbdb2b7469cd33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

// Internal function

// Returns True if the package "parent_name - version_name" can accept
// the version "child_version" of the needed package "child_name"
// No matter whether if "parent_name - parent_version" is
// installed or not

// Input arguments :
//
//   parent_name    : . String Array
//                    . mandatory
//
//   parent_version : . String Array
//                    . mandatory
//
//   child_name     : . Single String
//                    . mandatory
//
//   child_version  : . Single String
//                    . mandatory

// Output arguments :
//
//   result : . Boolean Array

function result = atomsPackageIsCompatible(parent_name,parent_version,child_name,child_version)

    rhs    = argn(2);
    result = [];

    // Check number of input arguments
    // =========================================================================
    if rhs <> 4 then
        error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsPackageIsCompatible",4));
    end

    // Check input parameter type
    // =========================================================================

    if type(parent_name) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsPackageIsCompatible",1));
    end

    if type(parent_version) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsPackageIsCompatible",2));
    end

    if type(child_name) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsPackageIsCompatible",3));
    end

    if type(child_version) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsPackageIsCompatible",4));
    end

    // Check input parameter dimension
    // =========================================================================

    if size(parent_name,"*") <> size(parent_version,"*") then
        error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsPackageIsCompatible",1,2));
    end

    if size(child_name,"*") <> 1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsPackageIsCompatible",3));
    end

    if size(child_version,"*") <> 1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsPackageIsCompatible",4));
    end

    // Loop on parents
    // =========================================================================

    for i=1:size(parent_name,"*")

        // Get the dependency field of this package
        // =========================================================================

        parent_deps = atomsToolboxDetails([parent_name(i),parent_version(i)],"Depends");

        if isempty(parent_deps)
            result = [ result ; %F ];
            continue;
        end

        // get the line corresponding to child_name
        // =========================================================================

        parent_deps_this_child = parent_deps(grep(parent_deps,"/\s"+child_name+"\s/","r"));

        if isempty(parent_deps_this_child) then
            result = [ result ; %F ];
            continue;
        end

        // get the line corresponding to child_name
        // =========================================================================

        this_dependency_tab     = stripblanks(strsplit(parent_deps_this_child,regexp(stripblanks(parent_deps_this_child),"/\s/")));

        this_dependency_dir     = this_dependency_tab(1);
        this_dependency_name    = this_dependency_tab(2);
        this_dependency_version = this_dependency_tab(3);

        // List versions of the dependency we can test

        if (this_dependency_dir == "~") | ..
            ( (this_dependency_dir == "=" ) & (this_dependency_version == child_version ) ) | ..
            ( (this_dependency_dir == ">=") & ( atomsVersionCompare(child_version,this_dependency_version) >= 0 ) ) | ..
            ( (this_dependency_dir == ">" ) & ( atomsVersionCompare(child_version,this_dependency_version) >  0 ) ) | ..
            ( (this_dependency_dir == "<=") & ( atomsVersionCompare(child_version,this_dependency_version) <= 0 ) ) | ..
            ( (this_dependency_dir == "<" ) & ( atomsVersionCompare(child_version,this_dependency_version) <  0 ) ) then

            result = [ result ; %T ];

        else
            result = [ result ; %F ];
        end

    end

    result = matrix(result,size(parent_name) );

endfunction