Skip to content

Commit 4d8cbde

Browse files
committed
makefile actions now support action variables
Signed-off-by: worksofliam <[email protected]>
1 parent 2cde8fb commit 4d8cbde

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

cli/src/builders/environment.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { str } from "crc-32/crc32c";
22
import { ObjectType } from "../targets";
3+
import path from "path";
34

45
// Always try and store parmId as lowercase
56
export type CommandParameters = { [parmId: string]: string };
@@ -43,6 +44,22 @@ export function extCanBeProgram(ext: string): boolean {
4344
return ([`MODULE`, `PGM`].includes(getObjectType(ext)));
4445
}
4546

47+
export function getTrueBasename(name: string) {
48+
// Logic to handle second extension, caused by bob.
49+
const sourceObjectTypes = [`.PGM`, `.SRVPGM`, `.TEST`];
50+
const secondName = path.parse(name);
51+
if (secondName.ext && sourceObjectTypes.includes(secondName.ext.toUpperCase())) {
52+
name = secondName.name;
53+
}
54+
55+
// Remove bob text convention
56+
if (name.includes(`-`)) {
57+
name = name.substring(0, name.indexOf(`-`));
58+
}
59+
60+
return name;
61+
}
62+
4663
export function getObjectType(ext: string): ObjectType {
4764
switch (ext.toLowerCase()) {
4865
case `dspf`:

cli/src/builders/make/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { warningOut } from '../../cli';
66
import { name } from '../../../webpack.config';
77
import { FolderOptions, getFolderOptions } from './folderSettings';
88
import { readAllRules } from './customRules';
9-
import { CompileData, CommandParameters } from '../environment';
9+
import { CompileData, CommandParameters, getTrueBasename } from '../environment';
1010
import { iProject } from '../iProject';
1111
import { ReadFileSystem } from '../../readFileSystem';
1212
import { ProjectActions } from '../actions';
@@ -271,12 +271,30 @@ export class MakeProject {
271271
const parentName = ileObject.relativePath ? path.dirname(ileObject.relativePath) : undefined;
272272
const qsysTempName: string | undefined = (parentName && parentName.length > 10 ? parentName.substring(0, 10) : parentName);
273273

274+
const simpleReplace = (str: string, search: string, replace: string) => {
275+
return str.replace(new RegExp(search, `gi`), replace);
276+
}
277+
274278
const resolve = (command: string) => {
275279
command = command.replace(new RegExp(`\\*CURLIB`, `g`), `$(BIN_LIB)`);
276280
command = command.replace(new RegExp(`\\$\\*`, `g`), ileObject.systemName);
277281
command = command.replace(new RegExp(`\\$<`, `g`), asPosix(ileObject.relativePath));
278282
command = command.replace(new RegExp(`\\$\\(SRCPF\\)`, `g`), qsysTempName);
279283

284+
// Additionally, we have to support Actions variables
285+
command = simpleReplace(command, `&BUILDLIB`, `$(BIN_LIB)`);
286+
command = simpleReplace(command, `&CURLIB`, `$(BIN_LIB)`);
287+
command = simpleReplace(command, `&LIBLS`, ``);
288+
command = simpleReplace(command, `&BRANCHLIB`, `$(BIN_LIB)`);
289+
290+
const pathDetail = path.parse(ileObject.relativePath || ``);
291+
292+
command = simpleReplace(command, `&RELATIVEPATH`, asPosix(ileObject.relativePath));
293+
command = simpleReplace(command, `&BASENAME`, pathDetail.base);
294+
command = simpleReplace(command, `{filename}`, pathDetail.base);
295+
command = simpleReplace(command, `&NAME`, getTrueBasename(pathDetail.name));
296+
command = simpleReplace(command, `&EXTENSION`, pathDetail.ext.startsWith(`.`) ? pathDetail.ext.substring(1) : pathDetail.ext);
297+
280298
if (ileObject.deps && ileObject.deps.length > 0) {
281299
// This piece of code adds special variables that can be used for building dependencies
282300
const uniqueObjectTypes = ileObject.deps.map(d => d.type).filter((value, index, array) => array.indexOf(value) === index);

cli/test/cs_srvpgm.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ describe(`pseudo tests`, () => {
8888
expect(contents).not.toContain(`EMPDET.SRVPGM`); // Ensure no service program is created
8989
expect(contents).toContain(`EMPDET.MODULE`);
9090

91+
console.log(contents);
92+
9193
// As picked up from the actions.json
92-
expect(contents).toContain(`system "CRTBNDRPG THEPARM('''cooldude''')" > .logs/mypgm.splf`);
94+
expect(contents).toContain(`system "CRTBNDRPG NAME(mypgm) THEPARM('qrpglesrc/mypgm.pgm.rpgle')" > .logs/mypgm.splf`);
9395
});
9496

9597
test('there are actions', async () => {
@@ -117,6 +119,6 @@ describe(`pseudo tests`, () => {
117119
const rpgleSrc = path.join(`qrpglesrc`, `mypgm.pgm.rpgle`);
118120
const actionC = actions.getActionForPath(rpgleSrc);
119121
expect(actionC).toBeDefined();
120-
expect(actionC?.command).toBe(`CRTBNDRPG THEPARM('cooldude')`);
122+
expect(actionC?.command).toBe(`CRTBNDRPG NAME(&NAME) THEPARM('&RELATIVEPATH')`);
121123
});
122124
});

cli/test/fixtures/cs_srvpgm/.vscode/actions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"extensions": [
66
"rpgle"
77
],
8-
"command": "CRTBNDRPG THEPARM('cooldude')"
8+
"command": "CRTBNDRPG NAME(&NAME) THEPARM('&RELATIVEPATH')"
99
},
1010
{
1111
"name": "Global run SQL",

0 commit comments

Comments
 (0)