From 083383cfa43497e89b8f3f1c062241033ca56aad Mon Sep 17 00:00:00 2001 From: XeroOl Date: Sat, 8 Jun 2024 00:00:45 -0500 Subject: [PATCH] Add a bunch of tools for bundling/unbundling fennel-ls --- src/fennel-ls/analyzer.fnl | 2 +- tools/gen-docs.fnl | 25 ++----------------------- tools/unvendor.fnl | 16 ++++++++++++++++ tools/util/sh.fnl | 20 ++++++++++++++++++++ tools/vendor.fnl | 30 ++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 tools/unvendor.fnl create mode 100644 tools/util/sh.fnl create mode 100644 tools/vendor.fnl diff --git a/src/fennel-ls/analyzer.fnl b/src/fennel-ls/analyzer.fnl index 835d454..80dcf6d 100644 --- a/src/fennel-ls/analyzer.fnl +++ b/src/fennel-ls/analyzer.fnl @@ -1,4 +1,4 @@ -"Language +"Analyzer This module is for searching through the data provided by compiler.fnl. It searches through a file to find information about symbols that appear in the file. diff --git a/tools/gen-docs.fnl b/tools/gen-docs.fnl index eb2ac69..3cdde15 100644 --- a/tools/gen-docs.fnl +++ b/tools/gen-docs.fnl @@ -1,26 +1,5 @@ "Script to generate /src/fennel-ls/docs/lua54.fnl and friends automatically" - -(fn sh [...] - "run a shell command." - (let [command (table.concat - (icollect [_ arg (ipairs [...])] - (if - ;; table skips escaping - (= (type arg) :table) - (. arg 1) - ;; simple string skips escaping - (arg:find "^[a-zA-Z0-9/_-]+$") - arg - ;; full escaping - (.. "'" - (string.gsub arg "'" "\\'") - "'"))) - " ")] - (print (.. "tools/gen-docs: " command)) - (os.execute command))) - -(fn mkdir-p [dirname] - (sh "mkdir" "-p" dirname)) +(local {: sh} (require :tools.util.sh)) (fn curl-cached [url] (let [filename (.. "build/" (url:gsub "[/:]" "_")) @@ -41,7 +20,7 @@ result "\n")))) (fn main [] - (mkdir-p "build/") + (sh :mkdir :-p "build/") (let [{:convert lua-manual} (require :tools.gen-docs.lua-manual) {:convert tic-manual} (require :tools.gen-docs.tic80)] (derive-docs-from-url "https://www.lua.org/manual/5.1/manual.html" "lua51.fnl" lua-manual) diff --git a/tools/unvendor.fnl b/tools/unvendor.fnl new file mode 100644 index 0000000..b68dfde --- /dev/null +++ b/tools/unvendor.fnl @@ -0,0 +1,16 @@ +(local {: sh} (require :tools.util.sh)) + +(sh :rm :-f + ;; delete vendored "fennel" + "src/fennel.lua" + ;; delete vendored "fennel" (build dependency) + "fennel" + ;; delete vendored "faith" (build dependency) + "test/faith/faith.fnl" + ;; delete vendored "penlight" (build dependency) + "test/pl/stringio.lua") + +;; write a dummy file to forward to the installation of penlight on LUA_PATH +(doto (io.open "test/pl/stringio.lua") + (: :write "(require :pl.stringio)") + (: :close)) diff --git a/tools/util/sh.fnl b/tools/util/sh.fnl new file mode 100644 index 0000000..7236363 --- /dev/null +++ b/tools/util/sh.fnl @@ -0,0 +1,20 @@ +(fn sh [...] + "run a shell command." + (let [command (table.concat + (icollect [_ arg (ipairs [...])] + (if + ;; table skips escaping + (= (type arg) :table) + (. arg 1) + ;; simple string skips escaping + (arg:find "^[a-zA-Z0-9/_-%.]+$") + arg + ;; full escaping + (.. "'" + (string.gsub arg "'" "\\'") + "'"))) + " ")] + (print (.. "tools/gen-docs: " command)) + (os.execute command))) + +{: sh} diff --git a/tools/vendor.fnl b/tools/vendor.fnl new file mode 100644 index 0000000..ff04c8a --- /dev/null +++ b/tools/vendor.fnl @@ -0,0 +1,30 @@ +(local {: sh} (require :tools.util.sh)) + +(fn git-clone [location url tag] + (if tag + (sh :git :clone :-c :advice.detachedHead=false :--depth=1 :--branch tag url location) + (sh :git :clone :-c :advice.detachedHead=false :--depth=1 url location))) + +(local fennel-version "1.4.2") +(local faith-version "0.1.2") +(local penlight-version "1.14.0") + +;; get && build fennel +(sh :mkdir :-p "build") +(when (not (io.open "build/fennel/fennel")) + (git-clone "build/fennel" + "https://git.sr.ht/~technomancy/fennel" + fennel-version) + (sh :make :-C "build/fennel")) +sh :cp "build/fennel/fennel" "." +(sh :cp "build/fennel/fennel.lua" "src") + +;; get faith +(when (not (io.open "build/fennel/faith.fnl")) + (git-clone "build/faith" "https://git.sr.ht/~technomancy/faith" faith-version)) +(sh :cp "build/faith/faith.fnl" "test/faith/faith.fnl") + +;; get penlight.stringio +(when (not (io.open "build/pl/stringio.lua")) + (git-clone "build/penlight" "https://github.com/lunarmodules/Penlight" penlight-version)) +(sh :cp "build/penlight/lua/pl/stringio.lua" "test/pl/stringio.lua")