Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
caumond committed Jan 13, 2025
1 parent 97110e1 commit b6fd95d
Show file tree
Hide file tree
Showing 41 changed files with 1,116 additions and 1,173 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/commit_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ jobs:
path: /home/runner/.m2/repository
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-
- name: Tests code alias + linter + forbidden words
run: bb wf-4 -iawlp
- name: Test code
- name: Test code ;;TODO Missing alias + linter + forbidden words
run: bb test test-bb test-unit
- name: Write git diff - show what has been changed by zprint
run: git diff
Expand Down
19 changes: 10 additions & 9 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
-1))
System/exit)}
test {:doc "Dev test bb code in jvm"
:requires [[automaton-build.tasks.test :as test]
[automaton-build.tasks.common :as tasks-common]]
:task (-> (test/run "clj-test-runner"
#{{:description "bb tests in jvm"
:alias :test-bb}
{:description "unit tests - assembly tests at unit level"
:alias :test-unit}
{:description "test local development environmnet itself"
:alias :test-dev}})
:requires [[automaton-build.tasks.test :as test]]
:task (-> (test/run-one-liner-headers
"clj-test-runner"
#{{:description "bb tests in jvm"
:alias :test-bb}
{:description "unit tests - assembly tests at unit level"
:alias :test-unit}
{:description "test local development environmnet itself"
:alias :test-dev}}
(current-task))
System/exit)}
wf-2 {:depends [-base-deps]
:doc "Launch dev environment toolings."
Expand Down
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
:deps {babashka/fs {:mvn/version "0.5.22"}
babashka/process {:mvn/version "0.5.22"}
cheshire/cheshire {:mvn/version "5.13.0"}
clj-htmltopdf/clj-htmltopdf {:mvn/version "0.2.1"}
codox/codox {:mvn/version "0.10.8"}
io.github.clojure/tools.build {:mvn/version "0.10.5"}
metosin/malli {:mvn/version "0.16.1"}
org.clojure/tools.cli {:mvn/version "1.1.230"}
zprint/zprint {:mvn/version "1.2.9"}}
:paths ["src/bb"]}
58 changes: 0 additions & 58 deletions src/bb/automaton_build/actions/cmd.clj

This file was deleted.

96 changes: 50 additions & 46 deletions src/bb/automaton_build/code/clj.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns automaton-build.code.clj
"A proxy to `clojure.tools.build.api`library for building artifacts in Clojure projects."
"A proxy to `clojure.tools.build.api` library for building artifacts in Clojure projects."
(:require
[automaton-build.os.file :as build-file]
[automaton-build.os.filename :as build-filename]
Expand All @@ -21,7 +21,9 @@
(defn compile-clj
"Compile Clojure source to classes in :class-dir. Clojure source files are found in :basis :paths by default, or override with :src-dirs."
[params]
(clj-build-api/compile-clj params))
(merge (try (clj-build-api/compile-clj params)
{:params params}
(catch Exception e (throw (ex-info "Compilation failed" {:params params} e))))))

