[FPKG] Add very basic initialization function to initialize straight.el

Signed-off-by: Sameer Rahmani <lxsameer@gnu.org>
This commit is contained in:
Sameer Rahmani 2020-04-16 18:17:36 +01:00
parent 6e3a872eb6
commit d09a6c450a
6 changed files with 222 additions and 4 deletions

118
core/fg42/fpkg/core.el Normal file
View File

@ -0,0 +1,118 @@
;;; fpkg --- Package manager for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2020 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/FG42/FG42
;; Version: 3.0.0
;;
;; 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.
;;
;; 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.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(require 'fg42/system/api)
(defvar bootstrap-version nil
"`straight.el' bootstrap version. Set it in the `system' level, not here.")
(defvar straight-base-dir)
(defvar straight-repository-branch)
(defvar straight-cache-autoloads)
(defvar straight-check-for-modifications)
(defvar straight-enable-package-integration)
(defvar straight-vc-git-default-clone-depth)
(defvar autoload-compute-prefixes)
(defvar straight-fix-org)
(defvar straight-recipe-repositories)
(defvar straight-recipe-overrides)
(defun fg42-fpkg/-set-straight-values (system)
"Set the default values for some of `straight.el' vars for the SYSTEM."
(setq straight-base-dir (fg42-system/fpkg-path system)
straight-repository-branch "develop"
;; Our autoload process is different.
straight-cache-autoloads nil
;; `straight.el' suppose to be a functional pkg manager but it actually
;; allows user to edit libraries in place which we don't like it.
;; We have our own mechanism to allow users extend FG42 so we don't
;; want `straight.el' to handle it. Frankly it reduces the boot time
;; by a lot.
straight-check-for-modifications nil
straight-enable-package-integration nil
;; We don't want `straight.el' to deep clone the dependencies. Some packages
;; might break this way according to `doom-emacs'
straight-vc-git-default-clone-depth 1
;; We have our own autoload system.
autoload-compute-prefixes nil
straight-fix-org nil))
(defun fg42-fpkg/-install-core-dependencies (system)
"Install the core dependencies of the given SYSTEM.
Core dependencies are thoses packages that the system itself is depends on
and not the extensions."
(mapc #'straight-use-recipes (fg42-system/core-dependencies system)))
(defun fg42-fpkg/initialize (system)
"Initilize the package manager for the given SYSTEM.
Basically fpkg will bootstrap and `straight.el' repositoryu for the given
SYSTEM by fetching the required values from it. Including the path to the
target directory."
(unless (fboundp 'straight--reset-caches)
(let ((bootstrap-file (concat (fg42-system/fpkg-path system)
"straight/repos/straight.el/bootstrap.el"))
(bootstrap-version (fg42-system/fpkg-backend-version system)))
(make-directory (fg42-system/fpkg-path system) t)
(fg42-fpkg/-set-straight-values system)
(or (require 'straight nil t)
(file-readable-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
(format "https://raw.githubusercontent.com/raxod502/straight.el/%s/install.el"
straight-repository-branch)
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp))
(load bootstrap-file nil t)))
(require 'straight))
(funcall #'straight--reset-caches)
(fg42-fpkg/-install-core-dependencies system)
(setq straight-recipe-repositories nil
straight-recipe-overrides nil)
;; Someday we might have to use our own fork of `straight.el'
(straight-register-package
`(straight :type git :host github
:repo "raxod502/straight.el"
:files ("straight*.el")
:branch ,straight-repository-branch
:no-byte-compile t))
(fg42-system/fpkg-initilized! system))
(defun fg42-fpkg/initialize-once (system)
"Initilize FPKG only once for the given SYSTEM."
(when (not (fg42-system/fpkg-initilized-p system))
(fg42-fpkg/initialize system)
(straight-use-package 'use-package)))
(provide 'fg42/fpkg/core)
;;; core.el ends here

66
core/fg42/system/api.el Normal file
View File

@ -0,0 +1,66 @@
;;; system --- System library of FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2020 Sameer Rahmani <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/FG42/FG42
;; Version: 3.0.0
;;
;; 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.
;;
;; 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.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;; This namespace contains several selector function to work with the
;; `fg42-system' data structure.
;;
;;; Code:
(require 'fg42/utils)
(require 'fg42/system/core)
(defun fg42-system/root (system)
"Return the root path of the given SYSTEM."
(fg42-system-root system))
(defun fg42-system/fpkg-path (system)
"Return the absolute path to the fpkg backend from SYSTEM root."
(path-join
(fg42-system/root system)
(fg42-system-fpkg-backend-path system)))
(defun fg42-system/fpkg-backend-version (system)
"Return the FPKG backend version of the given SYSTEM."
(fg42-system-fpkg-backend-version system))
(defun fg42-system/fpkg-initilized-p (system)
"Return a boolean value indicating whether the SYSTEM is initialized or not."
(fg42-system-fpkg-initilized system))
(defun fg42-system/fpkg-initilized! (system)
"Mark fpkg as initialized for the given SYSTEM."
(setf (fg42-system-fpkg-initilized system) t))
(defun fg42-system/core-dependencies (system)
"Return a list of core dependencies for the given SYSTEM.
Core dependencies are those packages which are essential to the system itself
and not the extensions."
(fg42-system-core-dependencies system))
(provide 'fg42/system/api)
;;; api.el ends here

View File

@ -42,14 +42,15 @@ to load FG42."
;; as the default value
(root (concat (getenv "HOME") "/.fg42"))
(fpkg-backend-version 5)
(fpkg-backend-path ".fpkg")
(fpkg-initilized nil)
(core-dependencies '())
;; The directory to store all sort of temporary files including
;; backups, flycheck temps and stuff like that.
(tmp-path "~/.tmp")
;; ;; A list of preloads to setup extensions which are not loaded yet.
;; ;; For more information on preloads checkout `fg42/extension'
;; (preloads '())
(extensions '())
(abilities '())
;; A function which takes the `system' and starts it.

View File

@ -121,5 +121,13 @@ or
:initial-value (apply (car (last fns)) values))))
(defun path-join (&rest paths)
"Join the given PATHS."
(apply #'concat
(append
(mapcar #'file-name-as-directory (butlast paths))
(last paths))))
(provide 'fg42/utils)
;;; utils.el ends here

24
fbt
View File

@ -23,6 +23,7 @@
;;
;;; Commentary:
;;; Code:
(defvar FG42_VERSION "3.0.0-snapshot"
"The version number of the current build of FG42.")
@ -68,6 +69,25 @@ The DIR should be relative to FG42_HOME."
(message "TBD"))
(defun fpkg-init (params)
"Setup fpkg repository with the given PARAMS."
(require 'fg42/fpkg/core)
(fg42-fpkg/initialize FG42))
(defun print-fpkg-help (command)
"Print the usage for fpkg and the possible wrong COMMAND."
(message "Usage:\n")
(message "init - Setup the fpkg repository"))
(defun fpkg (params)
"The main interface to `fpkg' subcommand and PARAMS."
(let ((subcommand (car args))
(args (cdr params)))
(cond
((string= subcommand "init") (funcall #'fpkg-init args))
(t (print-fpkg-help subcommand)))))
(defun print-help (command)
"Print out a usage instructions and print out the invalid msg for COMMAND."
(when command
@ -91,7 +111,11 @@ The DIR should be relative to FG42_HOME."
(setenv "FG42_HOME" fg42-home)
(setenv "FG42_VERSION" FG42_VERSION)
(add-to-list 'load-path (concat (file-name-as-directory fg42-home) "core"))
(load (concat (file-name-as-directory (getenv "FG42_HOME")) "system"))
(cond
((string= command "fpkg") (funcall #'fpkg args))
((string= command "lint") (funcall #'lint (or (car args) "core")))
((string= command "compile") (funcall #'compile (or (car args) "core")))
((string= command "build") (funcall #'build args))

View File

@ -32,6 +32,7 @@
(defsystem FG42
"FG42 implemented in term of systems and this is the default system."
:start (lambda (system) (message "hooray!"))
:fpkg-backend-path ".fpkg-v3"
:extensions '(fg42-elisp))