Skip to content

Commit 8cd1ec8

Browse files
committed
For make projects, load up custom rules from actions file
Signed-off-by: worksofliam <[email protected]>
1 parent 525a482 commit 8cd1ec8

14 files changed

+106
-66
lines changed

cli/src/builders/iProject.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,4 @@ export class iProject {
3333
}
3434
}
3535
}
36-
37-
applyAction(newAction: Action) {
38-
if (newAction.environment && newAction.environment === `ile` && newAction.extensions && newAction.extensions.length > 0) {
39-
if (!newAction.extensions.includes(`GLOBAL`)) {
40-
const firstExt = newAction.extensions[0].toLowerCase();
41-
const becomesObject = getObjectType(firstExt);
42-
const commandData = fromCl(newAction.command);
43-
this.compiles[firstExt] = {
44-
becomes: becomesObject,
45-
...commandData
46-
};
47-
}
48-
}
49-
}
5036
}

cli/src/builders/make/customRules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from "path";
66
import { MakeProject } from ".";
77

88
/**
9-
* Scan for all rules.mk files and read attributes and custom
9+
* Scan for all ibmi-bob rules.mk files and read attributes and custom
1010
* dependencies into the targets.
1111
*/
1212
export function readAllRules(targets: Targets, project: MakeProject) {

cli/src/builders/make/index.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
import { existsSync, readFileSync } from 'fs';
22
import path from 'path';
33
import { ILEObject, ILEObjectTarget, ImpactedObject, ObjectType, Targets } from '../../targets';
4-
import { asPosix, getFiles, toCl } from '../../utils';
4+
import { asPosix, fromCl, getFiles, toCl } from '../../utils';
55
import { warningOut } from '../../cli';
66
import { name } from '../../../webpack.config';
77
import { FolderOptions, getFolderOptions } from './folderSettings';
88
import { readAllRules } from './customRules';
99
import { CompileData, CommandParameters } from '../environment';
1010
import { iProject } from '../iProject';
11+
import { ReadFileSystem } from '../../readFileSystem';
12+
import { ProjectActions } from '../actions';
1113

1214
export class MakeProject {
1315
private noChildren: boolean = false;
1416
private settings: iProject = new iProject();
17+
private actions: ProjectActions;
18+
1519
private folderSettings: {[folder: string]: FolderOptions} = {};
1620

17-
constructor(private cwd: string, private targets: Targets) {
18-
this.setupSettings();
21+
constructor(private cwd: string, private targets: Targets, private rfs: ReadFileSystem) {
22+
this.actions = new ProjectActions(this.targets, this.rfs);
1923
}
2024

2125
public setNoChildrenInBuild(noChildren: boolean) {
2226
this.noChildren = noChildren;
2327
}
2428

25-
private setupSettings() {
29+
async setupSettings() {
2630
// First, let's setup the project settings
2731
try {
28-
const content = readFileSync(path.join(this.cwd, `iproj.json`), { encoding: `utf-8` });
32+
const content = await this.rfs.readFile(path.join(this.cwd, `iproj.json`));
2933
const asJson: iProject = JSON.parse(content);
3034

3135
this.settings.applySettings(asJson);
@@ -37,6 +41,8 @@ export class MakeProject {
3741
this.folderSettings = getFolderOptions(this.cwd);
3842

3943
readAllRules(this.targets, this);
44+
45+
await this.actions.loadAllActions();
4046
}
4147

4248
public getSettings() {
@@ -168,7 +174,7 @@ export class MakeProject {
168174
let lines = [];
169175

170176
for (const entry of Object.entries(this.settings.compiles)) {
171-
const [type, data] = entry;
177+
let [type, data] = entry;
172178

173179
// commandSource means 'is this object built from CL commands in a file'
174180
if (data.commandSource) {
@@ -213,7 +219,24 @@ export class MakeProject {
213219
// This is used when your object really has source
214220

215221
const possibleTarget: ILEObjectTarget = this.targets.getTarget(ileObject) || (ileObject as ILEObjectTarget);
216-
const customAttributes = this.getObjectAttributes(data, possibleTarget);
222+
let customAttributes = this.getObjectAttributes(data, possibleTarget);
223+
224+
if (ileObject.relativePath) {
225+
const possibleAction = this.actions.getActionForPath(ileObject.relativePath);
226+
if (possibleAction) {
227+
const clData = fromCl(possibleAction.command);
228+
// If there is an action for this object, we want to apply the action's parameters
229+
// to the custom attributes.
230+
231+
data = {
232+
...data,
233+
command: clData.command,
234+
parameters: {
235+
...data.parameters,
236+
}
237+
}
238+
}
239+
}
217240

218241
lines.push(...MakeProject.generateSpecificTarget(data, possibleTarget, customAttributes));
219242
}

cli/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ async function main() {
223223

224224
break;
225225
case `make`:
226-
const makeProj = new MakeProject(cwd, targets);
226+
const makeProj = new MakeProject(cwd, targets, fs);
227+
await makeProj.setupSettings();
228+
227229
makeProj.setNoChildrenInBuild(cliSettings.makeFileNoChildren);
228230

229231
let specificObjects: ILEObject[] | undefined = cliSettings.fileList ? cliSettings.lookupFiles.map(f => targets.getResolvedObject(path.join(cwd, f))).filter(o => o) : undefined;

cli/test/cs_srvpgm.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe(`pseudo tests`, () => {
2323
expect(targets.getTargets().length).toBeGreaterThan(0);
2424
targets.resolveBinder();
2525

26-
make = new MakeProject(project.cwd, targets);
26+
make = new MakeProject(project.cwd, targets, fs);
27+
await make.setupSettings();
2728

2829
actions = new ProjectActions(targets, fs);
2930
await actions.loadAllActions();
@@ -75,8 +76,9 @@ describe(`pseudo tests`, () => {
7576
expect(files[path.join(`qrpglesrc`, `Rules.mk`)]).not.toContain(`EMPDET.SRVPGM`); // Ensure no service program is created
7677
});
7778

78-
test('makefile', () => {
79-
const makefile = new MakeProject(targets.getCwd(), targets);
79+
test('makefile', async () => {
80+
const makefile = new MakeProject(targets.getCwd(), targets, fs);
81+
await make.setupSettings();
8082

8183
const contents = makefile.getMakefile().join(`\n`);
8284

cli/test/cs_with_bnddir.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe(`pseudo tests`, () => {
2121
expect(targets.getTargets().length).toBeGreaterThan(0);
2222
targets.resolveBinder();
2323

24-
make = new MakeProject(project.cwd, targets);
24+
make = new MakeProject(project.cwd, targets, fs);
25+
await make.setupSettings();
2526
});
2627

2728
test(`That test files are understood`, () => {
@@ -54,8 +55,9 @@ describe(`pseudo tests`, () => {
5455
expect(employees.deps.find(f => f.systemName === `EMPLOYEE` && f.type === `FILE`)).toBeDefined();
5556
});
5657

57-
test('makefile', () => {
58-
const makefile = new MakeProject(targets.getCwd(), targets);
58+
test('makefile', async () => {
59+
const makefile = new MakeProject(targets.getCwd(), targets, fs);
60+
await make.setupSettings();
5961

6062
const contents = makefile.getMakefile().join(`\n`);
6163

cli/test/ddsDeps.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ describe(`dds_refs tests`, () => {
8080
expect(logs).toBeUndefined();
8181
});
8282

83-
test(`make doesn't include refs that do not exist`, () => {
84-
const makeProject = new MakeProject(project.cwd, targets);
83+
test(`make doesn't include refs that do not exist`, async () => {
84+
const makeProject = new MakeProject(project.cwd, targets, fs);
85+
await makeProject.setupSettings();
8586

8687
const targetContent = makeProject.generateTargets();
8788

cli/test/ddsDepsWithRefFile.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ describe(`dds_refs tests with reference file`, () => {
8484
});
8585

8686

87-
test(`make doesn't include refs that do not exist or are referenced objects`, () => {
88-
const makeProject = new MakeProject(project.cwd, targets);
87+
test(`make doesn't include refs that do not exist or are referenced objects`, async () => {
88+
const makeProject = new MakeProject(project.cwd, targets, fs);
89+
await makeProject.setupSettings();
8990

9091
const targetContent = makeProject.generateTargets();
9192

cli/test/make.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { assert, expect, test } from 'vitest'
22
import { baseTargets, cwd, multiModuleObjects } from './fixtures/targets';
33
import { MakeProject } from '../src/builders/make';
4+
import { ReadFileSystem } from '../src/readFileSystem';
45

56
test('generateTargets (pre-resolve)', async () => {
67
const targets = await baseTargets(true);
7-
const project = new MakeProject(cwd, targets);
8+
const project = new MakeProject(cwd, targets, new ReadFileSystem());
9+
await project.setupSettings();
810

911
const targetContent = project.generateTargets();
1012

@@ -32,7 +34,7 @@ test('generateTargets (post-resolve)', async () => {
3234

3335
targets.resolveBinder();
3436

35-
const project = new MakeProject(cwd, targets);
37+
const project = new MakeProject(cwd, targets, new ReadFileSystem());
3638

3739
const targetContent = project.generateTargets();
3840

@@ -62,7 +64,8 @@ test('generateTargets (post-resolve)', async () => {
6264
test('generateHeader (binder changes)', async () => {
6365
const targets = await baseTargets(true);
6466

65-
const project = new MakeProject(cwd, targets);
67+
const project = new MakeProject(cwd, targets, new ReadFileSystem());
68+
await project.setupSettings();
6669

6770
const headerContentA = project.generateHeader();
6871
let bndDirIndex = headerContentA.findIndex(h => h.startsWith(`BNDDIR=`));
@@ -80,7 +83,8 @@ test('generateHeader (binder changes)', async () => {
8083
test('applySettings (binder)', async () => {
8184
const targets = await baseTargets(true);
8285

83-
const project = new MakeProject(cwd, targets);
86+
const project = new MakeProject(cwd, targets, new ReadFileSystem());
87+
await project.setupSettings();
8488

8589
project.getSettings().applySettings({
8690
binders: [`TESTING`]
@@ -102,7 +106,9 @@ test('applySettings (binder)', async () => {
102106
test(`Multi-module program and service program`, async () => {
103107
const targets = await multiModuleObjects();
104108

105-
const project = new MakeProject(cwd, targets);
109+
const project = new MakeProject(cwd, targets, new ReadFileSystem());
110+
await project.setupSettings();
111+
106112
const settings = project.getSettings();
107113

108114
settings.applySettings({

cli/test/multiModule.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ describe(`multi_module tests`, () => {
4848
expect(objectsMod.deps.length).toBe(0);
4949
});
5050

51-
test(`Generate makefile`, () => {
52-
const makeProj = new MakeProject(project.cwd, targets);
51+
test(`Generate makefile`, async () => {
52+
const makeProj = new MakeProject(project.cwd, targets, fs);
53+
await makeProj.setupSettings();
5354

5455
writeFileSync(path.join(project.cwd, `makefile`), makeProj.getMakefile().join(`\n`));
5556
});

0 commit comments

Comments
 (0)