Saturday, 5 January 2008

Handling vendor/third-party libraries in Common Lisp projects

Any non-trivial application is going to have some third party dependencies. When working in C++, I have this very annoying habit to always have all third-party source in source control so that I could build it. And in fact, I would build the third-party libraries along with my own code. The benefits of this setup are:


  • No extra package installation besides compilers and build tools (ideally, I'd put these in as well!)

  • Package versions are fixed.

  • Free to patch libraries because SVN would usually merge nicely on library upgrades.


As we know, Common Lisp is compiled so this annoying habit should carry over nicely. Unfortunately, until very recently, I just didn't get how I would do it. Tonight, I threw together a small hack that works well enough which is all you can hope for at the end of the day.

Typically, my project layouts look like:

sohail@dev:~/project$ find . -maxdepth 1
.
./src
./test
./project.asd
./project-test.asd
./vendor

The vendor directory is where I usually stuff all the third-party dependencies. For example, you might have cl-fad as one of your dependencies. In the project's ASD file, you would add cl-fad as one of the modules you depend on. But the only problem is, how do you tell ASDF to look in ~/project/vendor/cl-fad for the asd files?

Obviously, the answer is asdf:*central-registry*, a list of directory pathnames that ASDF searches when asked to load something. But the problem is that I can check out my project anywhere on the file system, so I can't hardcode the paths.

So dynamically, we need to figure out the root of the checkout, call it *project-root*, get a list of all the ASDF-loadable packages in vendor and add their respective directories to asdf:*central-registry*. Simple enough, but I know more about pathnames than I ever wanted to know! Here is the code (put into project.asd):

(defparameter *project-root*
(make-pathname :directory (pathname-directory *load-truename*)))

(defparameter *vendor-root*
(merge-pathnames "vendor/" *project-root*))

(defparameter *asd-wildcard*
(merge-pathnames "*/*.asd" *vendor-root*))

(defparameter *all-asd-files*
(directory *asd-wildcard*))

(dolist (asd-file *all-asd-files*)
(pushnew (make-pathname :directory (directory-namestring asd-file))
asdf:*central-registry*
:test #'equal))

(defsystem myproject
...
:depends-on (#:cl-fad))

Fun! Hopefully someone knows a simpler way to do this but this makes me happy for now!

2 comments:

Chanwoo Yoo said...

Thanks a lot! This post is really helpful.

dvd troubleshooting said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsaircraft support equipmentsbest support equipments for aircraftsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestThe causes of economic recessionwhat are the causes of economic recessionadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

vero beach vacationvero beach vacationsbeach vacation homes veroms beach vacationsms beach vacationms beach condosmaui beach vacationmaui beach vacationsmaui beach clubbeach vacationsyour beach vacationscheap beach vacations

bob hairstylebob haircutsbob layeredpob hairstylebobbedclassic bobCare for Curly HairTips for Curly Haircurly hair12r 22.5 best pricetires truck bustires 12r 22.5

washington new housenew house houstonnew house san antonionew house venturanew houston house houston house tx