(defn set-project-root!
"Sets project root variable that's defaulted to \".\" to `root`"
Expand Down Expand Up @@ -53,52 +55,54 @@
;; ********************************************************************************
;; Jar compilation

(defn compile-jar
"In a `project-dir`, do a clj compilation with all files and directories from `app-paths`. Stores the resulted jar in `target-jar-filepath`."
[project-dir app-paths target-jar-filepath normalln errorln verbose]
(let [tmp-dir (build-file/create-temp-dir)]
(merge {:target-dir tmp-dir
:app-paths app-paths
:target-jar-filepath target-jar-filepath
:project-dir project-dir}
(try
(normalln
(str "Copy files and dirs `" app-paths "` from `" project-dir "` to `" tmp-dir "`"))
(let [copy-ress (copy-project-files project-dir app-paths tmp-dir)]
(println "copy-ress " (pr-str copy-ress))
(->> copy-ress
(mapv
(fn [{:keys [status apath target-path exception]}]
(defn- compile-and-uber-jar
[project-dir app-paths target-jar-filepath printers verbose jar-main skip-uberjar?]
(let [{:keys [normalln errorln]} printers
tmp-dir (build-file/create-temp-dir)]
(merge
{:target-dir tmp-dir
:app-paths app-paths
:target-jar-filepath target-jar-filepath
:project-dir project-dir}
(try (-> (str "Copy files and dirs `" app-paths "` from `" project-dir "` to `" tmp-dir "`")
normalln)
(->> (copy-project-files project-dir app-paths tmp-dir)
(mapv (fn [{:keys [status apath target-path exception]}]
(if (= status :success)
(when verbose
(normalln (str "Copied successfully `" apath "` to `" target-path "`")))
(do (errorln (str "Error during copy of `" apath "` to `" target-path "`"))
(normalln (pr-str exception))))))))
#_(comment
(normalln "Compiling")
(let [basis (create-basis)]
(compile-clj {:basis basis
:class-dir tmp-dir})
(normalln "Set project root to" project-dir)
(set-project-root! (build-filename/absolutize project-dir))
(normalln "Create jar")
(jar {:class-dir tmp-dir
:jar-file target-jar-filepath})))
{:status :success}
(catch Exception e
{:status :failed
:exception e})))))
(normalln (pr-str exception)))))))
(normalln "Compiling")
(let [basis (create-basis)]
(println (with-out-str (compile-clj {:basis basis
:class-dir tmp-dir})))
(normalln (str "Set project root to `" project-dir "`"))
(set-project-root! (build-filename/absolutize project-dir))
(normalln "Create jar")
(jar {:class-dir tmp-dir
:main jar-main
:jar-file target-jar-filepath})
(if skip-uberjar?
(normalln "Skip uberjar")
(do (normalln "Create uberjar")
(uber {:uber-file target-jar-filepath
:class-dir tmp-dir
:basis basis
:main jar-main}))))
(normalln "Compilation has succeeded")
{:status :success}
(catch Exception e
(errorln "Compilation failed")
{:status :failed
:exception e})))))

(defn compile-jar
"In a `project-dir`, do a clj compilation with all files and directories from `app-paths`. Stores the resulted jar in `target-jar-filepath`."
[project-dir app-paths target-jar-filepath printers verbose jar-main]
(compile-and-uber-jar project-dir app-paths target-jar-filepath printers verbose jar-main true))

