ProtocolBuffers.build 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?xml version="1.0"?>
  2. <project name="Protocol Buffers" default="build" basedir=".">
  3. <description>Port of Google's Protocol Buffers to C#/.NET</description>
  4. <!-- NAntContrib configuration. TODO(jonskeet): Improve this? -->
  5. <property name="nantcontrib-dir"
  6. value="${path::combine(nant::get-base-directory(), '../../NAntContrib')}"
  7. overwrite="false" />
  8. <loadtasks assembly="${path::combine(nantcontrib-dir, 'bin/NAnt.Contrib.Tasks.dll')}" />
  9. <property name="build-configuration"
  10. value="Debug"
  11. overwrite="false" />
  12. <property name="src"
  13. value="${project::get-base-directory()}/src" />
  14. <property name="tools-protoc"
  15. value="${project::get-base-directory()}/lib/protoc.exe"
  16. overwrite="false" />
  17. <!-- Output directory for copying generated binaries -->
  18. <property name="output-dir"
  19. value="${path::combine(project::get-base-directory(), 'dist')}"
  20. overwrite="false" />
  21. <!-- Directory to find test data -->
  22. <property name="testdata-dir"
  23. value="${path::combine(project::get-base-directory(), 'testdata')}"
  24. overwrite="false" />
  25. <!-- Base directory to find protos (core, C# options, tests) -->
  26. <property name="protos-dir"
  27. value="${path::combine(project::get-base-directory(), 'protos')}"
  28. overwrite="false" />
  29. <!-- Scratch directory used when generating code -->
  30. <property name="tmp-dir"
  31. value="${path::combine(project::get-base-directory(), 'tmp')}"
  32. overwrite="false" />
  33. <!-- Directory to build and run benchmarks in -->
  34. <property name="benchmark-run-dir"
  35. value="${path::combine(tmp-dir, 'benchmark')}"
  36. overwrite="false" />
  37. <!-- Directory to find benchmark data in -->
  38. <property name="benchmark-data-dir"
  39. value="${path::combine(project::get-base-directory(), 'benchmarks')}"
  40. overwrite="false" />
  41. <!-- Which version of protogen to use when regenerating source -->
  42. <property name="tools-protogen-config"
  43. value="${build-configuration}"
  44. overwrite="false" />
  45. <property name="tools-protogen"
  46. value="${src}/ProtoGen/bin/${tools-protogen-config}/protogen.exe"
  47. overwrite="false"/>
  48. <target name="clean-build"
  49. description="Rebuilds all source and binaries, including distribution">
  50. <!--
  51. - Use call instead of dependencies to make it clear what's going on: we
  52. - need to call some targets multiple times.
  53. -->
  54. <call target="clean" />
  55. <call target="build" />
  56. <call target="generate-source" />
  57. <call target="copy-generated-source" />
  58. <!-- Now we've got fresh source, build again -->
  59. <call target="clean" />
  60. <call target="build" />
  61. <!--
  62. - In particularly insane situations we should possibly do another
  63. - round of generating source and building, but it gets silly.
  64. -->
  65. <call target="test" />
  66. <call target="dist" />
  67. </target>
  68. <target name="clean-build-all"
  69. description="Rebuilds all source and binaries in all configurations, including distribution">
  70. <!--
  71. - Use call instead of dependencies to make it clear what's going on: we
  72. - need to call some targets multiple times.
  73. -->
  74. <call target="clean" />
  75. <call target="build" />
  76. <call target="generate-source" />
  77. <call target="copy-generated-source" />
  78. <!-- Now we've got fresh source, build again -->
  79. <call target="clean" />
  80. <call target="build-all-configs" />
  81. <!--
  82. - In particularly insane situations we should possibly do another
  83. - round of generating source and building, but it gets silly.
  84. -->
  85. <call target="test" />
  86. <call target="dist" />
  87. </target>
  88. <target name="clean"
  89. description="Removes built binaries (of all configurations) and the source generation directory">
  90. <delete>
  91. <fileset>
  92. <include name="${src}/ProtoGen/bin/**" />
  93. <include name="${src}/ProtoGen/obj/**" />
  94. <include name="${src}/ProtoGen.Test/bin/**" />
  95. <include name="${src}/ProtoGen.Test/obj/**" />
  96. <include name="${src}/ProtocolBuffers/bin/**" />
  97. <include name="${src}/ProtocolBuffers/obj/**" />
  98. <include name="${src}/ProtocolBuffers.Test/bin/**" />
  99. <include name="${src}/ProtocolBuffers.Test/obj/**" />
  100. <include name="${tmp-dir}" />
  101. <include name="${output-dir}" />
  102. </fileset>
  103. </delete>
  104. </target>
  105. <target name="generate-source"
  106. description="Generate source (unit tests, core messages etc). Does not copy source.">
  107. <fail message="protoc and protogen must both exist"
  108. unless="${file::exists(tools-protoc) and file::exists(tools-protogen)}" />
  109. <delete dir="${tmp-dir}" />
  110. <mkdir dir="${tmp-dir}" />
  111. <exec program="${tools-protoc}"
  112. workingdir="${tmp-dir}">
  113. <arg value="--proto_path=${protos-dir}" />
  114. <arg value="--descriptor_set_out=compiled.pb" />
  115. <arg file="${protos-dir}/google/protobuf/descriptor.proto" />
  116. <arg file="${protos-dir}/google/protobuf/csharp_options.proto" />
  117. <arg file="${protos-dir}/google/protobuf/unittest.proto" />
  118. <arg file="${protos-dir}/google/protobuf/unittest_csharp_options.proto" />
  119. <arg file="${protos-dir}/google/protobuf/unittest_custom_options.proto" />
  120. <arg file="${protos-dir}/google/protobuf/unittest_embed_optimize_for.proto" />
  121. <arg file="${protos-dir}/google/protobuf/unittest_import.proto" />
  122. <arg file="${protos-dir}/google/protobuf/unittest_mset.proto" />
  123. <arg file="${protos-dir}/google/protobuf/unittest_optimize_for.proto" />
  124. <arg file="${protos-dir}/tutorial/addressbook.proto" />
  125. </exec>
  126. <exec program="${tools-protogen}"
  127. workingdir="${tmp-dir}">
  128. <arg value="compiled.pb" />
  129. </exec>
  130. </target>
  131. <target name="copy-generated-source"
  132. description="Copies generated source from temporary directory to source tree. Use with care!">
  133. <copy todir="${src}/ProtocolBuffers/DescriptorProtos">
  134. <fileset basedir="${tmp-dir}">
  135. <include name="DescriptorProtoFile.cs" />
  136. <include name="CSharpOptions.cs" />
  137. </fileset>
  138. </copy>
  139. <copy todir="${src}/ProtocolBuffers.Test/TestProtos">
  140. <fileset basedir="${tmp-dir}">
  141. <include name="UnitTestProtoFile.cs" />
  142. <include name="UnitTestCSharpOptionsProtoFile.cs" />
  143. <include name="UnitTestCustomOptionsProtoFile.cs" />
  144. <include name="UnitTestEmbedOptimizeForProtoFile.cs" />
  145. <include name="UnitTestImportProtoFile.cs" />
  146. <include name="UnitTestMessageSetProtoFile.cs" />
  147. <include name="UnitTestOptimizeForProtoFile.cs" />
  148. </fileset>
  149. </copy>
  150. <copy todir="${src}/AddressBook">
  151. <fileset basedir="${tmp-dir}">
  152. <include name="AddressBookProtos.cs" />
  153. </fileset>
  154. </copy>
  155. </target>
  156. <target name="build"
  157. description="Builds all C# code">
  158. <msbuild project="${src}/ProtocolBuffers.sln">
  159. <property name="Configuration"
  160. value="${build-configuration}" />
  161. <property name="Platform" value="Any CPU" />
  162. </msbuild>
  163. </target>
  164. <target name="benchmark" description="Builds and runs benchmarks">
  165. <delete dir="${benchmark-run-dir}" />
  166. <mkdir dir="${benchmark-run-dir}" />
  167. <!-- Generate benchmark source files -->
  168. <exec program="${tools-protoc}"
  169. workingdir="${benchmark-run-dir}">
  170. <arg value="--proto_path=${benchmark-data-dir};${protos-dir}" />
  171. <arg value="--include_imports=compiled.pb" />
  172. <arg value="--descriptor_set_out=compiled.pb" />
  173. <arg file="${benchmark-data-dir}/google_size.proto" />
  174. <arg file="${benchmark-data-dir}/google_speed.proto" />
  175. </exec>
  176. <exec program="${tools-protogen}"
  177. workingdir="${benchmark-run-dir}">
  178. <arg value="compiled.pb" />
  179. </exec>
  180. <!-- Build them into a library -->
  181. <csc target="library"
  182. output="${benchmark-run-dir}/BenchmarkTypes.dll"
  183. optimize="true">
  184. <sources>
  185. <include name="${benchmark-run-dir}/GoogleSizeProtoFile.cs" />
  186. <include name="${benchmark-run-dir}/GoogleSpeedProtoFile.cs" />
  187. </sources>
  188. <references>
  189. <include name="${src}/ProtocolBuffers/bin/${build-configuration}/Google.ProtocolBuffers.dll" />
  190. </references>
  191. </csc>
  192. <!-- Copy everything we need into the same directory -->
  193. <copy todir="${benchmark-run-dir}" flatten="true">
  194. <fileset>
  195. <include name="${src}/ProtocolBuffers/bin/${build-configuration}/Google.ProtocolBuffers.dll" />
  196. <include name="${src}/ProtoBench/bin/${build-configuration}/ProtoBench.exe" />
  197. <include name="${benchmark-data-dir}/google_message1.dat" />
  198. <include name="${benchmark-data-dir}/google_message2.dat" />
  199. </fileset>
  200. </copy>
  201. <!-- Run! -->
  202. <exec program="${benchmark-run-dir}/ProtoBench.exe"
  203. workingdir="${benchmark-run-dir}"
  204. output="${benchmark-run-dir}/results.txt">
  205. <arg value="Google.ProtocolBuffers.ProtoBench.SizeMessage1,BenchmarkTypes" />
  206. <arg value="google_message1.dat" />
  207. <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage1,BenchmarkTypes" />
  208. <arg value="google_message1.dat" />
  209. <arg value="Google.ProtocolBuffers.ProtoBench.SizeMessage2,BenchmarkTypes" />
  210. <arg value="google_message2.dat" />
  211. <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage2,BenchmarkTypes" />
  212. <arg value="google_message2.dat" />
  213. </exec>
  214. </target>
  215. <target name="test"
  216. description="Runs all unit tests">
  217. <nunit2>
  218. <formatter type="Plain" />
  219. <test assemblyname="${src}/ProtocolBuffers.Test/bin/${build-configuration}/Google.ProtocolBuffers.Test.dll" />
  220. <test assemblyname="${src}/Protogen.Test/bin/${build-configuration}/Google.ProtocolBuffers.ProtoGen.Test.dll" />
  221. </nunit2>
  222. </target>
  223. <target name="build-all-configs"
  224. description="Builds all versions of the main library">
  225. <msbuild project="${src}/ProtocolBuffers.sln">
  226. <property name="Configuration" value="Debug" />
  227. <property name="Platform" value="Any CPU" />
  228. </msbuild>
  229. <msbuild project="${src}/ProtocolBuffers.sln">
  230. <property name="Configuration" value="Release" />
  231. <property name="Platform" value="Any CPU" />
  232. </msbuild>
  233. <msbuild project="${src}/ProtocolBuffers.sln">
  234. <property name="Configuration" value="Silverlight2" />
  235. <property name="Platform" value="Any CPU" />
  236. </msbuild>
  237. <!-- Note the deliberate lack of space in the platform name -->
  238. <msbuild project="${src}/ProtocolBuffers/ProtocolBuffersCF.csproj">
  239. <property name="Configuration" value="Release" />
  240. <property name="Platform" value="AnyCPU" />
  241. </msbuild>
  242. </target>
  243. <target name="dist"
  244. description="Copies all binaries into the output directory">
  245. <delete dir="${output-dir}" />
  246. <copy todir="${output-dir}">
  247. <fileset basedir="${project::get-base-directory()}">
  248. <include name="readme.txt" />
  249. <include name="license.txt" />
  250. </fileset>
  251. </copy>
  252. <mkdir dir="${output-dir}" />
  253. <mkdir dir="${output-dir}/Protoc" />
  254. <mkdir dir="${output-dir}/Debug" />
  255. <mkdir dir="${output-dir}/Release" />
  256. <mkdir dir="${output-dir}/Silverlight2" />
  257. <mkdir dir="${output-dir}/CompactFramework35" />
  258. <copy todir="${output-dir}/Protoc">
  259. <fileset basedir="${project::get-base-directory()}/lib">
  260. <include name="protoc.exe" />
  261. <include name="protoc-license.txt" />
  262. </fileset>
  263. </copy>
  264. <copy todir="${output-dir}/Debug"
  265. flatten="true">
  266. <fileset basedir="${src}">
  267. <include name="ProtocolBuffers/bin/Debug/Google.ProtocolBuffers.*" />
  268. <include name="ProtoGen/bin/Debug/ProtoGen.*" />
  269. <include name="ProtoMunge/bin/Debug/ProtoMunge.*" />
  270. <include name="ProtoDump/bin/Debug/ProtoDump.*" />
  271. <include name="ProtoBench/bin/Debug/ProtoBench.*" />
  272. <exclude name="**/*vshost*" />
  273. </fileset>
  274. </copy>
  275. <copy todir="${output-dir}/Release"
  276. flatten="true">
  277. <fileset basedir="${src}">
  278. <include name="ProtocolBuffers/bin/Release/Google.ProtocolBuffers.*" />
  279. <include name="ProtoGen/bin/Release/ProtoGen.*" />
  280. <include name="ProtoMunge/bin/Release/ProtoMunge.*" />
  281. <include name="ProtoDump/bin/Release/ProtoDump.*" />
  282. <include name="ProtoBench/bin/Release/ProtoBench.*" />
  283. <exclude name="**/*vshost*" />
  284. </fileset>
  285. </copy>
  286. <copy todir="${output-dir}/Silverlight2"
  287. flatten="true">
  288. <fileset basedir="${src}">
  289. <include name="ProtocolBuffers/bin/Silverlight2/Google.ProtocolBuffers.dll" />
  290. </fileset>
  291. </copy>
  292. <copy todir="${output-dir}/CompactFramework35"
  293. flatten="true">
  294. <fileset basedir="${src}">
  295. <include name="ProtocolBuffers/bin/ReleaseCF/Google.ProtocolBuffers.dll" />
  296. </fileset>
  297. </copy>
  298. <copy todir="${output-dir}">
  299. <fileset basedir="${project::get-base-directory()}">
  300. <include name="protos/**" />
  301. </fileset>
  302. </copy>
  303. </target>
  304. </project>