Skip to content

Commit 1ba2cbf

Browse files
committed
Trust ClojureScript :file analysis metadata
Updated ClojureScript's reader to use the :file metadata returned by analysis. It formerly set :file to the actual path of the :file it was analysing. This change matches the Clojure reader behaviour and allows for potemkin import-vars type manipulation of metadata to, for example, point at an alternate var's docs in a different source file. To verify readers are still returning data that we expect, I added some tests based on the existing playgound under test-sources. The tests are a good start but not comprehensive and should be extended as needed. Circleci config is included to automatically run tests on commit. While adding tests, I noticed small bugs and made corrections: 1. The ClojureScript reader now sorts protocol methods by name. This matches the behaviour of the Clojure reader. 2. The Clojure reader will now add a single var for each defrecord with the name of the defrecord. This matches the ClojureScript behaviour and is apparently the desired behaviour for cljdoc. For consistency and testability: - we are now removing keys with empty/nil values from reader analysis maps. - to be conistent with the ClojureScript reader, the Clojure reader no longer returns :file :line :column :end-column and :end-line on the namespace element. For maintainability and to reduce confusion I removed unused: html writer, resources and project.clj. Notes: As part of this change, the ClojureScript reader will stop supressing protocol functions when the actual source does not match the :file metadata. This allows for a tool such as import-vars to point to, and have documented, an imported protocol function. No action was needed for the Clojure reader to make this work. This change was made a bit challenging due to cljdoc's usage of codox's root-dir and :file metadata: The original intent of codox is that the config :root-dir point to the project (aka git) root of a project and that the :file metadata was simply what was returned by analysis. Codox added the :path to analysis metadata to resolve :file to the :root-dir. Cljdoc does not set the :root-dir to the project root, ignores the :path and assumes that the :file is always relative to configured :source-path. Although this usage works for cljdoc, it did sprain my brain while making this change. To compensate, I have been careful to ensure that :file continues to always be relative to the the configured :source-path. Another oddity was that altered :file metadata is being resolved to paths within the jar file when codox is called from cljdoc. This might be due to the way the classpath is setup when doing an analysis run. My change is coded to handle this situation when it arises.
1 parent b29b16a commit 1ba2cbf

30 files changed

+536
-1397
lines changed

.circleci/config.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Clojure CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-clojure/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
branches:
9+
only:
10+
- /cljs-proper.*/
11+
12+
docker:
13+
- image: circleci/clojure:tools-deps-1.10.0.442
14+
15+
working_directory: ~/repo
16+
17+
steps:
18+
- checkout
19+
20+
- restore_cache:
21+
keys:
22+
- v1-dependencies-{{ checksum "codox/deps.edn" }}
23+
- v1-dependencies- # fallback if cache not found
24+
25+
- run:
26+
name: Dump tool versions
27+
command: clojure -e '(println (System/getProperty "java.runtime.name") (System/getProperty "java.runtime.version") "\nClojure" (clojure-version))'
28+
working_directory: ~/repo/codox
29+
30+
- run:
31+
name: Dump classpath
32+
command: clojure -Spath
33+
working_directory: ~/repo/codox
34+
35+
- run:
36+
name: Run tests
37+
command: clojure -Atest --reporter documentation --plugin kaocha.plugin/junit-xml --junit-xml-file target/test-results/unit/results.xml
38+
working_directory: ~/repo/codox
39+
40+
- save_cache:
41+
paths:
42+
- ~/.m2
43+
key: v1-dependencies-{{ checksum "codox/deps.edn" }}
44+
45+
- store_test_results:
46+
path: codox/target/test-results
47+
48+
- store_artifacts:
49+
path: codox/target/test-results

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
pom.xml
22
pom.xml.asc
33
*jar
4+
.cpcache/
45
lib/
56
classes/
67
target/
8+
out/
79
checkouts/
810
.lein-*
911
.nrepl-port

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
### Notes about this fork
22

3-
- Focused on extracting structured data (EDN) from jars.
4-
- Any writing-related (HTML etc.) dependencies have been removed, code is kept to keep diff to mainline manageable.
5-
- Various tweaks have been done to align the results of Clojure and ClojureScript analysis.
3+
[![CircleCI](https://circleci.com/gh/cljdoc/codox/tree/cljs-proper.svg?style=svg)](https://circleci.com/gh/cljdoc/codox/tree/cljs-proper)
64

5+
- Focused on extracting structured data (EDN) from jars for cljdoc which makes use of work under codox subdir only.
6+
- Any writing-related (HTML etc.) dependencies have been removed.
7+
- Any remaining unused files are kept only to keep diff to mainline manageable.
8+
- Various tweaks have been done to align the results of Clojure and ClojureScript analysis.
9+
- During dev, tests can be run via `clojure -A:test --watch`
710

811
---
912

codox/deps.edn

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{:paths ["src" "resources" "test-sources"]
1+
{:paths ["src"]
22
:deps {org.clojure/clojure {:mvn/version "1.9.0"}
33
org.clojure/tools.namespace {:mvn/version "0.2.11"}
4-
org.clojure/clojurescript {:mvn/version "1.10.339"}}}
4+
org.clojure/clojurescript {:mvn/version "1.10.520"}}
5+
:aliases {:test
6+
{:extra-paths ["test" "test-sources"]
7+
:extra-deps {lambdaisland/kaocha {:mvn/version "0.0-413"}
8+
lambdaisland/kaocha-junit-xml {:mvn/version "0.0-70"}}
9+
:main-opts ["-m" "kaocha.runner"]}}}

codox/project.clj

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)