How to specify the compile time path of boot build tool?

I’m trying to compile some code with macros that require external resources at both compile time & runtime.

For example:

.
├── build.boot
├── CHANGELOG.md
├── doc
│   └── intro.md
├── LICENSE
├── README.md
├── resources
│   └── String.g4
├── src
│   └── antlr_test
│       └── core.clj
└── test
    └── antlr_test
        └── core_test.clj

6 directories, 8 files

Here’s my project directory. The String.g4 is required for both compiling and running. if I run boot build under the root dir, it will complain that “String.g4” is not found when expanding the macros.

I’ve tired to solve this by copy String.g4 to the root dir of the project and it works, but it might not be the best solution.

I’ll be glad if you could tell me a better solution.

Thanks a lot!

1 Like

Are you setting the :resource-path in your build.boot file?

For example, assuming you are calling set-env! already:

(set-env! 
  :resource-paths #{"resources"}
  ...)

Yeah, I’m using the one generated by the boot template:

(def project 'antlr-test)
(def version "0.1.0-SNAPSHOT")

(set-env! :resource-paths #{"resources" "src"}
          :source-paths   #{"test"}
          :dependencies   '[[org.clojure/clojure "RELEASE"]
                            [clj-antlr "0.2.9"]
                            [adzerk/boot-test "RELEASE" :scope "test"]])

(task-options!
 aot {:namespace   #{'antlr-test.core}}
 pom {:project     project
      :version     version
      :description "FIXME: write description"
      :url         "http://example/FIXME"
      :scm         {:url "https://github.com/yourname/antlr-test"}
      :license     {"Eclipse Public License"
                    "http://www.eclipse.org/legal/epl-v10.html"}}
 repl {:init-ns    'antlr-test.core}
 jar {:main        'antlr-test.core
      :file        (str "antlr-test-" version "-standalone.jar")})

(deftask build
  "Build the project locally as a JAR."
  [d dir PATH #{str} "the set of directories to write to (target)."]
  (let [dir (if (seq dir) dir #{"target"})]
    (comp (aot) (pom) (uber) (jar) (target :dir dir))))

(deftask run
  "Run the project."
  [a args ARG [str] "the arguments for the application."]
  (with-pass-thru fs
    (require '[antlr-test.core :as app])
    (apply (resolve 'app/-main) args)))

(require '[adzerk.boot-test :refer [test]])

Also, here’s the source code. What I’m trying to do is to test the clj-antlr library.

(ns antlr-test.core
  (:gen-class)
  (:require [clj-antlr.core :as antlr]))

(def grammar (antlr/parser "./String.g4"))
(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!")
  (let [input (slurp "input.txt")]
    (prn input)
    (prn (grammar input))))

If you move String.g4 into the resources directory, you should be able to access it via clojure.java.io/resource

This works fine, thanks a lot!