ProtocolBuffers.build 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. <!-- Which version of protogen to use when regenerating source -->
  34. <property name="tools-protogen-config"
  35. value="${build-configuration}"
  36. overwrite="false" />
  37. <property name="tools-protogen"
  38. value="${src}/ProtoGen/bin/${tools-protogen-config}/protogen.exe"
  39. overwrite="false"/>
  40. <property name="tools-protobench" value="${src}/ProtoBench/bin/${build-configuration}/protobench.exe"
  41. overwrite="false"/>
  42. <target name="clean-build"
  43. description="Rebuilds all source and binaries, including distribution">
  44. <!--
  45. - Use call instead of dependencies to make it clear what's going on: we
  46. - need to call some targets multiple times.
  47. -->
  48. <call target="clean" />
  49. <call target="build" />
  50. <call target="generate-source" />
  51. <call target="copy-generated-source" />
  52. <!-- Now we've got fresh source, build again -->
  53. <call target="clean" />
  54. <call target="build" />
  55. <!--
  56. - In particularly insane situations we should possibly do another
  57. - round of generating source and building, but it gets silly.
  58. -->
  59. <call target="test" />
  60. <call target="dist" />
  61. </target>
  62. <target name="clean"
  63. description="Removes built binaries (of all configurations) and the source generation directory">
  64. <delete>
  65. <fileset>
  66. <include name="${src}/ProtoGen/bin/**" />
  67. <include name="${src}/ProtoGen/obj/**" />
  68. <include name="${src}/ProtoGen.Test/bin/**" />
  69. <include name="${src}/ProtoGen.Test/obj/**" />
  70. <include name="${src}/ProtocolBuffers/bin/**" />
  71. <include name="${src}/ProtocolBuffers/obj/**" />
  72. <include name="${src}/ProtocolBuffers.Test/bin/**" />
  73. <include name="${src}/ProtocolBuffers.Test/obj/**" />
  74. <include name="${tmp-dir}" />
  75. <include name="${output-dir}" />
  76. </fileset>
  77. </delete>
  78. </target>
  79. <target name="generate-source"
  80. description="Generate source (unit tests, core messages etc). Does not copy source.">
  81. <fail message="protoc and protogen must both exist"
  82. unless="${file::exists(tools-protoc) and file::exists(tools-protogen)}" />
  83. <delete dir="${tmp-dir}" />
  84. <mkdir dir="${tmp-dir}" />
  85. <exec program="${tools-protoc}"
  86. workingdir="${tmp-dir}">
  87. <arg value="--proto_path=${protos-dir}" />
  88. <arg value="--descriptor_set_out=compiled.pb" />
  89. <arg file="${protos-dir}/google/protobuf/benchmark.proto" />
  90. <arg file="${protos-dir}/google/protobuf/benchmark_speed.proto" />
  91. <arg file="${protos-dir}/google/protobuf/descriptor.proto" />
  92. <arg file="${protos-dir}/google/protobuf/csharp_options.proto" />
  93. <arg file="${protos-dir}/google/protobuf/unittest.proto" />
  94. <arg file="${protos-dir}/google/protobuf/unittest_custom_options.proto" />
  95. <arg file="${protos-dir}/google/protobuf/unittest_embed_optimize_for.proto" />
  96. <arg file="${protos-dir}/google/protobuf/unittest_import.proto" />
  97. <arg file="${protos-dir}/google/protobuf/unittest_mset.proto" />
  98. <arg file="${protos-dir}/google/protobuf/unittest_optimize_for.proto" />
  99. <arg file="${protos-dir}/tutorial/addressbook.proto" />
  100. </exec>
  101. <exec program="${tools-protogen}"
  102. workingdir="${tmp-dir}">
  103. <arg value="compiled.pb" />
  104. </exec>
  105. </target>
  106. <target name="copy-generated-source"
  107. description="Copies generated source from temporary directory to source tree. Use with care!">
  108. <copy todir="${src}/ProtocolBuffers/DescriptorProtos">
  109. <fileset basedir="${tmp-dir}">
  110. <include name="DescriptorProtoFile.cs" />
  111. <include name="CSharpOptions.cs" />
  112. </fileset>
  113. </copy>
  114. <copy todir="${src}/ProtocolBuffers.Test/TestProtos">
  115. <fileset basedir="${tmp-dir}">
  116. <include name="UnitTestProtoFile.cs" />
  117. <include name="UnitTestCustomOptionsProtoFile.cs" />
  118. <include name="UnitTestEmbedOptimizeForProtoFile.cs" />
  119. <include name="UnitTestImportProtoFile.cs" />
  120. <include name="UnitTestMessageSetProtoFile.cs" />
  121. <include name="UnitTestOptimizeForProtoFile.cs" />
  122. </fileset>
  123. </copy>
  124. <copy todir="${src}/AddressBook">
  125. <fileset basedir="${tmp-dir}">
  126. <include name="AddressBookProtos.cs" />
  127. </fileset>
  128. </copy>
  129. <copy todir="${src}/ProtoBench">
  130. <fileset basedir="${tmp-dir}">
  131. <include name="BenchmarkProtoFile.cs" />
  132. <include name="BenchmarkSpeedProtoFile.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="test"
  144. description="Runs all unit tests">
  145. <nunit2>
  146. <formatter type="Plain" />
  147. <test assemblyname="${src}/ProtocolBuffers.Test/bin/${build-configuration}/Google.ProtocolBuffers.Test.dll" />
  148. <test assemblyname="${src}/Protogen.Test/bin/${build-configuration}/Google.ProtocolBuffers.ProtoGen.Test.dll" />
  149. </nunit2>
  150. </target>
  151. <target name="perf-test"
  152. description="Runs all performance tests">
  153. <exec program="${tools-protobench}"
  154. workingdir="${testdata-dir}">
  155. <arg value="Google.ProtocolBuffers.ProtoBench.Message1,ProtoBench" />
  156. <arg value="benchmark_message1.dat" />
  157. <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage1,ProtoBench" />
  158. <arg value="benchmark_message1.dat" />
  159. <arg value="Google.ProtocolBuffers.ProtoBench.Message3,ProtoBench" />
  160. <arg value="benchmark_message3.dat" />
  161. <arg value="Google.ProtocolBuffers.ProtoBench.SpeedMessage3,ProtoBench" />
  162. <arg value="benchmark_message3.dat" />
  163. </exec>
  164. </target>
  165. <target name="dist"
  166. description="Copies compiled binaries into the output directory">
  167. <delete dir="${output-dir}" />
  168. <mkdir dir="${output-dir}" />
  169. <copy todir="${output-dir}"
  170. flatten="true">
  171. <fileset basedir="${src}">
  172. <include name="ProtocolBuffers/bin/${build-configuration}/Google.ProtocolBuffers.dll" />
  173. <include name="ProtoGen/bin/${build-configuration}/ProtoGen.exe" />
  174. <include name="ProtoMunge/bin/${build-configuration}/ProtoMunge.exe" />
  175. <include name="ProtoDump/bin/${build-configuration}/ProtoDump.exe" />
  176. <include name="ProtoBench/bin/${build-configuration}/ProtoBench.exe" />
  177. </fileset>
  178. </copy>
  179. </target>
  180. </project>