ProtocolBuffers.build 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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"
  69. description="Removes built binaries (of all configurations) and the source generation directory">
  70. <delete>
  71. <fileset>
  72. <include name="${src}/ProtoGen/bin/**" />
  73. <include name="${src}/ProtoGen/obj/**" />
  74. <include name="${src}/ProtoGen.Test/bin/**" />
  75. <include name="${src}/ProtoGen.Test/obj/**" />
  76. <include name="${src}/ProtocolBuffers/bin/**" />
  77. <include name="${src}/ProtocolBuffers/obj/**" />
  78. <include name="${src}/ProtocolBuffers.Test/bin/**" />
  79. <include name="${src}/ProtocolBuffers.Test/obj/**" />
  80. <include name="${tmp-dir}" />
  81. <include name="${output-dir}" />
  82. </fileset>
  83. </delete>
  84. </target>
  85. <target name="generate-source"
  86. description="Generate source (unit tests, core messages etc). Does not copy source.">
  87. <fail message="protoc and protogen must both exist"
  88. unless="${file::exists(tools-protoc) and file::exists(tools-protogen)}" />
  89. <delete dir="${tmp-dir}" />
  90. <mkdir dir="${tmp-dir}" />
  91. <exec program="${tools-protoc}"
  92. workingdir="${tmp-dir}">
  93. <arg value="--proto_path=${protos-dir}" />
  94. <arg value="--descriptor_set_out=compiled.pb" />
  95. <arg file="${protos-dir}/google/protobuf/descriptor.proto" />
  96. <arg file="${protos-dir}/google/protobuf/csharp_options.proto" />
  97. <arg file="${protos-dir}/google/protobuf/unittest.proto" />
  98. <arg file="${protos-dir}/google/protobuf/unittest_csharp_options.proto" />
  99. <arg file="${protos-dir}/google/protobuf/unittest_custom_options.proto" />
  100. <arg file="${protos-dir}/google/protobuf/unittest_embed_optimize_for.proto" />
  101. <arg file="${protos-dir}/google/protobuf/unittest_import.proto" />
  102. <arg file="${protos-dir}/google/protobuf/unittest_mset.proto" />
  103. <arg file="${protos-dir}/google/protobuf/unittest_optimize_for.proto" />
  104. <arg file="${protos-dir}/tutorial/addressbook.proto" />
  105. </exec>
  106. <exec program="${tools-protogen}"
  107. workingdir="${tmp-dir}">
  108. <arg value="compiled.pb" />
  109. </exec>
  110. </target>
  111. <target name="copy-generated-source"
  112. description="Copies generated source from temporary directory to source tree. Use with care!">
  113. <copy todir="${src}/ProtocolBuffers/DescriptorProtos">
  114. <fileset basedir="${tmp-dir}">
  115. <include name="DescriptorProtoFile.cs" />
  116. <include name="CSharpOptions.cs" />
  117. </fileset>
  118. </copy>
  119. <copy todir="${src}/ProtocolBuffers.Test/TestProtos">
  120. <fileset basedir="${tmp-dir}">
  121. <include name="UnitTestProtoFile.cs" />
  122. <include name="UnitTestCSharpOptionsProtoFile.cs" />
  123. <include name="UnitTestCustomOptionsProtoFile.cs" />
  124. <include name="UnitTestEmbedOptimizeForProtoFile.cs" />
  125. <include name="UnitTestImportProtoFile.cs" />
  126. <include name="UnitTestMessageSetProtoFile.cs" />
  127. <include name="UnitTestOptimizeForProtoFile.cs" />
  128. </fileset>
  129. </copy>
  130. <copy todir="${src}/AddressBook">
  131. <fileset basedir="${tmp-dir}">
  132. <include name="AddressBookProtos.cs" />
  133. </fileset>
  134. </copy>
  135. </target>
  136. <target name="build"
  137. description="Builds all C# code">
  138. <msbuild project="${src}/ProtocolBuffers.sln">
  139. <property name="Configuration"
  140. value="${build-configuration}" />
  141. </msbuild>
  142. </target>
  143. <target name="benchmark" description="Builds and runs benchmarks">
  144. <delete dir="${benchmark-run-dir}" />
  145. <mkdir dir="${benchmark-run-dir}" />
  146. <!-- Generate benchmark source files -->
  147. <exec program="${tools-protoc}"
  148. workingdir="${benchmark-run-dir}">
  149. <arg value="--proto_path=${benchmark-data-dir};${protos-dir}" />
  150. <arg value="--include_imports=compiled.pb" />
  151. <arg value="--descriptor_set_out=compiled.pb" />
  152. <arg file="${benchmark-data-dir}/google_size.proto" />
  153. <arg file="${benchmark-data-dir}/google_speed.proto" />
  154. </exec>
  155. <exec program="${tools-protogen}"
  156. workingdir="${benchmark-run-dir}">
  157. <arg value="compiled.pb" />
  158. </exec>
  159. <!-- Build them into a library -->
  160. <csc target="library"
  161. output="${benchmark-run-dir}/BenchmarkTypes.dll"
  162. optimize="true">
  163. <sources>
  164. <include name="${benchmark-run-dir}/GoogleSizeProtoFile.cs" />
  165. <include name="${benchmark-run-dir}/GoogleSpeedProtoFile.cs" />
  166. </sources>
  167. <references>
  168. <include name="${src}/ProtocolBuffers/bin/${build-configuration}/Google.ProtocolBuffers.dll" />
  169. </references>
  170. </csc>
  171. <!-- Copy everything we need into the same directory -->
  172. <copy todir="${benchmark-run-dir}" flatten="true">
  173. <fileset>
  174. <include name="${src}/ProtocolBuffers/bin/${build-configuration}/Google.ProtocolBuffers.dll" />
  175. <include name="${src}/ProtoBench/bin/${build-configuration}/ProtoBench.exe" />
  176. <include name="${benchmark-data-dir}/google_message1.dat" />
  177. <include name="${benchmark-data-dir}/google_message2.dat" />
  178. </fileset>
  179. </copy>
  180. <!-- Run! -->
  181. <exec program="${benchmark-run-dir}/ProtoBench.exe"
  182. workingdir="${benchmark-run-dir}"
  183. output="${benchmark-run-dir}/results.txt">
  184. <arg value="Google.ProtocolBuffers.ProtoBench.SizeMessage1,BenchmarkTypes" />
  185. <arg value="google_message1.dat" />
  186. <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage1,BenchmarkTypes" />
  187. <arg value="google_message1.dat" />
  188. <arg value="Google.ProtocolBuffers.ProtoBench.SizeMessage2,BenchmarkTypes" />
  189. <arg value="google_message2.dat" />
  190. <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage2,BenchmarkTypes" />
  191. <arg value="google_message2.dat" />
  192. </exec>
  193. </target>
  194. <target name="test"
  195. description="Runs all unit tests">
  196. <nunit2>
  197. <formatter type="Plain" />
  198. <test assemblyname="${src}/ProtocolBuffers.Test/bin/${build-configuration}/Google.ProtocolBuffers.Test.dll" />
  199. <test assemblyname="${src}/Protogen.Test/bin/${build-configuration}/Google.ProtocolBuffers.ProtoGen.Test.dll" />
  200. </nunit2>
  201. </target>
  202. <target name="dist"
  203. description="Copies compiled binaries into the output directory">
  204. <delete dir="${output-dir}" />
  205. <mkdir dir="${output-dir}" />
  206. <copy todir="${output-dir}"
  207. flatten="true">
  208. <fileset basedir="${src}">
  209. <include name="ProtocolBuffers/bin/${build-configuration}/Google.ProtocolBuffers.dll" />
  210. <include name="ProtoGen/bin/${build-configuration}/ProtoGen.exe" />
  211. <include name="ProtoMunge/bin/${build-configuration}/ProtoMunge.exe" />
  212. <include name="ProtoDump/bin/${build-configuration}/ProtoDump.exe" />
  213. <include name="ProtoBench/bin/${build-configuration}/ProtoBench.exe" />
  214. </fileset>
  215. </copy>
  216. </target>
  217. </project>