2015-07-07 00:01:24 +01:00
|
|
|
;;; fpkg --- a simple package manager for FG42 -*- lexical-binding: t; -*-
|
|
|
|
|
2019-08-21 15:38:13 +01:00
|
|
|
;; Copyright (C) 2010-2019 Sameer Rahmani <lxsameer@gnu.org>
|
2015-07-07 00:01:24 +01:00
|
|
|
|
2015-07-07 13:10:57 +01:00
|
|
|
;; Author: Sameer Rahmani <lxsameer@gnu.org>
|
2015-07-07 00:01:24 +01:00
|
|
|
;; Keywords: lisp fg42 IDE package manager
|
|
|
|
;; Version: 1.0.0
|
2019-08-21 15:38:13 +01:00
|
|
|
;;
|
2015-07-07 00:01:24 +01:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2019-08-21 15:38:13 +01:00
|
|
|
;;
|
2015-07-07 00:01:24 +01:00
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2019-08-21 15:38:13 +01:00
|
|
|
;;
|
2015-07-07 00:01:24 +01:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-08-21 15:38:13 +01:00
|
|
|
;;
|
2015-07-07 00:01:24 +01:00
|
|
|
;;; Commentary:
|
2019-08-21 15:38:13 +01:00
|
|
|
;;
|
2015-07-07 00:01:24 +01:00
|
|
|
;; Simple package manager for FG42
|
2019-08-21 15:38:13 +01:00
|
|
|
;;
|
2015-07-07 00:01:24 +01:00
|
|
|
;;; Code:
|
|
|
|
(require 'cl-lib)
|
2015-07-07 12:25:06 +01:00
|
|
|
(require 'subr-x)
|
|
|
|
(require 'fpkg/installers)
|
2015-07-07 00:01:24 +01:00
|
|
|
|
|
|
|
;; Variables ---------------------------------
|
|
|
|
(cl-defstruct fpkg-dependency
|
|
|
|
"Package structure for FG42."
|
|
|
|
name
|
|
|
|
(version "0")
|
2015-07-07 12:25:06 +01:00
|
|
|
(path nil)
|
|
|
|
(source 'elpa))
|
2015-07-07 00:01:24 +01:00
|
|
|
|
|
|
|
(defvar required-packages (make-hash-table)
|
|
|
|
"A hash of `fg42-package structure representing required packages.")
|
|
|
|
|
|
|
|
;; Functions ----------------------------------
|
2015-07-07 12:25:06 +01:00
|
|
|
(defun all-dependencies-installed? ()
|
|
|
|
"Return t if all the dependencies installed."
|
|
|
|
(let ((result t))
|
2015-07-08 11:00:09 +01:00
|
|
|
(dolist (pkg (hash-table-keys required-packages))
|
|
|
|
(when (not (package-installed-p pkg))
|
|
|
|
(message "'%s' package is not installed" pkg)
|
|
|
|
(setq result nil)))
|
2015-07-07 12:25:06 +01:00
|
|
|
result))
|
2015-07-07 13:10:57 +01:00
|
|
|
|
2015-07-07 12:25:06 +01:00
|
|
|
(defun install--package (pkg)
|
|
|
|
"Intall a package 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)))
|
|
|
|
|
2015-07-07 00:01:24 +01:00
|
|
|
(defun fpkg-initialize ()
|
|
|
|
"Initilize the package.el and related stuff to be used in FG42"
|
2015-07-07 12:25:06 +01:00
|
|
|
(let ((packages (hash-table-values required-packages)))
|
|
|
|
|
|
|
|
(require 'package)
|
2015-07-07 13:10:57 +01:00
|
|
|
|
2015-07-07 12:25:06 +01:00
|
|
|
(add-to-list 'package-archives
|
2015-07-10 22:11:50 +01:00
|
|
|
'("melpa" . "http://melpa.org/packages/") t)
|
2015-07-07 12:25:06 +01:00
|
|
|
(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)
|
2015-07-07 13:10:57 +01:00
|
|
|
|
2015-07-07 12:25:06 +01:00
|
|
|
(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))))))
|
|
|
|
|
2015-07-07 13:10:57 +01:00
|
|
|
|
2015-07-07 00:01:24 +01:00
|
|
|
|
|
|
|
(defun depends-on (pkgname &rest args)
|
|
|
|
"Global function to specify a single dependency"
|
|
|
|
(let ((pkg (apply 'make-fpkg-dependency :name pkgname args)))
|
|
|
|
(puthash pkgname pkg required-packages)))
|
2015-07-07 10:42:08 +01:00
|
|
|
|
2019-01-23 14:10:15 +00:00
|
|
|
(message "FPKG has been initialized.")
|
2015-07-07 00:01:24 +01:00
|
|
|
(provide 'fpkg)
|