Revert fpkg to use package.el temporary until we finish Enma

This commit is contained in:
Sameer Rahmani 2020-05-17 11:06:41 +01:00
parent cfc46220f5
commit daf8bf3cdf
1 changed files with 50 additions and 27 deletions

View File

@ -37,37 +37,59 @@
(source 'elpa)) (source 'elpa))
(defvar bootstrap-version nil
"Bootstrap version of straight. This var is used in straight's installer.")
(defvar fpkg-packages-path
(expand-file-name ".fpkg/" fg42-home)
"The path to the directory which FPKG will use to store that packages.")
(defvar fpkg-initilized-p nil (defvar fpkg-initilized-p nil
"A boolean flag that indicates whether FPKG is initialized or not.") "A boolean flag that indicates whether FPKG is initialized or not.")
(defvar required-packages (make-hash-table) (defvar required-packages (make-hash-table)
"A hash of `fg42-package structure representing required packages.") "A hash of `fg42-package structure representing required packages.")
;; Functions ----------------------------------
(defun fpkg-initialize ()
"Initilize the straight.e package manager and setup necessary hooks."
(let ((bootstrap-file (concat fpkg-packages-path
"straight/repos/straight.el/bootstrap.el"))
(bootstrap-version 5))
(make-directory fpkg-packages-path t) ;; Functions ----------------------------------
(setq straight-base-dir fpkg-packages-path) (defun all-dependencies-installed? ()
(if (not (file-exists-p bootstrap-file)) "Return t if all the dependencies installed."
(with-current-buffer (let ((result t))
(url-retrieve-synchronously (dolist (pkg (hash-table-keys required-packages))
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" (when (not (package-installed-p pkg))
'silent 'inhibit-cookies) (message "'%s' package is not installed" pkg)
(goto-char (point-max)) (setq result nil)))
(eval-print-last-sexp)) result))
(load bootstrap-file nil 'nomessage))))
(defun install--package (pkg)
"Intall the package PKG via its propreate source."
(let* ((source (fpkg-dependency-source pkg))
(func-name (concat "install-package-via-" (symbol-name source)))
(install-func (symbol-function (intern func-name))))
(funcall install-func pkg)))
(defun fpkg-initialize ()
"Initilize the `package.el' and related stuff to be used in FG42."
(let ((packages (hash-table-values required-packages)))
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
;; Initialize package.el
(package-initialize)
(setq url-http-attempt-keepalives nil)
(unless (all-dependencies-installed?)
;; check for new packages (package versions)
(message "%s" "Refreshing package database...")
(package-refresh-contents)
;; install the missing packages
(dolist (pkg packages)
(when (not (package-installed-p (fpkg-dependency-name pkg)))
(install--package pkg))))))
(defun fpkg-initialize-once () (defun fpkg-initialize-once ()
@ -76,9 +98,10 @@
(fpkg-initialize))) (fpkg-initialize)))
(defun depends-on (pkgname) (defun depends-on (pkgname &rest args)
"Install the given PKGNAME if it isn't installed." "Install the package PKGNAME with respect to the ARGS."
(straight-use-package pkgname)) (let ((pkg (apply 'make-fpkg-dependency :name pkgname args)))
(puthash pkgname pkg required-packages)))
(provide 'fpkg) (provide 'fpkg)