Skip to content

Commit

Permalink
Additional support for XRP/Romi (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiquanyeo authored Sep 22, 2023
1 parent 37b00d5 commit b790545
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 22 deletions.
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,24 @@ def downloadNewCommands = tasks.register('downloadNewCommands', Download) {
overwrite true
}

def downloadRomiVendordep = tasks.register('downloadRomiVendordep', Download) {
src 'https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/romiVendordep/RomiVendordep.json'
dest 'vscode-wpilib/resources/vendordeps/RomiVendordep.json'
overwrite true
}

def downloadXRPVendordep = tasks.register('downloadXRPVendordep', Download) {
src 'https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/xrpVendordep/XRPVendordep.json'
dest 'vscode-wpilib/resources/vendordeps/XRPVendordep.json'
overwrite true
}

task copyFromVsCodeToStandaloneResources(type: Copy) {
dependsOn extractCppDependencies
dependsOn extractJavaDependencies
dependsOn downloadNewCommands
dependsOn downloadRomiVendordep
dependsOn downloadXRPVendordep
from ('vscode-wpilib/resources/java') {
into 'java'
}
Expand Down
8 changes: 3 additions & 5 deletions vscode-wpilib/resources/gradle/cppxrp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ plugins {
wpi.sim.addGui().defaultEnabled = true
wpi.sim.addDriverstation()

//Sets the websocket client remote host.
wpi.sim.envVar("HALSIMWS_HOST", "192.168.42.1")
wpi.sim.envVar("HALSIMWS_FILTERS", "AIO,DIO,DriverStation,Encoder,Gyro,XRPMotor,XRPServo")
wpi.sim.addWebsocketsServer().defaultEnabled = true
wpi.sim.addWebsocketsClient().defaultEnabled = true
//Sets the XRP Client Host
wpi.sim.envVar("HALSIMXRP_HOST", "192.168.42.1")
wpi.sim.addXRPClient().defaultEnabled = true

model {
components {
Expand Down
8 changes: 3 additions & 5 deletions vscode-wpilib/resources/gradle/javaxrp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ test {
wpi.sim.addGui().defaultEnabled = true
wpi.sim.addDriverstation()

//Sets the websocket client remote host.
wpi.sim.envVar("HALSIMWS_HOST", "192.168.42.1")
wpi.sim.envVar("HALSIMWS_FILTERS", "AIO,DIO,DriverStation,Encoder,Gyro,XRPMotor,XRPServo")
wpi.sim.addWebsocketsServer().defaultEnabled = true
wpi.sim.addWebsocketsClient().defaultEnabled = true
//Sets the XRP Client Host
wpi.sim.envVar("HALSIMXRP_HOST", "192.168.42.1")
wpi.sim.addXRPClient().defaultEnabled = true

// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
// in order to make them all available at runtime. Also adding the manifest so WPILib
Expand Down
6 changes: 4 additions & 2 deletions vscode-wpilib/src/shared/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IExampleJsonLayout {
foldername: string;
gradlebase: string;
commandversion: number;
extravendordeps?: string[];
}

export class Examples {
Expand All @@ -31,6 +32,7 @@ export class Examples {
}
const examples: IExampleJsonLayout[] = jsonc.parse(data) as IExampleJsonLayout[];
for (const e of examples) {
const extraVendordeps: string[] = (e.extravendordeps !== undefined) ? e.extravendordeps : [];
const provider: IExampleTemplateCreator = {
getLanguage(): string {
return java ? 'java' : 'cpp';
Expand All @@ -46,13 +48,13 @@ export class Examples {
if (java) {
if (!await generateCopyJava(resourceRoot, path.join(examplesFolder, e.foldername),
path.join(gradleBasePath, e.gradlebase), folderInto.fsPath, 'frc.robot.Main', path.join('frc', 'robot'),
false)) {
false, extraVendordeps)) {
vscode.window.showErrorMessage(i18n('message', 'Cannot create into non empty folder'));
return false;
}
} else {
if (!await generateCopyCpp(resourceRoot, path.join(examplesFolder, e.foldername),
path.join(gradleBasePath, e.gradlebase), folderInto.fsPath, false, false)) {
path.join(gradleBasePath, e.gradlebase), folderInto.fsPath, false, false, extraVendordeps)) {
vscode.window.showErrorMessage(i18n('message', 'Cannot create into non empty folder'));
return false;
}
Expand Down
28 changes: 26 additions & 2 deletions vscode-wpilib/src/shared/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { setExecutePermissions } from './permissions';
type CopyCallback = (srcFolder: string, rootFolder: string) => Promise<boolean>;

export async function generateCopyCpp(resourcesFolder: string, fromTemplateFolder: string | CopyCallback, fromGradleFolder: string, toFolder: string,
addCpp: boolean, directGradleImport: boolean): Promise<boolean> {
addCpp: boolean, directGradleImport: boolean, extraVendordeps: string[]): Promise<boolean> {
try {
const existingFiles = await readdirAsync(toFolder);
if (existingFiles.length > 0) {
Expand Down Expand Up @@ -96,6 +96,18 @@ export async function generateCopyCpp(resourcesFolder: string, fromTemplateFolde
const vendorFile = path.join(path.dirname(resourcesFolder), 'vendordeps', commandName);
await copyFileAsync(vendorFile, path.join(vendorDir, commandName));

for (const vendordep of extraVendordeps) {
if (vendordep === 'romi') {
const romiVendordepName = 'RomiVendordep.json';
const romiVendordepFile = path.join(path.dirname(resourcesFolder), 'vendordeps', romiVendordepName);
await copyFileAsync(romiVendordepFile, path.join(vendorDir, romiVendordepName));
} else if (vendordep === 'xrp') {
const xrpVendordepName = 'XRPVendordep.json';
const xrpVendordepFile = path.join(path.dirname(resourcesFolder), 'vendordeps', xrpVendordepName);
await copyFileAsync(xrpVendordepFile, path.join(vendorDir, xrpVendordepName));
}
}

return true;
} catch (e) {
logger.error('Project creation failure', e);
Expand All @@ -104,7 +116,7 @@ export async function generateCopyCpp(resourcesFolder: string, fromTemplateFolde
}

export async function generateCopyJava(resourcesFolder: string, fromTemplateFolder: string | CopyCallback, fromGradleFolder: string, toFolder: string,
robotClassTo: string, copyRoot: string, directGradleImport: boolean,
robotClassTo: string, copyRoot: string, directGradleImport: boolean, extraVendordeps: string[],
packageReplaceString?: string | undefined): Promise<boolean> {
try {
const existingFiles = await readdirAsync(toFolder);
Expand Down Expand Up @@ -236,6 +248,18 @@ to get a proper path relative to the deploy directory.` ]));
const vendorFile = path.join(path.dirname(resourcesFolder), 'vendordeps', commandName);
await copyFileAsync(vendorFile, path.join(vendorDir, commandName));

for (const vendordep of extraVendordeps) {
if (vendordep === 'romi') {
const romiVendordepName = 'RomiVendordep.json';
const romiVendordepFile = path.join(path.dirname(resourcesFolder), 'vendordeps', romiVendordepName);
await copyFileAsync(romiVendordepFile, path.join(vendorDir, romiVendordepName));
} else if (vendordep === 'xrp') {
const xrpVendordepName = 'XRPVendordep.json';
const xrpVendordepFile = path.join(path.dirname(resourcesFolder), 'vendordeps', xrpVendordepName);
await copyFileAsync(xrpVendordepFile, path.join(vendorDir, xrpVendordepName));
}
}

return true;
} catch (e) {
logger.error('Project creation failure', e);
Expand Down
6 changes: 4 additions & 2 deletions vscode-wpilib/src/shared/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ITemplateJsonLayout {
foldername: string;
gradlebase: string;
commandversion: number;
extravendordeps?: string[];
}

export class Templates {
Expand All @@ -31,6 +32,7 @@ export class Templates {
}
const templates: ITemplateJsonLayout[] = jsonc.parse(data) as ITemplateJsonLayout[];
for (const e of templates) {
const extraVendordeps: string[] = (e.extravendordeps !== undefined) ? e.extravendordeps : [];
const provider: IExampleTemplateCreator = {
getLanguage(): string {
return java ? 'java' : 'cpp';
Expand All @@ -46,13 +48,13 @@ export class Templates {
if (java) {
if (!await generateCopyJava(resourceRoot, path.join(templatesFolder, e.foldername),
path.join(gradleBasePath, e.gradlebase), folderInto.fsPath, 'frc.robot.Main', path.join('frc', 'robot'),
false)) {
false, extraVendordeps)) {
vscode.window.showErrorMessage(i18n('message', 'Cannot create into non empty folder'));
return false;
}
} else {
if (!await generateCopyCpp(resourceRoot, path.join(templatesFolder, e.foldername),
path.join(gradleBasePath, e.gradlebase), folderInto.fsPath, false, false)) {
path.join(gradleBasePath, e.gradlebase), folderInto.fsPath, false, false, extraVendordeps)) {
vscode.window.showErrorMessage(i18n('message', 'Cannot create into non empty folder'));
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions vscode-wpilib/src/shared/vendorexamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IJsonExample {
packagetoreplace?: string | undefined;
dependencies: string[];
foldername: string;
extravendordeps?: string[];
}

// tslint:disable-next-line:no-any
Expand Down Expand Up @@ -57,6 +58,7 @@ export async function addVendorExamples(resourceRoot: string, core: IExampleTemp
// Only handle java and cpp
continue;
}
const extraVendordeps: string[] = (ex.extravendordeps !== undefined) ? ex.extravendordeps : [];
const provider: IExampleTemplateCreator = {
getLanguage(): string {
return ex.language;
Expand All @@ -72,13 +74,13 @@ export async function addVendorExamples(resourceRoot: string, core: IExampleTemp
if (ex.language === 'java') {
if (!await generateCopyJava(shimmedResourceRoot, path.join(exampleDir, ex.foldername),
path.join(gradleBasePath, ex.gradlebase), folderInto.fsPath, 'frc.robot.' + ex.mainclass,
path.join('frc', 'robot'), false, ex.packagetoreplace)) {
path.join('frc', 'robot'), false, extraVendordeps, ex.packagetoreplace)) {
vscode.window.showErrorMessage(i18n('message', 'Cannot create into non empty folder'));
return false;
}
} else {
if (!await generateCopyCpp(shimmedResourceRoot, path.join(exampleDir, ex.foldername),
path.join(gradleBasePath, ex.gradlebase), folderInto.fsPath, false, false)) {
path.join(gradleBasePath, ex.gradlebase), folderInto.fsPath, false, false, extraVendordeps)) {
vscode.window.showErrorMessage(i18n('message', 'Cannot create into non empty folder'));
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions vscode-wpilib/src/webviews/gradle2020import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ export class Gradle2020Import extends WebViewBase {
if (cpp) {
const gradlePath = path.join(gradleBasePath, data.romi ? 'cppromi' : 'cpp');
success = await generateCopyCpp(path.join(resourceRoot, 'cpp'), path.join(oldProjectPath, 'src'), gradlePath, toFolder,
false, true);
false, true, []);
} else {
const gradlePath = path.join(gradleBasePath, data.romi ? 'javaromi' : 'java');
success = await generateCopyJava(path.join(resourceRoot, 'java'), path.join(oldProjectPath, 'src'), gradlePath, toFolder,
javaRobotPackage, '', true);
javaRobotPackage, '', true, []);
}

if (!success) {
Expand Down
4 changes: 2 additions & 2 deletions wpilib-utility-standalone/src/generatorscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function handleCppCreate(_item: IDisplayJSON, _srcRoot: string): Promise<v
const toFolder = dirArr[0];

const templateFolder = path.join(_srcRoot, _item.foldername);
const result = await generateCopyCpp(resourceRoot, templateFolder, path.join(gradleRoot, _item.gradlebase), toFolder, false, false);
const result = await generateCopyCpp(resourceRoot, templateFolder, path.join(gradleRoot, _item.gradlebase), toFolder, false, false, []);
if (!result) {
await dialog.showMessageBox({
message: 'Cannot extract into non empty directory',
Expand All @@ -229,7 +229,7 @@ async function handleJavaCreate(_item: IDisplayJSON, _srcRoot: string): Promise<

const templateFolder = path.join(_srcRoot, _item.foldername);
const result = await generateCopyJava(resourceRoot, templateFolder, path.join(gradleRoot, _item.gradlebase), toFolder,
'frc.robot.Robot', path.join('frc', 'robot'), false);
'frc.robot.Robot', path.join('frc', 'robot'), false, []);

if (!result) {
await dialog.showMessageBox({
Expand Down

0 comments on commit b790545

Please sign in to comment.