Advertisement
Guest User

Untitled

a guest
Feb 9th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.49 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. - <project name="athena-project-build" default="deploy">
  3. <property file="${user.home}/wpilib/java/${version}/ant/ni_image.properties" />
  4. - <!-- Load Tasks
  5. -->
  6. - <taskdef resource="net/sf/antcontrib/antlib.xml">
  7. - <classpath>
  8. <pathelement location="${wpilib.ant.dir}/ant-contrib.jar" />
  9. </classpath>
  10. </taskdef>
  11. <taskdef resource="net/jtools/classloadertask/antlib.xml" classpath="${classloadertask.jar}" />
  12. <classloader loader="system" classpath="${jsch.jar}" />
  13. - <target name="clean" description="Clean up all build and distribution artifacts.">
  14. <delete dir="${build.dir}" />
  15. <delete dir="${dist.dir}" />
  16. </target>
  17. - <!-- Targets
  18. -->
  19. - <target name="get-target-ip">
  20. <property name="ant.enable.asserts" value="true" />
  21. <assert name="team-number" exists="true" message="Team number not set. Go to Window->Preferences->WPILib Preferences to set it." />
  22. <echo>Finding roboRIO, please ignore any [hostinfo] error messages</echo>
  23. <var name="target" unset="true" />
  24. - <trycatch>
  25. - <try>
  26. - <parallel failonany="true">
  27. - <sequential>
  28. <echo>Trying mDNS: roboRIO-${team-number}-FRC.local</echo>
  29. <hostinfo prefix="targethost_local" host="roboRIO-${team-number}-FRC.local" />
  30. - <if>
  31. - <not>
  32. <equals arg1="${targethost_local.ADDR4}" arg2="0.0.0.0" />
  33. </not>
  34. - <then>
  35. <echo>Resolved mDNS to ${targethost_local.ADDR4}</echo>
  36. - <if>
  37. <socket server="${targethost_local.ADDR4}" port="80" />
  38. - <then>
  39. <property name="target" value="${targethost_local.ADDR4}" />
  40. <fail>${targethost_local.ADDR4}</fail>
  41. </then>
  42. </if>
  43. </then>
  44. </if>
  45. </sequential>
  46. - <sequential>
  47. <echo>Trying DNS: roboRIO-${team-number}-FRC.lan</echo>
  48. <hostinfo prefix="targethost_lan" host="roboRIO-${team-number}-FRC.lan" />
  49. - <if>
  50. - <not>
  51. <equals arg1="${targethost_lan.ADDR4}" arg2="0.0.0.0" />
  52. </not>
  53. - <then>
  54. <echo>Resolved DNS to ${targethost_lan.ADDR4}</echo>
  55. - <if>
  56. <socket server="${targethost_lan.ADDR4}" port="80" />
  57. - <then>
  58. <property name="target" value="${targethost_lan.ADDR4}" />
  59. <fail>${targethost_lan.ADDR4}</fail>
  60. </then>
  61. </if>
  62. </then>
  63. </if>
  64. </sequential>
  65. - <sequential>
  66. <echo>Trying USB: 172.22.11.2</echo>
  67. - <if>
  68. <socket server="172.22.11.2" port="80" />
  69. - <then>
  70. <property name="target" value="172.22.11.2" />
  71. <fail>172.22.11.2</fail>
  72. </then>
  73. </if>
  74. </sequential>
  75. - <sequential>
  76. <math result="ip.upper" operand1="${team-number}" operation="/" operand2="100" datatype="int" />
  77. <math result="ip.lower" operand1="${team-number}" operation="%" operand2="100" datatype="int" />
  78. <property name="targethost_ip" value="10.${ip.upper}.${ip.lower}.2" />
  79. <echo>Trying Static Ethernet: ${targethost_ip}</echo>
  80. - <if>
  81. <socket server="${targethost_ip}" port="80" />
  82. - <then>
  83. <property name="target" value="${targethost_ip}" />
  84. <fail>${targethost_ip}</fail>
  85. </then>
  86. </if>
  87. </sequential>
  88. - <sequential>
  89. <sleep seconds="20" />
  90. <fail />
  91. </sequential>
  92. </parallel>
  93. </try>
  94. <catch />
  95. </trycatch>
  96. - <if>
  97. <isset property="target" />
  98. - <then>
  99. <echo>roboRIO found at ${target}</echo>
  100. </then>
  101. - <else>
  102. <assert name="roboRIOFound" message="roboRIO not found, please check that the roboRIO is connected, imaged and that the team number is set properly in Eclipse" />
  103. </else>
  104. </if>
  105. </target>
  106. - <target name="compile" description="Compile the source code.">
  107. <mkdir dir="${build.dir}" />
  108. - <path id="classpath.path">
  109. <fileset dir="${userLibs.dir}" includes="*.jar" excludes="*-sources.jar,*-javadoc.jar" />
  110. <fileset file="${wpilib.jar}" />
  111. <fileset file="${networktables.jar}" />
  112. <fileset file="${opencv.jar}" />
  113. <fileset file="${cscore.jar}" />
  114. <fileset dir="${userLibs}" erroronmissingdir="false" />
  115. </path>
  116. <pathconvert property="classpathProp" refid="classpath.path" />
  117. <echo>[athena-compile] Compiling ${src.dir} with classpath=${classpathProp} to ${build.dir}</echo>
  118. <javac srcdir="${src.dir}" destdir="${build.dir}" includeAntRuntime="no" includeJavaRuntime="no" classpathref="classpath.path" target="${ant.java.version}" source="${ant.java.version}" compiler="javac${ant.java.version}" debug="true" />
  119. </target>
  120. - <target name="jar" depends="compile">
  121. <echo>[athena-jar] Making jar ${dist.jar}.</echo>
  122. <mkdir dir="${dist.dir}" />
  123. <mkdir dir="${build.jars}" />
  124. <echo>[athena-jar] Copying jars to ${build.jars}.</echo>
  125. - <copy todir="${build.jars}" flatten="true">
  126. <path refid="classpath.path" />
  127. </copy>
  128. - <jar destfile="${dist.jar}" update="false">
  129. - <manifest>
  130. <attribute name="Main-Class" value="edu.wpi.first.wpilibj.RobotBase" />
  131. <attribute name="Robot-Class" value="${robot.class}" />
  132. <attribute name="Class-Path" value="." />
  133. </manifest>
  134. <fileset dir="${build.dir}" includes="**/*.class" />
  135. <zipgroupfileset dir="${build.jars}" />
  136. </jar>
  137. </target>
  138. - <!-- We're running a clean here to get around a known ant issue where it does not detected changed constant variables.
  139. To get around this, we're recompiling the entire project, which is not an issue for most teams. If this is an issue
  140. for you, you can remove the clean here, just be sure to do a full rebuild after you've changed any constants.
  141. Reference: http://stackoverflow.com/questions/6430001/ant-doesnt-recompile-constants
  142. -->
  143. - <target name="deploy" depends="clean,jar,get-target-ip,dependencies" description="Deploy the jar and start the program running.">
  144. - <deploy-libs libs.name="WPI_Native_Libraries" libs.basedir="${wpilib.native.lib}" libs.deployDir="${libDeploy.dir}">
  145. - <libs.local>
  146. - <fileset id="wpiNativeLibs.local" dir="${wpilib.native.lib}">
  147. <include name="libHALAthena.so" />
  148. <include name="libntcore.so" />
  149. <include name="libwpiutil.so" />
  150. <include name="libopencv*.so.3.1" />
  151. <include name="libcscore.so" />
  152. <include name="libopencv_java310.so" />
  153. <include name="libwpilibJavaJNI.so" />
  154. </fileset>
  155. </libs.local>
  156. </deploy-libs>
  157. - <deploy-libs libs.name="User_Libraries" libs.basedir="${userLibs.dir}" libs.deployDir="${libDeploy.dir}">
  158. - <libs.local>
  159. - <fileset dir="${userLibs.dir}">
  160. <include name="**/*.so" />
  161. </fileset>
  162. </libs.local>
  163. </deploy-libs>
  164. <echo>[athena-deploy] Copying code over.</echo>
  165. <scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}" password="${password}" trust="true" />
  166. <sshexec host="${target}" username="${adminUsername}" password="${adminPassword}" trust="true" command="ldconfig" />
  167. - <!-- Suppress the exit status so that if no netconsole was running then
  168. it doesn't show up red on the output.
  169. -->
  170. <sshexec host="${target}" username="${adminUsername}" password="${adminPassword}" trust="true" failonerror="false" command="killall -q netconsole-host || :" />
  171. - <deploy-libs libs.name="netconsole-host" libs.basedir="${wpilib.ant.dir}" libs.deployDir="/usr/local/frc/bin">
  172. - <libs.local>
  173. - <fileset id="netconsole.local" dir="${wpilib.ant.dir}">
  174. <include name="netconsole-host" />
  175. </fileset>
  176. </libs.local>
  177. </deploy-libs>
  178. <scp file="${wpilib.ant.dir}/robotCommand" todir="${username}@${target}:${command.dir}" password="${password}" trust="true" />
  179. <echo>[athena-deploy] Starting program.</echo>
  180. <sshexec host="${target}" username="${username}" password="${password}" trust="true" failonerror="false" command="${deploy.kill.command};" />
  181. <sshexec host="${target}" username="${username}" password="${password}" trust="true" command="sync" />
  182. </target>
  183. - <target name="debug-deploy" depends="clean,jar,get-target-ip,dependencies" description="Deploy the jar and start the program running.">
  184. - <deploy-libs libs.name="WPI_Native_Libraries" libs.basedir="${wpilib.native.lib}" libs.deployDir="${libDeploy.dir}">
  185. - <libs.local>
  186. - <fileset id="wpiNativeLibs.local" dir="${wpilib.native.lib}">
  187. <include name="libHALAthena.so" />
  188. <include name="libntcore.so" />
  189. <include name="libwpiutil.so" />
  190. <include name="libopencv*.so.3.1" />
  191. <include name="libcscore.so" />
  192. <include name="libopencv_java310.so" />
  193. <include name="libwpilibJavaJNI.so" />
  194. </fileset>
  195. </libs.local>
  196. </deploy-libs>
  197. - <deploy-libs libs.name="User_Libraries" libs.basedir="${userLibs.dir}" libs.deployDir="${libDeploy.dir}">
  198. - <libs.local>
  199. - <fileset dir="${userLibs.dir}">
  200. <include name="**/*.so" />
  201. </fileset>
  202. </libs.local>
  203. </deploy-libs>
  204. <echo>[athena-deploy] Copying code over.</echo>
  205. <scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}" password="${password}" trust="true" />
  206. - <!-- The remoteDebugCommand file is used by /usr/local/frc/bin/frcRunRobot.sh on the roboRIO
  207. -->
  208. <scp file="${wpilib.ant.dir}/robotDebugCommand" todir="${username}@${target}:${command.dir}" password="${password}" trust="true" />
  209. - <!-- The frcdebug file is used as a flag for /usr/local/frc/bin/frcRunRobot.sh to run the robot program in debug mode
  210. -->
  211. <scp file="${wpilib.ant.dir}/frcdebug" todir="${username}@${target}:${debug.flag.dir}" password="${password}" trust="true" />
  212. <sshexec host="${target}" username="${username}" password="${password}" trust="true" command="${debug.flag.command}" />
  213. <echo>[athena-deploy] Starting Debug program.</echo>
  214. <sshexec host="${target}" username="${username}" password="${password}" trust="true" failonerror="false" command="${deploy.kill.command}" />
  215. </target>
  216. - <!-- Simulate
  217. -->
  218. - <target name="jar-for-simulation" depends="compile">
  219. <echo>[jar-for-simulation] Building jar.</echo>
  220. - <jar destfile="${simulation.dist.jar}">
  221. - <manifest>
  222. <attribute name="Built-By" value="${user.name}" />
  223. <attribute name="Robot-Class" value="${robot.class}" />
  224. <attribute name="Main-Class" value="edu.wpi.first.wpilibj.RobotBase" />
  225. </manifest>
  226. <fileset dir="${build.dir}" />
  227. - <zipgroupfileset dir="${wpilib.sim.lib}">
  228. <include name="**/*.jar" />
  229. </zipgroupfileset>
  230. </jar>
  231. </target>
  232. - <target name="simulate" depends="jar-for-simulation">
  233. - <sequential>
  234. <echo>[simulate] You may now run Gazebo and your DriverStation</echo>
  235. <echo>[simulate] Running Code.</echo>
  236. - <java jar="${simulation.dist.jar}" fork="true">
  237. <jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
  238. </java>
  239. </sequential>
  240. </target>
  241. - <target name="debug-simulate" depends="jar-for-simulation">
  242. - <sequential>
  243. <echo>[simulate] You may now run Gazebo and your DriverStation</echo>
  244. <echo>[simulate] Running Code In Debug Mode.</echo>
  245. - <java jar="${simulation.dist.jar}" fork="true">
  246. <jvmarg value="-Xdebug" />
  247. <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8348" />
  248. <jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
  249. </java>
  250. </sequential>
  251. </target>
  252. - <target name="dependencies" depends="get-target-ip">
  253. <property name="ant.enable.asserts" value="true" />
  254. - <post to="http://${target}/nisysapi/server" property="roboRIOSysValuesUTF16" verbose="false" encoding="UTF-16LE" append="false">
  255. <prop name="Function" value="GetPropertiesOfItem" />
  256. <prop name="Plugins" value="nisyscfg" />
  257. <prop name="Items" value="system" />
  258. </post>
  259. - <!-- post erroneously turns UTF-16LE 0x0A00 (LF) into non-UTF16
  260. 0x0D0A00 (CRLF), so do a poor man's conversion from UTF-16 by just
  261. removing all the nul characters.
  262. -->
  263. <propertyregex property="roboRIOSysValues" input="${roboRIOSysValuesUTF16}" regexp="\x00" replace="" global="true" defaultValue="${roboRIOSysValuesUTF16}" />
  264. <propertyregex property="roboRIOImage" input="${roboRIOSysValues}" regexp="FRC_roboRIO_[0-9]+_v([0-9]+)" select="\1" defaultValue="ImageRegExFail" />
  265. <propertyregex property="roboRIOImageYear" input="${roboRIOSysValues}" regexp="FRC_roboRIO_([0-9]+)_v" select="\1" defaultValue="ImageRegExFail" />
  266. - <assert message="Image of roboRIO does not match plugin. ${line.separator}Allowed image year: ${roboRIOAllowedYear} version: ${roboRIOAllowedImages}. ${line.separator}Actual image year: ${roboRIOImageYear} version ${roboRIOImage}. ${line.separator}RoboRIO needs to be re-imaged or plugins updated.">
  267. - <bool>
  268. - <and>
  269. <contains string="${roboRIOAllowedImages}" substring="${roboRIOImage}" />
  270. <contains string="${roboRIOAllowedYear}" substring="${roboRIOImageYear}" />
  271. </and>
  272. </bool>
  273. </assert>
  274. <echo>roboRIO image version validated</echo>
  275. <echo>Checking for JRE. If this fails install the JRE using these instructions: https://wpilib.screenstepslive.com/s/4485/m/13503/l/288822-installing-java-8-on-the-roborio-using-the-frc-roborio-java-installer-java-only</echo>
  276. <sshexec host="${target}" username="${username}" password="${password}" trust="true" failonerror="true" command="test -d ${roboRIOJRE.dir}" />
  277. </target>
  278. - <!-- libs.name should not contain spaces as it is used to name a file
  279. -->
  280. - <macrodef name="deploy-libs">
  281. <attribute name="libs.name" />
  282. <attribute name="libs.basedir" />
  283. <attribute name="libs.deployDir" />
  284. <element name="libs.local" />
  285. - <sequential>
  286. <local name="libs.local.notEmpty" />
  287. <local name="libs.local.checksum" />
  288. <local name="libs.deployed.checksum" />
  289. <local name="libs.local.modified.property" />
  290. <delete file="@{libs.basedir}/@{libs.name}.properties" />
  291. <scp file="${adminUsername}@${target}:@{libs.deployDir}/@{libs.name}.properties" todir="@{libs.basedir}" password="${adminPassword}" trust="true" failonerror="false" />
  292. - <restrict id="libs.local.modified">
  293. <libs.local />
  294. - <modified update="true" seldirs="true" cache="propertyfile" algorithm="digest" comparator="equal">
  295. <param name="cache.cachefile" value="@{libs.basedir}/@{libs.name}.properties" />
  296. <param name="algorithm.algorithm" value="MD5" />
  297. </modified>
  298. </restrict>
  299. - <pathconvert refid="libs.local.modified" property="libs.local.modified.property" pathsep="," setonempty="false">
  300. <globmapper from="@{libs.basedir}/*" to="*" handledirsep="true" />
  301. </pathconvert>
  302. - <if>
  303. <isset property="libs.local.modified.property" />
  304. - <then>
  305. <echo message="Deploying libraries ${line.separator} ${libs.local.modified.property}" />
  306. - <scp todir="${adminUsername}@${target}:@{libs.deployDir}" password="${adminPassword}" trust="true">
  307. <fileset dir="@{libs.basedir}" includes="${libs.local.modified.property}" />
  308. <fileset file="@{libs.basedir}/@{libs.name}.properties" />
  309. </scp>
  310. <sshexec host="${target}" username="${adminUsername}" password="${adminPassword}" trust="true" command="chmod -R +x @{libs.deployDir}" />
  311. </then>
  312. </if>
  313. </sequential>
  314. </macrodef>
  315. </project>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement