Fixed wpilibj_frcnetcomm.py and added invocation to Travis (#1106)

Making Travis run wpilibj_frcnetcomm.py will help avoid bitrot in
FRCNetComm.java in the future. Formatting was also enabled on Python
source files and FRCNetComm.java was added back to the generated files
list.
This commit is contained in:
Tyler Veness
2018-05-27 21:53:39 -07:00
committed by Peter Johnson
parent 7c9517ce5b
commit 8958c4eabd
4 changed files with 41 additions and 30 deletions

View File

@@ -12,11 +12,11 @@ generatedFileExclude {
gtest/
ni-libraries/include/
ni-libraries/lib/
FRCNetComm\.java$
}
modifiableFileExclude {
shared/arm-linux-jni/
\.py$
\.so$
}

View File

@@ -36,5 +36,6 @@ cache:
script:
- python3.5 -m wpiformat -y 2018 -clang 5.0
- python3.5 gen/wpilibj_frcnetcomm.py
- git --no-pager diff --exit-code HEAD # Ensure formatter made no changes
- ./gradlew --no-daemon --console=plain -PskipAthena :hal:halSharedLibrary :hal:halJNISharedLibrary :wpilibc:wpilibcSharedLibrary :wpilibj:jar

View File

@@ -10,14 +10,15 @@ import os
import re
import subprocess
# Check that the current directory is part of a Git repository
def inGitRepo(directory):
ret = subprocess.run(["git", "rev-parse"], stderr = subprocess.DEVNULL)
return ret.returncode == 0
def in_git_repo(directory):
return subprocess.run(["git", "rev-parse"]).returncode == 0
def main():
if not inGitRepo("."):
print("Error: not invoked within a Git repository", file = sys.stderr)
if not in_git_repo("."):
print("Error: not invoked within a Git repository", file=sys.stderr)
sys.exit(1)
# Handle running in either the root or gen directories
@@ -26,7 +27,7 @@ def main():
configPath = ".."
outputName = configPath + \
"/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/FRCNetComm.java"
"/hal/src/main/java/edu/wpi/first/wpilibj/hal/FRCNetComm.java"
# Set initial copyright year and get current year
year = "2016"
@@ -41,12 +42,12 @@ def main():
temp.write("*/\n")
# Write second line of comment
temp.write("/* Copyright (c) FIRST ")
temp.write("/* Copyright (c) ")
if year != currentYear:
temp.write(year)
temp.write("-")
temp.write(currentYear)
temp.write(". All Rights Reserved.")
temp.write(" FIRST. All Rights Reserved.")
for i in range(0, 24):
temp.write(" ")
if year == currentYear:
@@ -68,8 +69,6 @@ def main():
temp.write("""
package edu.wpi.first.wpilibj.hal;
import edu.wpi.first.wpilibj.hal.JNIWrapper;
/**
* JNI wrapper for library <b>FRC_NetworkCommunication</b><br>.
*/
@@ -79,14 +78,17 @@ public class FRCNetComm extends JNIWrapper {
# Read enums from C++ source files
firstEnum = True
for fileName in ["LoadOut.h", "UsageReporting.h"]:
with open(configPath + "/hal/include/FRC_NetworkCommunication/" + \
fileName, "r") as cppSource:
files = [
"/ni-libraries/include/FRC_NetworkCommunication/LoadOut.h",
"/hal/src/main/native/include/HAL/UsageReporting.h"
]
for fileName in files:
with open(configPath + fileName, "r") as cppSource:
while True:
# Read until an enum is encountered
line = ""
pos = -1
while line.find("enum") == -1:
while "enum" not in line:
line = cppSource.readline()
if line == "":
break
@@ -95,22 +97,22 @@ public class FRCNetComm extends JNIWrapper {
break
# If "{" is on next line, read next line
if line.find("{") == -1:
if "{" not in line:
line = cppSource.readline()
# Write enum to output file as interface
values = []
line = cppSource.readline()
while line.find("}") == -1:
while "}" not in line:
if line == "\n":
values.append("")
else:
if line[0] != "#":
line = line.strip()
if line[len(line) - 1] == ",":
values.append(line[0:len(line) - 1])
else:
values.append(line)
elif line[0] != "#":
try:
values.append(
re.search("[^,]+", line.strip()).group())
except AttributeError:
# Ignore lines that don't match value regex
pass
line = cppSource.readline()
# Extract enum name
@@ -127,8 +129,7 @@ public class FRCNetComm extends JNIWrapper {
firstEnum = False
else:
temp.write("\n")
temp.write(" /**\n"
" * ")
temp.write(" /**\n * ")
# Splits camelcase string into words
enumCamel = re.findall(r'[A-Z](?:[a-z]+|[A-Z]*(?=[A-Z]|$))',
@@ -137,7 +138,7 @@ public class FRCNetComm extends JNIWrapper {
for i in range(1, len(enumCamel)):
temp.write(enumCamel[i][0].lower() + \
enumCamel[i][1:len(enumCamel[i])] + " ")
temp.write("from " + fileName + "\n"
temp.write("from " + os.path.basename(fileName) + "\n"
" */\n"
" @SuppressWarnings(\"TypeName\")\n"
" public interface " + enumName + " {\n")
@@ -150,13 +151,12 @@ public class FRCNetComm extends JNIWrapper {
temp.write("\n")
continue
if value.find("=") == -1:
if "=" not in value:
value = value + " = " + str(count)
count += 1
# Add scoping for values from a different enum
if enumName != "tModuleType" and \
value.find("kModuleType") != -1:
if enumName != "tModuleType" and "kModuleType" in value:
value = value.replace("kModuleType",
"tModuleType.kModuleType")
temp.write(" int " + value[0:len(value)] + ";\n")
@@ -174,5 +174,6 @@ public class FRCNetComm extends JNIWrapper {
pass
os.rename(outputName + ".tmp", outputName)
if __name__ == "__main__":
main()

View File

@@ -108,6 +108,14 @@ public class FRCNetComm extends JNIWrapper {
int kResourceType_PCM = 60;
int kResourceType_PigeonIMU = 61;
int kResourceType_NidecBrushless = 62;
int kResourceType_CANifier = 63;
int kResourceType_CTRE_future0 = 64;
int kResourceType_CTRE_future1 = 65;
int kResourceType_CTRE_future2 = 66;
int kResourceType_CTRE_future3 = 67;
int kResourceType_CTRE_future4 = 68;
int kResourceType_CTRE_future5 = 69;
int kResourceType_CTRE_future6 = 70;
}
/**
@@ -119,6 +127,7 @@ public class FRCNetComm extends JNIWrapper {
int kLanguage_CPlusPlus = 2;
int kLanguage_Java = 3;
int kLanguage_Python = 4;
int kLanguage_DotNet = 5;
int kCANPlugin_BlackJagBridge = 1;
int kCANPlugin_2CAN = 2;