Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8" ?>
- - <project name="athena-project-build" default="deploy">
- <property file="${user.home}/wpilib/java/${version}/ant/ni_image.properties" />
- - <!-- Load Tasks
- -->
- - <taskdef resource="net/sf/antcontrib/antlib.xml">
- - <classpath>
- <pathelement location="${wpilib.ant.dir}/ant-contrib.jar" />
- </classpath>
- </taskdef>
- <taskdef resource="net/jtools/classloadertask/antlib.xml" classpath="${classloadertask.jar}" />
- <classloader loader="system" classpath="${jsch.jar}" />
- - <target name="clean" description="Clean up all build and distribution artifacts.">
- <delete dir="${build.dir}" />
- <delete dir="${dist.dir}" />
- </target>
- - <!-- Targets
- -->
- - <target name="get-target-ip">
- <property name="ant.enable.asserts" value="true" />
- <assert name="team-number" exists="true" message="Team number not set. Go to Window->Preferences->WPILib Preferences to set it." />
- <echo>Finding roboRIO, please ignore any [hostinfo] error messages</echo>
- <var name="target" unset="true" />
- - <trycatch>
- - <try>
- - <parallel failonany="true">
- - <sequential>
- <echo>Trying mDNS: roboRIO-${team-number}-FRC.local</echo>
- <hostinfo prefix="targethost_local" host="roboRIO-${team-number}-FRC.local" />
- - <if>
- - <not>
- <equals arg1="${targethost_local.ADDR4}" arg2="0.0.0.0" />
- </not>
- - <then>
- <echo>Resolved mDNS to ${targethost_local.ADDR4}</echo>
- - <if>
- <socket server="${targethost_local.ADDR4}" port="80" />
- - <then>
- <property name="target" value="${targethost_local.ADDR4}" />
- <fail>${targethost_local.ADDR4}</fail>
- </then>
- </if>
- </then>
- </if>
- </sequential>
- - <sequential>
- <echo>Trying DNS: roboRIO-${team-number}-FRC.lan</echo>
- <hostinfo prefix="targethost_lan" host="roboRIO-${team-number}-FRC.lan" />
- - <if>
- - <not>
- <equals arg1="${targethost_lan.ADDR4}" arg2="0.0.0.0" />
- </not>
- - <then>
- <echo>Resolved DNS to ${targethost_lan.ADDR4}</echo>
- - <if>
- <socket server="${targethost_lan.ADDR4}" port="80" />
- - <then>
- <property name="target" value="${targethost_lan.ADDR4}" />
- <fail>${targethost_lan.ADDR4}</fail>
- </then>
- </if>
- </then>
- </if>
- </sequential>
- - <sequential>
- <echo>Trying USB: 172.22.11.2</echo>
- - <if>
- <socket server="172.22.11.2" port="80" />
- - <then>
- <property name="target" value="172.22.11.2" />
- <fail>172.22.11.2</fail>
- </then>
- </if>
- </sequential>
- - <sequential>
- <math result="ip.upper" operand1="${team-number}" operation="/" operand2="100" datatype="int" />
- <math result="ip.lower" operand1="${team-number}" operation="%" operand2="100" datatype="int" />
- <property name="targethost_ip" value="10.${ip.upper}.${ip.lower}.2" />
- <echo>Trying Static Ethernet: ${targethost_ip}</echo>
- - <if>
- <socket server="${targethost_ip}" port="80" />
- - <then>
- <property name="target" value="${targethost_ip}" />
- <fail>${targethost_ip}</fail>
- </then>
- </if>
- </sequential>
- - <sequential>
- <sleep seconds="20" />
- <fail />
- </sequential>
- </parallel>
- </try>
- <catch />
- </trycatch>
- - <if>
- <isset property="target" />
- - <then>
- <echo>roboRIO found at ${target}</echo>
- </then>
- - <else>
- <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" />
- </else>
- </if>
- </target>
- - <target name="compile" description="Compile the source code.">
- <mkdir dir="${build.dir}" />
- - <path id="classpath.path">
- <fileset dir="${userLibs.dir}" includes="*.jar" excludes="*-sources.jar,*-javadoc.jar" />
- <fileset file="${wpilib.jar}" />
- <fileset file="${networktables.jar}" />
- <fileset file="${opencv.jar}" />
- <fileset file="${cscore.jar}" />
- <fileset dir="${userLibs}" erroronmissingdir="false" />
- </path>
- <pathconvert property="classpathProp" refid="classpath.path" />
- <echo>[athena-compile] Compiling ${src.dir} with classpath=${classpathProp} to ${build.dir}</echo>
- <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" />
- </target>
- - <target name="jar" depends="compile">
- <echo>[athena-jar] Making jar ${dist.jar}.</echo>
- <mkdir dir="${dist.dir}" />
- <mkdir dir="${build.jars}" />
- <echo>[athena-jar] Copying jars to ${build.jars}.</echo>
- - <copy todir="${build.jars}" flatten="true">
- <path refid="classpath.path" />
- </copy>
- - <jar destfile="${dist.jar}" update="false">
- - <manifest>
- <attribute name="Main-Class" value="edu.wpi.first.wpilibj.RobotBase" />
- <attribute name="Robot-Class" value="${robot.class}" />
- <attribute name="Class-Path" value="." />
- </manifest>
- <fileset dir="${build.dir}" includes="**/*.class" />
- <zipgroupfileset dir="${build.jars}" />
- </jar>
- </target>
- - <!-- We're running a clean here to get around a known ant issue where it does not detected changed constant variables.
- To get around this, we're recompiling the entire project, which is not an issue for most teams. If this is an issue
- for you, you can remove the clean here, just be sure to do a full rebuild after you've changed any constants.
- Reference: http://stackoverflow.com/questions/6430001/ant-doesnt-recompile-constants
- -->
- - <target name="deploy" depends="clean,jar,get-target-ip,dependencies" description="Deploy the jar and start the program running.">
- - <deploy-libs libs.name="WPI_Native_Libraries" libs.basedir="${wpilib.native.lib}" libs.deployDir="${libDeploy.dir}">
- - <libs.local>
- - <fileset id="wpiNativeLibs.local" dir="${wpilib.native.lib}">
- <include name="libHALAthena.so" />
- <include name="libntcore.so" />
- <include name="libwpiutil.so" />
- <include name="libopencv*.so.3.1" />
- <include name="libcscore.so" />
- <include name="libopencv_java310.so" />
- <include name="libwpilibJavaJNI.so" />
- </fileset>
- </libs.local>
- </deploy-libs>
- - <deploy-libs libs.name="User_Libraries" libs.basedir="${userLibs.dir}" libs.deployDir="${libDeploy.dir}">
- - <libs.local>
- - <fileset dir="${userLibs.dir}">
- <include name="**/*.so" />
- </fileset>
- </libs.local>
- </deploy-libs>
- <echo>[athena-deploy] Copying code over.</echo>
- <scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}" password="${password}" trust="true" />
- <sshexec host="${target}" username="${adminUsername}" password="${adminPassword}" trust="true" command="ldconfig" />
- - <!-- Suppress the exit status so that if no netconsole was running then
- it doesn't show up red on the output.
- -->
- <sshexec host="${target}" username="${adminUsername}" password="${adminPassword}" trust="true" failonerror="false" command="killall -q netconsole-host || :" />
- - <deploy-libs libs.name="netconsole-host" libs.basedir="${wpilib.ant.dir}" libs.deployDir="/usr/local/frc/bin">
- - <libs.local>
- - <fileset id="netconsole.local" dir="${wpilib.ant.dir}">
- <include name="netconsole-host" />
- </fileset>
- </libs.local>
- </deploy-libs>
- <scp file="${wpilib.ant.dir}/robotCommand" todir="${username}@${target}:${command.dir}" password="${password}" trust="true" />
- <echo>[athena-deploy] Starting program.</echo>
- <sshexec host="${target}" username="${username}" password="${password}" trust="true" failonerror="false" command="${deploy.kill.command};" />
- <sshexec host="${target}" username="${username}" password="${password}" trust="true" command="sync" />
- </target>
- - <target name="debug-deploy" depends="clean,jar,get-target-ip,dependencies" description="Deploy the jar and start the program running.">
- - <deploy-libs libs.name="WPI_Native_Libraries" libs.basedir="${wpilib.native.lib}" libs.deployDir="${libDeploy.dir}">
- - <libs.local>
- - <fileset id="wpiNativeLibs.local" dir="${wpilib.native.lib}">
- <include name="libHALAthena.so" />
- <include name="libntcore.so" />
- <include name="libwpiutil.so" />
- <include name="libopencv*.so.3.1" />
- <include name="libcscore.so" />
- <include name="libopencv_java310.so" />
- <include name="libwpilibJavaJNI.so" />
- </fileset>
- </libs.local>
- </deploy-libs>
- - <deploy-libs libs.name="User_Libraries" libs.basedir="${userLibs.dir}" libs.deployDir="${libDeploy.dir}">
- - <libs.local>
- - <fileset dir="${userLibs.dir}">
- <include name="**/*.so" />
- </fileset>
- </libs.local>
- </deploy-libs>
- <echo>[athena-deploy] Copying code over.</echo>
- <scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}" password="${password}" trust="true" />
- - <!-- The remoteDebugCommand file is used by /usr/local/frc/bin/frcRunRobot.sh on the roboRIO
- -->
- <scp file="${wpilib.ant.dir}/robotDebugCommand" todir="${username}@${target}:${command.dir}" password="${password}" trust="true" />
- - <!-- The frcdebug file is used as a flag for /usr/local/frc/bin/frcRunRobot.sh to run the robot program in debug mode
- -->
- <scp file="${wpilib.ant.dir}/frcdebug" todir="${username}@${target}:${debug.flag.dir}" password="${password}" trust="true" />
- <sshexec host="${target}" username="${username}" password="${password}" trust="true" command="${debug.flag.command}" />
- <echo>[athena-deploy] Starting Debug program.</echo>
- <sshexec host="${target}" username="${username}" password="${password}" trust="true" failonerror="false" command="${deploy.kill.command}" />
- </target>
- - <!-- Simulate
- -->
- - <target name="jar-for-simulation" depends="compile">
- <echo>[jar-for-simulation] Building jar.</echo>
- - <jar destfile="${simulation.dist.jar}">
- - <manifest>
- <attribute name="Built-By" value="${user.name}" />
- <attribute name="Robot-Class" value="${robot.class}" />
- <attribute name="Main-Class" value="edu.wpi.first.wpilibj.RobotBase" />
- </manifest>
- <fileset dir="${build.dir}" />
- - <zipgroupfileset dir="${wpilib.sim.lib}">
- <include name="**/*.jar" />
- </zipgroupfileset>
- </jar>
- </target>
- - <target name="simulate" depends="jar-for-simulation">
- - <sequential>
- <echo>[simulate] You may now run Gazebo and your DriverStation</echo>
- <echo>[simulate] Running Code.</echo>
- - <java jar="${simulation.dist.jar}" fork="true">
- <jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
- </java>
- </sequential>
- </target>
- - <target name="debug-simulate" depends="jar-for-simulation">
- - <sequential>
- <echo>[simulate] You may now run Gazebo and your DriverStation</echo>
- <echo>[simulate] Running Code In Debug Mode.</echo>
- - <java jar="${simulation.dist.jar}" fork="true">
- <jvmarg value="-Xdebug" />
- <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8348" />
- <jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
- </java>
- </sequential>
- </target>
- - <target name="dependencies" depends="get-target-ip">
- <property name="ant.enable.asserts" value="true" />
- - <post to="http://${target}/nisysapi/server" property="roboRIOSysValuesUTF16" verbose="false" encoding="UTF-16LE" append="false">
- <prop name="Function" value="GetPropertiesOfItem" />
- <prop name="Plugins" value="nisyscfg" />
- <prop name="Items" value="system" />
- </post>
- - <!-- post erroneously turns UTF-16LE 0x0A00 (LF) into non-UTF16
- 0x0D0A00 (CRLF), so do a poor man's conversion from UTF-16 by just
- removing all the nul characters.
- -->
- <propertyregex property="roboRIOSysValues" input="${roboRIOSysValuesUTF16}" regexp="\x00" replace="" global="true" defaultValue="${roboRIOSysValuesUTF16}" />
- <propertyregex property="roboRIOImage" input="${roboRIOSysValues}" regexp="FRC_roboRIO_[0-9]+_v([0-9]+)" select="\1" defaultValue="ImageRegExFail" />
- <propertyregex property="roboRIOImageYear" input="${roboRIOSysValues}" regexp="FRC_roboRIO_([0-9]+)_v" select="\1" defaultValue="ImageRegExFail" />
- - <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.">
- - <bool>
- - <and>
- <contains string="${roboRIOAllowedImages}" substring="${roboRIOImage}" />
- <contains string="${roboRIOAllowedYear}" substring="${roboRIOImageYear}" />
- </and>
- </bool>
- </assert>
- <echo>roboRIO image version validated</echo>
- <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>
- <sshexec host="${target}" username="${username}" password="${password}" trust="true" failonerror="true" command="test -d ${roboRIOJRE.dir}" />
- </target>
- - <!-- libs.name should not contain spaces as it is used to name a file
- -->
- - <macrodef name="deploy-libs">
- <attribute name="libs.name" />
- <attribute name="libs.basedir" />
- <attribute name="libs.deployDir" />
- <element name="libs.local" />
- - <sequential>
- <local name="libs.local.notEmpty" />
- <local name="libs.local.checksum" />
- <local name="libs.deployed.checksum" />
- <local name="libs.local.modified.property" />
- <delete file="@{libs.basedir}/@{libs.name}.properties" />
- <scp file="${adminUsername}@${target}:@{libs.deployDir}/@{libs.name}.properties" todir="@{libs.basedir}" password="${adminPassword}" trust="true" failonerror="false" />
- - <restrict id="libs.local.modified">
- <libs.local />
- - <modified update="true" seldirs="true" cache="propertyfile" algorithm="digest" comparator="equal">
- <param name="cache.cachefile" value="@{libs.basedir}/@{libs.name}.properties" />
- <param name="algorithm.algorithm" value="MD5" />
- </modified>
- </restrict>
- - <pathconvert refid="libs.local.modified" property="libs.local.modified.property" pathsep="," setonempty="false">
- <globmapper from="@{libs.basedir}/*" to="*" handledirsep="true" />
- </pathconvert>
- - <if>
- <isset property="libs.local.modified.property" />
- - <then>
- <echo message="Deploying libraries ${line.separator} ${libs.local.modified.property}" />
- - <scp todir="${adminUsername}@${target}:@{libs.deployDir}" password="${adminPassword}" trust="true">
- <fileset dir="@{libs.basedir}" includes="${libs.local.modified.property}" />
- <fileset file="@{libs.basedir}/@{libs.name}.properties" />
- </scp>
- <sshexec host="${target}" username="${adminUsername}" password="${adminPassword}" trust="true" command="chmod -R +x @{libs.deployDir}" />
- </then>
- </if>
- </sequential>
- </macrodef>
- </project>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement