1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises
5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0,
7// pursuant to article 5.3.4 of the CeCILL v.2.1.
8// This file was originally licensed under the terms of the CeCILL v2.1,
9// and continues to be available under such terms.
10// For more information, see the COPYING file which you should have received
11// along with this program.
12
13// Internal function
14
15// Input arguments :
16
17//   name : . technical name of the package
18//          . single string
19//          . mandatory
20
21//   version : . version of the package
22//             . single string
23//             . optional
24
25//   tree_in : . Tree that will be concatenated in the output tree
26//             . struct
27//             . optional
28
29
30// Output arguments :
31
32//   tree_out : . Dependency tree of the package
33//              . struct
34//              . mandatory
35//              . Example :
36//                   tree_out  =
37//                   toolbox_5 - 1.0: [1x1 struct]
38//                   toolbox_4 - 1.0: [1x1 struct]
39//                   toolbox_2 - 1.3: [1x1 struct]
40//                   toolbox_1 - 1.9: [1x1 struct]
41
42//   version_out : . version of the package
43//                 . single string
44//                 . optional
45
46function [tree_out,version_out] = atomsDepTreeExt(name,version)
47
48    lhs = argn(1);
49    rhs = argn(2);
50
51    // Check number of input arguments
52    // =========================================================================
53
54    if (rhs < 1) | (rhs > 2) then
55        error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsDepTreeExt",1,2));
56    end
57
58    // Check input parameters type
59    // =========================================================================
60
61    if type(name) <> 10 then
62        error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"atomsDepTreeExt",1));
63    end
64
65    if (rhs>=2) & (type(version) <> 10) then
66        error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"atomsDepTreeExt",2));
67    end
68
69    // Check input parameters dimensions
70    // =========================================================================
71
72    if size(name) <> 1 then
73        error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"),"atomsDepTreeExt",1));
74    end
75
76    if (rhs>=2) & (size(name)<>1) then
77        error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"),"atomsDepTreeExt",1));
78    end
79
80    // If version not define, version is the list of version compatible with
81    // the current version of Scilab
82    // =========================================================================
83
84    if (rhs<2) | ((rhs>=2) & (version=="")) then
85        version = atomsCompatibleVersions(name);
86    end
87
88    // Loop on versions
89    // =========================================================================
90
91    for i=1:size(version,"*")
92
93        this_package_details = atomsToolboxDetails([name,version(i)]);
94        tree_out(name+" - "+version(i)) = this_package_details;
95
96        if lhs>1 then
97            version_out = version(i);
98        end
99
100        // Now, loop on dependencies
101        // =========================================================================
102
103        this_package_deptree = struct();
104
105        if isfield(this_package_details,"Depends") & (this_package_details("Depends") ~= "") then
106            dependencies = this_package_details("Depends");
107        else
108            dependencies = [];
109        end
110
111        for j=1:size(dependencies,"*")
112
113            this_dependency_success = %F;
114
115            // Split dependencies to get
116            //  - direction ("=",">=",">","<=","<","~")
117            //  - dependence name
118            //  - dependence version (optional)
119
120            this_dependency_tab     = stripblanks(strsplit(dependencies(j),regexp(stripblanks(dependencies(j)),"/\s/")));
121
122            this_dependency_dir     = this_dependency_tab(1);
123            this_dependency_name    = this_dependency_tab(2);
124            this_dependency_version = this_dependency_tab(3);
125
126            // List versions of the dependency we can test
127
128            if this_dependency_dir     == "="  then
129                this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version,this_dependency_version,%T,%T);
130
131            elseif this_dependency_dir == "~"  then
132                this_dependency_list = atomsGetVersions(this_dependency_name);
133
134            elseif this_dependency_dir == ">=" then
135                this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version,"",%T,%T);
136
137            elseif this_dependency_dir == "<=" then
138                this_dependency_list = atomsGetVersions(this_dependency_name,"",this_dependency_version,%T,%T);
139
140            elseif this_dependency_dir == ">" then
141                this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version,"",%F,%F);
142
143            elseif this_dependency_dir == "<" then
144                this_dependency_list = atomsGetVersions(this_dependency_name,"",this_dependency_version,%F,%F);
145
146            end
147
148            for k=1:size(this_dependency_list,"*")
149
150                tree = atomsDepTreeExt(this_dependency_name,this_dependency_list(k));
151
152                // Dependency Tree fails
153
154                if (type(tree) == 4) & (~ tree) then
155                    continue;
156                end
157
158                // Dependency Tree OK
159
160                if type(tree) == 17 then
161                    this_package_deptree    = atomsCatTree(this_package_deptree,tree);
162                    this_dependency_success = %T;
163                    break;
164                end
165
166            end
167
168            if ~  this_dependency_success then
169                tree_out = %F;
170                break;
171            end
172
173        end
174
175        if type(tree_out)==17 then
176            this_package_details("DependencyTree") = this_package_deptree;
177            tree_out(name+" - "+version(i))        = this_package_details;
178            return;
179        end
180
181    end
182
183endfunction
184