-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate binder source from module or service program #2485
base: master
Are you sure you want to change the base?
Changes from all commits
1f270d5
a246fdb
ec48ab9
dbd4bd5
25dda90
bc749b3
4090f47
63d4827
567ef22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ import tmp from 'tmp'; | |||||||||||||||||||||||||||||||||||||||||||||
import util from 'util'; | ||||||||||||||||||||||||||||||||||||||||||||||
import * as node_ssh from "node-ssh"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { GetMemberInfo } from './components/getMemberInfo'; | ||||||||||||||||||||||||||||||||||||||||||||||
import { AttrOperands, CommandResult, IBMiError, IBMiMember, IBMiObject, IFSFile, QsysPath, SpecialAuthorities } from './types'; | ||||||||||||||||||||||||||||||||||||||||||||||
import { AttrOperands, CommandResult, IBMiError, IBMiMember, IBMiObject, IFSFile, ProgramExportImportInfo, ModuleExport, QsysPath, SpecialAuthorities } from './types'; | ||||||||||||||||||||||||||||||||||||||||||||||
import { FilterType, parseFilter, singleGenericName } from './Filter'; | ||||||||||||||||||||||||||||||||||||||||||||||
import { default as IBMi } from './IBMi'; | ||||||||||||||||||||||||||||||||||||||||||||||
import { Tools } from './Tools'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -632,6 +632,65 @@ export default class IBMiContent { | |||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||
* @param object IBMiObject to get export and import info for | ||||||||||||||||||||||||||||||||||||||||||||||
* @returns an array of ProgramExportImportInfo | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
async getProgramExportImportInfo(library: string, name: string, type: string): Promise<ProgramExportImportInfo[]> { | ||||||||||||||||||||||||||||||||||||||||||||||
if (!['*PGM', '*SRVPGM'].includes(type)) { | ||||||||||||||||||||||||||||||||||||||||||||||
return []; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
const results = await this.ibmi.runSQL( | ||||||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||||||
`select PROGRAM_LIBRARY, PROGRAM_NAME, OBJECT_TYPE, SYMBOL_NAME, SYMBOL_USAGE,`, | ||||||||||||||||||||||||||||||||||||||||||||||
` ARGUMENT_OPTIMIZATION, DATA_ITEM_SIZE`, | ||||||||||||||||||||||||||||||||||||||||||||||
`from qsys2.program_export_import_info`, | ||||||||||||||||||||||||||||||||||||||||||||||
`where program_library = '${library}' and program_name = '${name}' `, | ||||||||||||||||||||||||||||||||||||||||||||||
`and object_type = '${type}'` | ||||||||||||||||||||||||||||||||||||||||||||||
].join("\n") | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
if (results.length) { | ||||||||||||||||||||||||||||||||||||||||||||||
return results.map(result => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
program_library: result.PROGRAM_LIBRARY, | ||||||||||||||||||||||||||||||||||||||||||||||
program_name: result.PROGRAM_NAME, | ||||||||||||||||||||||||||||||||||||||||||||||
object_type: result.OBJECT_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||
symbol_name: result.SYMBOL_NAME, | ||||||||||||||||||||||||||||||||||||||||||||||
symbol_usage: result.SYMBOL_USAGE, | ||||||||||||||||||||||||||||||||||||||||||||||
argument_optimization: result.ARGUMENT_OPTIMIZATION, | ||||||||||||||||||||||||||||||||||||||||||||||
data_item_size: result.DATA_ITEM_SIZE | ||||||||||||||||||||||||||||||||||||||||||||||
} as ProgramExportImportInfo)); | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
return []; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+652
to
+664
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to check the array's length. Directly return the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||
* @param object IBMiObject to get module exports for | ||||||||||||||||||||||||||||||||||||||||||||||
* @returns an array of ModuleExport | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
async getModuleExports(library: string, name: string): Promise<ModuleExport[]> { | ||||||||||||||||||||||||||||||||||||||||||||||
const outfile: string = Tools.makeid().toUpperCase(); | ||||||||||||||||||||||||||||||||||||||||||||||
const results = await this.runStatements( | ||||||||||||||||||||||||||||||||||||||||||||||
`@DSPMOD MODULE(${library}/${name}) DETAIL(*EXPORT) OUTPUT(*OUTFILE) OUTFILE(QTEMP/${outfile})`, | ||||||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||||||
`select EXLBNM as MODULE_LIBRARY, EXMONM as MODULE_NAME, EXMOAT as MODULE_ATTR, EXSYNM as SYMBOL_NAME,`, | ||||||||||||||||||||||||||||||||||||||||||||||
` case EXSYTY when '0' then 'PROCEDURE' when '1' then 'DATA' end as SYMBOL_TYPE, EXOPPP as ARGUMENT_OPTIMIZATION`, | ||||||||||||||||||||||||||||||||||||||||||||||
` from QTEMP.${outfile}` | ||||||||||||||||||||||||||||||||||||||||||||||
].join("\n") | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
if (results.length) { | ||||||||||||||||||||||||||||||||||||||||||||||
return results.map(result => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
module_library: result.MODULE_LIBRARY, | ||||||||||||||||||||||||||||||||||||||||||||||
module_name: result.MODULE_NAME, | ||||||||||||||||||||||||||||||||||||||||||||||
module_attr: result.MODULE_ATTR, | ||||||||||||||||||||||||||||||||||||||||||||||
symbol_name: result.SYMBOL_NAME, | ||||||||||||||||||||||||||||||||||||||||||||||
symbol_type: result.SYMBOL_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||
argument_optimization: result.ARGUMENT_OPTIMIZATION | ||||||||||||||||||||||||||||||||||||||||||||||
} as ModuleExport)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
return []; | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+681
to
+691
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, return the |
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||
* @param filter: the criterias used to list the members | ||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { Tools } from '../../Tools'; | |
import { posix } from 'path'; | ||
import IBMi from '../../IBMi'; | ||
import { newConnection, disposeConnection, CONNECTION_TIMEOUT } from '../connection'; | ||
import { ModuleExport, ProgramExportImportInfo } from '../../types'; | ||
|
||
describe('Content Tests', {concurrent: true}, () => { | ||
let connection: IBMi | ||
|
@@ -642,4 +643,77 @@ describe('Content Tests', {concurrent: true}, () => { | |
throw new Error(`Failed to create schema "${longName}"`); | ||
} | ||
}); | ||
|
||
it('getModuleExport', async () => { | ||
const content = connection.getContent(); | ||
const config = connection.getConfig(); | ||
const tempLib = config!.tempLibrary; | ||
const id: string = `${Tools.makeid().toUpperCase()}`; | ||
const source: string = `/tmp/vscodetemp-${id}.clle`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest to use |
||
await content.runStatements( | ||
`CALL QSYS2.IFS_WRITE(PATH_NAME =>'${source}', | ||
LINE => 'PGM', | ||
OVERWRITE => 'NONE', | ||
END_OF_LINE => 'CRLF')`, | ||
`CALL QSYS2.IFS_WRITE(PATH_NAME =>'${source}', | ||
LINE => 'ENDPGM', | ||
OVERWRITE => 'APPEND', | ||
END_OF_LINE => 'CRLF')`, | ||
`@CRTCLMOD MODULE(${tempLib}/${id}) SRCSTMF('${source}')`, | ||
`select 1 from sysibm.sysdummy1` | ||
); | ||
let exports: ModuleExport[] = await content.getModuleExports(tempLib, id); | ||
|
||
expect(exports.length).toBe(1); | ||
expect(exports.at(0)?.symbol_name).toBe(id); | ||
|
||
await connection!.runCommand({ | ||
command: `DLTMOD MODULE(${tempLib}/${id})`, | ||
environment: 'ile' | ||
}); | ||
Comment on lines
+670
to
+673
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be put in a |
||
await connection!.runCommand({ | ||
command: `DEL OBJLNK('${source}')`, | ||
environment: 'ile' | ||
}); | ||
}); | ||
|
||
it('getProgramExportImportInfo', async () => { | ||
const content = connection.getContent(); | ||
const config = connection.getConfig(); | ||
const tempLib = config!.tempLibrary; | ||
const id: string = `${Tools.makeid().toUpperCase()}`; | ||
const source: string = `/tmp/vscodetemp-${id}.clle`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, try using |
||
await content.runStatements( | ||
`CALL QSYS2.IFS_WRITE(PATH_NAME =>'${source}', | ||
LINE => 'PGM', | ||
OVERWRITE => 'NONE', | ||
END_OF_LINE => 'CRLF')`, | ||
`CALL QSYS2.IFS_WRITE(PATH_NAME =>'${source}', | ||
LINE => 'ENDPGM', | ||
OVERWRITE => 'APPEND', | ||
END_OF_LINE => 'CRLF')`, | ||
`@CRTCLMOD MODULE(${tempLib}/${id}) SRCSTMF('${source}')`, | ||
`@CRTSRVPGM SRVPGM(${tempLib}/${id}) MODULE(${tempLib}/${id}) EXPORT(*ALL)`, | ||
`select 1 from sysibm.sysdummy1` | ||
); | ||
|
||
const info: ProgramExportImportInfo[] = (await content.getProgramExportImportInfo(tempLib, id, '*SRVPGM')) | ||
.filter(info => info.symbol_usage === '*PROCEXP'); | ||
|
||
expect(info.length).toBe(1); | ||
expect(info.at(0)?.symbol_name).toBe(id); | ||
|
||
await connection!.runCommand({ | ||
command: `DLTSRVPGM SRVPGM(${tempLib}/${id})`, | ||
environment: 'ile' | ||
}); | ||
await connection!.runCommand({ | ||
command: `DLTMOD MODULE(${tempLib}/${id})`, | ||
environment: 'ile' | ||
}); | ||
Comment on lines
+706
to
+713
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be put in a |
||
await connection!.runCommand({ | ||
command: `DEL OBJLNK('${source}')`, | ||
environment: 'ile' | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -182,4 +182,23 @@ export type SearchHitLine = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export interface ProgramExportImportInfo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
program_library: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
program_name: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
object_type: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
symbol_name: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
symbol_usage: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
argument_optimization: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data_item_size: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export interface ModuleExport { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
module_library: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
module_name: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
module_attr: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
symbol_name: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
symbol_type: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
argument_optimization: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+185
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer camel case for variable names, to keep it consistent with the others.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export * from "./configuration/config/types"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to escape the dot here, since you'll be looking at an actual dot (and not any character).