(defn uber-jar
""
[class-dir app-paths target-jar-filepath project-dir jar-main java-opts]
(let [basis (create-basis)]
(compile-clj {:basis basis
:class-dir class-dir
:java-opts java-opts})
(uber {:class-dir class-dir
:uber-file target-jar-filepath
:basis basis
:main jar-main}))
;
)
(defn compile-uberjar
"In a `project-dir`, do a clj compilation with all files and directories from `app-paths`. Stores the resulted jar in `target-jar-filepath`."
[project-dir app-paths target-jar-filepath printers verbose jar-main]
(compile-and-uber-jar project-dir app-paths target-jar-filepath printers verbose jar-main false))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns automaton-build.fe.css
(ns automaton-build.code.css
"Load the file css.
Proxy to [tailwindcss](https://tailwindcss.com/docs/installation)."
Expand Down
38 changes: 0 additions & 38 deletions src/bb/automaton_build/code/lint.clj

This file was deleted.

113 changes: 113 additions & 0 deletions src/bb/automaton_build/code/report_aliases.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
(ns automaton-build.code.report-aliases
"Report aliases inconsistency:
* One `ns` with more than one alias,
* One `alias` assigned to more than one namespace.."
(:require
[automaton-build.code.files :as build-code-files]
[automaton-build.code.reports :as build-code-reports]
[automaton-build.os.file :as build-file]
[clojure.set :as set]
[clojure.string :as str]))

;; ********************************************************************************
;; Project directories
;; ********************************************************************************
(defn project-dirs
"Return all directories of the `deps.edn` file as in `deps-edn-filedesc`"
[deps-edn-filedesc]
(build-code-files/project-dirs (:dir deps-edn-filedesc) (:edn deps-edn-filedesc)))

(defn project-files
"Returns a vector of project file descriptions as found in the project in `project-dir`."
[project-dirs]
(->> project-dirs
build-code-files/project-files
(mapv build-file/read-file)))

;; ********************************************************************************
;; Helpers
;; ********************************************************************************
(defn alias-list
"List aliases in the files from `project-file-descs`.
Note that the scope of this `project-file-descs` is important. If you want to check consistancy between two projects, their files should be included in this list.
Return `matches`, a list of map with keys `:filename`, `:ns` and `:alias` for all matches found in the content."
[project-file-descs]
(->> project-file-descs
(mapcat (fn [{:keys [raw-content]
:as project-file-desc}]
(->> (build-code-reports/search-aliases project-file-desc)
(map (fn [{:keys [alias]
:as alias-map}]
(cond-> alias-map
(= "sut" alias) (assoc :sut-alias true :skip true)
(nil? alias) (assoc :nil-alias true :skip true)
(build-code-reports/is-ignored-file? raw-content)
(assoc :ignored-file true :skip true)))))))
vec))

;; ********************************************************************************
;; Alias actions definitions
;; ********************************************************************************
(defn scan-alias-project*
"For all `project-file-descs` in a project, their alias consistency is analyzed, reports are saved if exist.
Has side effects and echo the result.
Returns `true` if all aliases are consistent."
[{:keys [normalln uri-str h1 h2 h1-valid! h1-error!]
:as _printers}
project-file-descs
verbose?]
(h1 "Search for alias inconsistencies.")
(let [matches (alias-list project-file-descs)
non-skipped-matches (remove :skip matches)
clj-files-wo-aliases (set/difference (set (mapv :filename project-file-descs))
(set (mapv :filename non-skipped-matches)))]
(when verbose?
(normalln "found"
(count project-file-descs)
"files,"
(count matches)
"matches, with "
(count (filter :skip matches))
"ignored (sut:"
(count (filter :sut-alias matches))
", nil:"
(count (filter :nil-alias matches))
", ignored:"
(count (filter :ignored-file matches))
") and "
(count clj-files-wo-aliases)
"files with no alias.")
(normalln "ignored files are:"
(vec (distinct (map :filename (filter :ignored-file matches)))))
(let [filename (build-file/create-temp-file "matches.edn")]
(build-file/write-file filename (str/replace (pr-str matches) #"}" "}\n"))
(normalln "Find details of matches here:" (uri-str filename))))
(let [alias-inconsistents (build-code-reports/alias-inconsistent-ns clj-files-wo-aliases)
ns-inconsistentes (build-code-reports/ns-inconsistent-aliases clj-files-wo-aliases)
alias-valid? (and (empty? alias-inconsistents) (empty? ns-inconsistentes))]
(if alias-valid?
(h1-valid! "Alias are consistent.")
(do (h2 "That aliases are not consistent across namespaces")
(normalln (pr-str alias-inconsistents))
(h2 "That namespaces are not consistent aliases")
(normalln (pr-str alias-inconsistents))
(h1-error! "Alias inconsistency found.")))
alias-valid?)))

(defn scan-alias
"Scan all subproject of `monorepo-project-map` to generate their alias report.
Note all inconsistencies are searched across projects also.
Return `true` if all projects are valid."
[{:keys [subprojects]
:as _monorepo-project-map}
verbose?]
(-> (mapcat (fn [{:keys [deps]
:as _subproject}]
(project-files deps))
subprojects)
(scan-alias-project* verbose?)))
Loading

0 comments on commit b6fd95d

Please sign in to comment.