Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit 8ed0083

Browse files
committed
first take on using the cached dependency manifest in installation process
1 parent 07d9073 commit 8ed0083

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

dist/depends.lua

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ end
208208
-- Directory where the package was downloaded is stored in 'download_dir' attribute
209209
-- of that package in the table of packages returned by this function.
210210
--
211+
-- Optional argument 'dependency_manifest' is a table of dependencies examined
212+
-- from previous installations etc. It can be used to speed-up the dependency
213+
-- resolving procedure for example.
214+
--
211215
-- When optional 'force_no_download' parameter is set to true, then information
212216
-- about packages won't be downloaded during dependency resolving, assuming that
213217
-- entries in the provided manifest are already complete.
@@ -227,8 +231,9 @@ end
227231
-- in installed packages between the recursive calls of this function.
228232
--
229233
-- TODO: refactor this spaghetti code!
230-
local function get_packages_to_install(pkg, installed, manifest, force_no_download, suppress_printing, deploy_dir, dependency_parents, tmp_installed)
234+
local function get_packages_to_install(pkg, installed, manifest, dependency_manifest, force_no_download, suppress_printing, deploy_dir, dependency_parents, tmp_installed)
231235
manifest = manifest or mf.get_manifest()
236+
dependency_manifest = dependency_manifest or {}
232237
force_no_download = force_no_download or false
233238
suppress_printing = suppress_printing or false
234239
deploy_dir = deploy_dir or cfg.root_dir
@@ -240,6 +245,7 @@ local function get_packages_to_install(pkg, installed, manifest, force_no_downlo
240245
assert(type(pkg) == "string", "depends.get_packages_to_install: Argument 'pkg' is not a string.")
241246
assert(type(installed) == "table", "depends.get_packages_to_install: Argument 'installed' is not a table.")
242247
assert(type(manifest) == "table", "depends.get_packages_to_install: Argument 'manifest' is not a table.")
248+
assert(type(dependency_manifest) == "table", "depends.get_packages_to_install: Argument 'dependency_manifest' is not a table.")
243249
assert(type(force_no_download) == "boolean", "depends.get_packages_to_install: Argument 'force_no_download' is not a boolean.")
244250
assert(type(suppress_printing) == "boolean", "depends.get_packages_to_install: Argument 'suppress_printing' is not a boolean.")
245251
assert(type(deploy_dir) == "string", "depends.get_packages_to_install: Argument 'deploy_dir' is not a string.")
@@ -302,17 +308,23 @@ local function get_packages_to_install(pkg, installed, manifest, force_no_downlo
302308
-- will be rewritten by information taken from pkg's dist.info file
303309
if pkg.version == "scm" then pkg.was_scm_version = true end
304310

305-
-- download info about the package if not already downloaded and downloading not prohibited
306-
if not (pkg.download_dir or force_no_download) then
307-
local path_or_err
308-
pkg, path_or_err = package.retrieve_pkg_info(pkg, deploy_dir, suppress_printing)
309-
if not pkg then
310-
err = "Error when resolving dependencies: " .. path_or_err
311-
else
312-
-- set path to downloaded package - used to indicate that the
313-
-- package was already downloaded, to delete unused but downloaded
314-
-- packages and also to install choosen packages
315-
pkg.download_dir = path_or_err
311+
-- TODO: HERE?
312+
-- Try to obtain cached dependency information from the dependency manifest
313+
if dependency_manifest[pkg.name .. "-" .. pkg.version] and cfg.dep_cache then
314+
pkg = dependency_manifest[pkg.name .. "-" .. pkg.version]
315+
else
316+
-- download info about the package if not already downloaded and downloading not prohibited
317+
if not (pkg.download_dir or force_no_download) then
318+
local path_or_err
319+
pkg, path_or_err = package.retrieve_pkg_info(pkg, deploy_dir, suppress_printing)
320+
if not pkg then
321+
err = "Error when resolving dependencies: " .. path_or_err
322+
else
323+
-- set path to downloaded package - used to indicate that the
324+
-- package was already downloaded, to delete unused but downloaded
325+
-- packages and also to install choosen packages
326+
pkg.download_dir = path_or_err
327+
end
316328
end
317329
end
318330

@@ -528,7 +540,7 @@ function get_depends(packages, installed, manifest, dependency_manifest, deploy_
528540
-- get packages needed to satisfy the dependencies
529541
for _, pkg in pairs(packages) do
530542

531-
local needed_to_install, err = get_packages_to_install(pkg, tmp_installed, manifest, force_no_download, suppress_printing, deploy_dir)
543+
local needed_to_install, err = get_packages_to_install(pkg, tmp_installed, manifest, dependency_manifest, force_no_download, suppress_printing, deploy_dir)
532544

533545
-- if everything's fine
534546
if needed_to_install then
@@ -705,10 +717,16 @@ function update_dependency_manifest(pkg, installed, to_install, dep_manifest)
705717
dep_manifest[name_ver] = {}
706718
dep_manifest[name_ver].name = pkg.name
707719
dep_manifest[name_ver].version = pkg.version
720+
dep_manifest[name_ver].arch = pkg.arch
721+
dep_manifest[name_ver].type = pkg.type
708722
dep_manifest[name_ver].path = pkg.path
709723
dep_manifest[name_ver].depends = pkg.depends
710724
dep_manifest[name_ver].conflicts = pkg.conflicts
711725
dep_manifest[name_ver].provides = pkg.provides
726+
dep_manifest[name_ver].license = pkg.license
727+
dep_manifest[name_ver].desc = pkg.desc
728+
dep_manifest[name_ver].author = pkg.author
729+
dep_manifest[name_ver].maintainer = pkg.maintainer
712730

713731
-- add information which dependency is satisfied by which package
714732
if pkg.depends then

dist/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function install(package_names, deploy_dir, variables)
8282
-- installed, that is provided by two different modules in two deploy_dirs?
8383
local dep_manifest_file = sys.abs_path(sys.make_path(deploy_dir, cfg.dep_cache_file))
8484
local dep_manifest, status = {}
85-
if sys.exists(dep_manifest_file) and cfg.cache and not utils.cache_timeout_expired(cfg.cache_timeout, dep_manifest_file) then
85+
if sys.exists(dep_manifest_file) and not utils.cache_timeout_expired(cfg.cache_timeout, dep_manifest_file) then
8686
status, dep_manifest = mf.load_manifest(dep_manifest_file)
8787
if not dep_manifest then return nil, status end
8888
end

0 commit comments

Comments
 (0)