Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 208 lines (174 sloc) 9.472 kb
add374a @brown Add Lispworks floating point support using an FLI technique by
authored
1 ;;;; Copyright 2011 Google Inc. All Rights Reserved
2
3 ;;;; Redistribution and use in source and binary forms, with or without
4 ;;;; modification, are permitted provided that the following conditions are
5 ;;;; met:
6
7 ;;;; * Redistributions of source code must retain the above copyright
8 ;;;; notice, this list of conditions and the following disclaimer.
9 ;;;; * Redistributions in binary form must reproduce the above
10 ;;;; copyright notice, this list of conditions and the following disclaimer
11 ;;;; in the documentation and/or other materials provided with the
12 ;;;; distribution.
13 ;;;; * Neither the name of Google Inc. nor the names of its
14 ;;;; contributors may be used to endorse or promote products derived from
15 ;;;; this software without specific prior written permission.
16
17 ;;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ;;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ;;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ;;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ;;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ;;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ;;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ;;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ;;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ;;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ;;;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 ;;;; Author: brown@google.com (Robert Brown)
5d1a426 Initial commit of Common Lisp protocol buffer project.
Robert Brown authored
30
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
31 ;;;; Protobuf configuration
b647e92 @brown Fix problems with building when the protobuf.asd file is not in the
authored
32
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
33 (in-package #:common-lisp-user)
34
35 (defpackage #:protobuf-config
36 (:documentation "Configuration information for PROTOBUF.")
37 (:use #:common-lisp)
354d9b6 @brown Update for latest Gogole protoc. Use protoc-gen-lisp in PATH.
authored
38 (:export *protoc-relative-path*))
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
39
40 (in-package #:protobuf-config)
41
da7eaa9 @brown Add asdf:*PROTOC-RELATIVE-PATH* to control whether a relative or absolut...
authored
42 (defvar *protoc-relative-path* nil
354d9b6 @brown Update for latest Gogole protoc. Use protoc-gen-lisp in PATH.
authored
43 "Supply relative proto file paths to protoc, the protobuf compiler?")
da7eaa9 @brown Add asdf:*PROTOC-RELATIVE-PATH* to control whether a relative or absolut...
authored
44
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
45 ;;;; ASDF package changes
46
47 (in-package #:asdf)
da7eaa9 @brown Add asdf:*PROTOC-RELATIVE-PATH* to control whether a relative or absolut...
authored
48
df425d9 @brown README: Update the build instructions and test instructions.
authored
49 (defclass protobuf-source-file (cl-source-file)
43a8f79 @brown Re-indent defclass.
authored
50 ((relative-proto-pathname :initarg :proto-pathname
51 :initform nil
52 :reader proto-pathname
53 :documentation
54 "Relative pathname that specifies the location of a .proto file.")
55 (search-path :initform ()
56 :initarg :proto-search-path
57 :reader search-path
58 :documentation
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
59 "List containing directories where the protocol buffer compiler should search
60 for imported protobuf files. Non-absolute pathnames are treated as relative to
61 the directory containing the DEFSYSTEM form in which they appear."))
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
62 (:documentation "A protocol buffer definition file."))
63
df425d9 @brown README: Update the build instructions and test instructions.
authored
64 (export '(protobuf-source-file proto-pathname search-path))
65
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
66 ;;;; ASDF system definition
df425d9 @brown README: Update the build instructions and test instructions.
authored
67
68 (in-package #:common-lisp-user)
69
70 (defpackage #:protobuf-system
71 (:documentation "System definitions for protocol buffer code.")
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
72 (:use #:common-lisp
73 #:asdf
74 #:protobuf-config))
df425d9 @brown README: Update the build instructions and test instructions.
authored
75
76 (in-package #:protobuf-system)
77
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
78 (defclass proto-to-lisp (operation)
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
79 ()
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
80 (:documentation
81 "An ASDF operation that compiles a .proto file containing protocol buffer
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
82 definitions into a Lisp source file."))
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
83
df425d9 @brown README: Update the build instructions and test instructions.
authored
84 (defmethod component-depends-on ((operation compile-op) (component protobuf-source-file))
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
85 "Compiling a protocol buffer file depends on generating Lisp source code for
86 the protobuf, but also on loading package definitions and in-line function
87 definitions that the machine-generated protobuf Lisp code uses."
b94b59e @brown For PROTO-FILE targets the machine generated Lisp file is stored at
authored
88 `((proto-to-lisp ,(component-name component))
17a1bcc @brown Compiling proto files depends package, wire-format, etc. being loaded, n...
authored
89 ,@(call-next-method)))
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
90
df425d9 @brown README: Update the build instructions and test instructions.
authored
91 (defmethod component-depends-on ((operation load-op) (component protobuf-source-file))
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
92 "Loading a protocol buffer file depends on generating Lisp source code for the
93 protobuf, but also on loading package definitions and in-line function
94 definitions that the machine-generated protobuf Lisp code uses."
b94b59e @brown For PROTO-FILE targets the machine generated Lisp file is stored at
authored
95 `((proto-to-lisp ,(component-name component))
17a1bcc @brown Compiling proto files depends package, wire-format, etc. being loaded, n...
authored
96 ,@(call-next-method)))
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
97
df425d9 @brown README: Update the build instructions and test instructions.
authored
98 (defun proto-input (protobuf-source-file)
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
99 "Returns the pathname of the protocol buffer definition file that must be
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
100 translated into Lisp source code for this PROTO-FILE component."
df425d9 @brown README: Update the build instructions and test instructions.
authored
101 (if (proto-pathname protobuf-source-file)
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
102 ;; Path of the protobuf file was specified with :PROTO-PATHNAME.
103 (merge-pathnames
104 (make-pathname :type "proto")
df425d9 @brown README: Update the build instructions and test instructions.
authored
105 (merge-pathnames (pathname (proto-pathname protobuf-source-file))
c0cba28 @brown Stop using internal function asdf::component-parent-pathname. Ensure th...
authored
106 (component-pathname (component-parent protobuf-source-file))))
17a1bcc @brown Compiling proto files depends package, wire-format, etc. being loaded, n...
authored
107 ;; No :PROTO-PATHNAME was specified, so the path of the protobuf
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
108 ;; defaults to that of the Lisp file, but with a ".proto" suffix.
df425d9 @brown README: Update the build instructions and test instructions.
authored
109 (let ((lisp-pathname (component-pathname protobuf-source-file)))
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
110 (merge-pathnames (make-pathname :type "proto") lisp-pathname))))
111
df425d9 @brown README: Update the build instructions and test instructions.
authored
112 (defmethod input-files ((operation proto-to-lisp) (component protobuf-source-file))
354d9b6 @brown Update for latest Gogole protoc. Use protoc-gen-lisp in PATH.
authored
113 (list (proto-input component)))
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
114
df425d9 @brown README: Update the build instructions and test instructions.
authored
115 (defmethod output-files ((operation proto-to-lisp) (component protobuf-source-file))
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
116 "Arranges for the Lisp output file of PROTO-TO-LISP operations to be stored
117 where fasl files are located."
41ada93 @brown For ASDF 2 perform methods must determine output files by calling
authored
118 (values (list (component-pathname component))
a06b162 @brown The temporary Lisp source files produced by PROTO-TO-LISP operations are...
authored
119 nil)) ; allow around methods to translate
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
120
958b891 @brown README:
authored
121 (defun resolve-relative-pathname (path parent-path)
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
122 "When PATH doesn't have an absolute directory component, treat it as relative
123 to PARENT-PATH."
958b891 @brown README:
authored
124 (let* ((pathname (pathname path))
125 (directory (pathname-directory pathname)))
126 (if (and (list directory) (eq (car directory) :absolute))
127 pathname
128 (let ((resolved-path (merge-pathnames pathname parent-path)))
129 (make-pathname :directory (pathname-directory resolved-path)
130 :name nil
131 :type nil
132 :defaults resolved-path)))))
133
df425d9 @brown README: Update the build instructions and test instructions.
authored
134 (defun resolve-search-path (protobuf-source-file)
135 (let ((search-path (search-path protobuf-source-file)))
136 (let ((parent-path (component-pathname (component-parent protobuf-source-file))))
958b891 @brown README:
authored
137 (mapcar (lambda (path)
138 (resolve-relative-pathname path parent-path))
139 search-path))))
140
2e5aa99 @brown Improve error reporting for failed proto file translation.
authored
141 (define-condition protobuf-compile-failed (compile-failed)
142 ((shell-command :reader shell-command
143 :initarg :shell-command))
144 (:report (lambda (condition stream)
145 (format stream "~@<Error while invoking ~A on ~A. Failed shell command: ~S~@:>"
146 (error-operation condition) (error-component condition)
147 (shell-command condition))))
148 (:documentation "Condition signalled when translating a .proto file into Lisp code fails."))
149
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
150 ;; TODO(brown): This before method would not be needed if PROTO-TO-LISP were a subclass of
151 ;; COMPILE-OP. Should we make that change?
c0cba28 @brown Stop using internal function asdf::component-parent-pathname. Ensure th...
authored
152
153 (defmethod perform :before ((operation proto-to-lisp) (component protobuf-source-file))
154 (map nil #'ensure-directories-exist (output-files operation component)))
155
df425d9 @brown README: Update the build instructions and test instructions.
authored
156 (defmethod perform ((operation proto-to-lisp) (component protobuf-source-file))
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
157 (let* ((source-file (proto-input component))
da7eaa9 @brown Add asdf:*PROTOC-RELATIVE-PATH* to control whether a relative or absolut...
authored
158 (source-file-argument (if *protoc-relative-path*
159 (file-namestring source-file)
160 (namestring source-file)))
819368c @brown Use config packages. *protoc* and *protoc-gen-lisp* move from ASDF to
authored
161 ;; Around methods on output-file may globally redirect output products, so we must call
162 ;; that method instead of executing (component-pathname component).
41ada93 @brown For ASDF 2 perform methods must determine output files by calling
authored
163 (output-file (first (output-files operation component)))
958b891 @brown README:
authored
164 (search-path (cons (directory-namestring source-file) (resolve-search-path component)))
354d9b6 @brown Update for latest Gogole protoc. Use protoc-gen-lisp in PATH.
authored
165 (command (format nil "protoc --proto_path=~{~A~^:~} --lisp_out=~A ~A"
2e5aa99 @brown Improve error reporting for failed proto file translation.
authored
166 search-path
167 (directory-namestring output-file)
354d9b6 @brown Update for latest Gogole protoc. Use protoc-gen-lisp in PATH.
authored
168 source-file-argument)))
169 (multiple-value-bind (output error-output status)
170 (uiop:run-program command :output t :error-output :output :ignore-error-status t)
171 (unless (zerop status)
172 (error 'protobuf-compile-failed
173 :component component :operation operation :shell-command command)))))
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
174
a06b162 @brown The temporary Lisp source files produced by PROTO-TO-LISP operations are...
authored
175 (defmethod asdf::component-self-dependencies :around ((op load-op) (c protobuf-source-file))
5b32488 @brown unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.
authored
176 "Removes PROTO-TO-LISP operations from self dependencies. Otherwise, the Lisp
177 output files of PROTO-TO-LISP are considered to be input files for LOAD-OP,
178 which means ASDF loads both the .lisp file and the .fasl file."
9ef17d8 Handle proto files with one ASDF component instead of two.
Robert Brown authored
179 (remove-if (lambda (x)
180 (eq (car x) 'proto-to-lisp))
181 (call-next-method)))
182
41aaee9 @brown With ASDF 3 our redefinition of PERFORM when called with a COMPILE-OP an...
authored
183 (defmethod input-files ((operation compile-op) (c protobuf-source-file))
184 (output-files 'proto-to-lisp c))
185
926fb1a @brown Switch to new optimization scheme, where the compiler optimization level
authored
186 (in-package #:asdf/user)
187
5d1a426 Initial commit of Common Lisp protocol buffer project.
Robert Brown authored
188 (defsystem protobuf
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
189 :name "Protocol Buffer"
190 :description "Protocol buffer code"
0ed9244 @brown Use nibbles to serialize floating point values.
authored
191 :long-description
192 "A Common Lisp implementation of Google's protocol buffer serialization libraries."
cf38369 @brown Increase version number.
authored
193 :version "0.9.1"
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
194 :author "Robert Brown"
bee6f8a @brown protobuf.asd: correct spelling of license
authored
195 :license "See file COPYING and the copyright messages in individual files."
926fb1a @brown Switch to new optimization scheme, where the compiler optimization level
authored
196 :defsystem-depends-on (com.google.base)
9812d7c @brown Remove unneeded uses of "#:" in ASDF files.
authored
197 :depends-on (com.google.base
198 varint
199 #-(or allegro clisp sbcl) trivial-utf-8)
200 :in-order-to ((test-op (test-op protobuf-test)))
d38e61a move zig zag encoding functions to a new package, wire-format
Robert Brown authored
201 :components
202 ((:static-file "COPYING")
203 (:static-file "README")
204 (:static-file "TODO")
15b121b @brown Move base and varint code into separate directories with their own ASDF
authored
205 (:file "package")
206 (:file "protocol-buffer" :depends-on ("package"))
0ed9244 @brown Use nibbles to serialize floating point values.
authored
207 (:fast-unsafe-source-file "wire-format" :depends-on ("package"))))
Something went wrong with that request. Please try again.