Skip to content

Commit

Permalink
Merge pull request #98 from IBM/feature/headers
Browse files Browse the repository at this point in the history
Feature/headers
  • Loading branch information
worksofliam authored Nov 7, 2024
2 parents 19f7888 + 4f5dd66 commit 287e5a3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cli/src/builders/bob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RulesFile {

const existingLine = this.parsed.find(r => r.target === objName && r.isUserWritten !== true);

const lineContent = `${path.relative(this.subdir, target.relativePath)} ${target.deps.filter(d => d.reference !== true).map(d => `${d.systemName}.${d.type}`).join(` `)}`.trimEnd();
const lineContent = `${path.relative(this.subdir, target.relativePath)} ${target.headers ? target.headers.join(` `) + ` ` : ``}${target.deps.filter(d => d.reference !== true).map(d => `${d.systemName}.${d.type}`).join(` `)}`.trimEnd();

if (existingLine) {
existingLine.ogLine = `${objName}: ${lineContent}`;
Expand Down
111 changes: 61 additions & 50 deletions cli/src/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export interface ILEObject {
exports?: string[];
/** each function import in the object */
imports?: string[];

/** headers. only supports RPGLE and is not recursive */
headers?: string[];
}

export interface ILEObjectTarget extends ILEObject {
Expand Down Expand Up @@ -161,7 +164,7 @@ export class Targets {
if (sqlExtensions.includes(extension.toLowerCase())) {
const ref = this.sqlObjectDataFromPath(localPath);
if (ref) {
if (ref.object.system) theObject.systemName = ref.object.system.toUpperCase();
if (ref.object.system) theObject.systemName = ref.object.system.toUpperCase();
if (ref.object.name) theObject.longName = ref.object.name;
// theObject.type = ref.type;
}
Expand Down Expand Up @@ -502,7 +505,7 @@ export class Targets {

// We have a local cache of refs found so we don't keep doing global lookups
// on objects we already know to depend on in this object.

let alreadyFoundRefs: string[] = [];

const handleObjectPath = (currentKeyword: string, recordFormat: any, value: string) => {
Expand Down Expand Up @@ -971,7 +974,7 @@ export class Targets {

return importName;
});

// define exported functions
if (cache.keyword[`NOMAIN`]) {
ileObject.type = `MODULE`;
Expand All @@ -982,66 +985,74 @@ export class Targets {
.map(ref => ref.name.toUpperCase());
}

const target: ILEObjectTarget = {
...ileObject,
deps: []
};

infoOut(`${ileObject.systemName}.${ileObject.type}: ${ileObject.relativePath}`);

cache.includes.forEach((include: IncludeStatement) => {
// RPGLE includes are always returned as posix paths
// even on Windows. We need to do some magic to convert here for Windows systems
include.toPath = toLocalPath(include.toPath);
if (cache.includes && cache.includes.length > 0) {
ileObject.headers = [];

cache.includes.forEach((include: IncludeStatement) => {
// RPGLE includes are always returned as posix paths
// even on Windows. We need to do some magic to convert here for Windows systems
include.toPath = toLocalPath(include.toPath);

const includeDetail = path.parse(include.toPath);
const includeDetail = path.parse(include.toPath);

if (includeDetail.ext !== `.rpgleinc`) {
const possibleName = includeDetail.name.toLowerCase().endsWith(`.pgm`) ? includeDetail.name.substring(0, includeDetail.name.length - 4) : includeDetail.name;
if (includeDetail.ext !== `.rpgleinc`) {
const possibleName = includeDetail.name.toLowerCase().endsWith(`.pgm`) ? includeDetail.name.substring(0, includeDetail.name.length - 4) : includeDetail.name;

if (this.suggestions.renames) {
const renameLogPath = this.getRelative(include.toPath);
if (this.suggestions.renames) {
const renameLogPath = this.getRelative(include.toPath);

// We need to make sure the .rpgleinc rename is most important
if (this.logger.exists(renameLogPath, `rename`)) {
this.logger.flush(renameLogPath);
// We need to make sure the .rpgleinc rename is most important
if (this.logger.exists(renameLogPath, `rename`)) {
this.logger.flush(renameLogPath);
}

this.logger.fileLog(renameLogPath, {
message: `Rename suggestion`,
type: `rename`,
change: {
rename: {
path: include.toPath,
newName: `${possibleName}.rpgleinc`
}
}
});
} else {
this.logger.fileLog(this.getRelative(include.toPath), {
message: `referenced as include, but should use the '.rpgleinc' extension.`,
type: `warning`,
});
}
}

this.logger.fileLog(renameLogPath, {
message: `Rename suggestion`,
type: `rename`,
const theIncludePath = asPosix(this.getRelative(include.toPath));

ileObject.headers.push(theIncludePath);

if (this.suggestions.includes) {
this.logger.fileLog(ileObject.relativePath, {
message: `Will update to use unix style path.`,
type: `includeFix`,
line: include.line,
change: {
rename: {
path: include.toPath,
newName: `${possibleName}.rpgleinc`
}
lineContent: (options.isFree ? `` : ``.padEnd(6)) + `/copy '${theIncludePath}'`
}
});
} else {
this.logger.fileLog(this.getRelative(include.toPath), {
message: `referenced as include, but should use the '.rpgleinc' extension.`,
type: `warning`,
this.logger.fileLog(ileObject.relativePath, {
message: `Include at line ${include.line} found, to path '${theIncludePath}'`,
type: `info`,
line: include.line,
});
}
}
});
}

if (this.suggestions.includes) {
this.logger.fileLog(ileObject.relativePath, {
message: `Will update to use unix style path.`,
type: `includeFix`,
line: include.line,
change: {
lineContent: (options.isFree ? `` : ``.padEnd(6)) + `/copy '${asPosix(this.getRelative(include.toPath))}'`
}
});
} else {
this.logger.fileLog(ileObject.relativePath, {
message: `Include at line ${include.line} found, to path '${asPosix(this.getRelative(include.toPath))}'`,
type: `info`,
line: include.line,
});
}
});
const target: ILEObjectTarget = {
...ileObject,
deps: []
};

// This usually means .pgm is in the name
if (ileObject.type === `PGM` && cache.keyword[`NOMAIN`]) {
Expand Down Expand Up @@ -1417,7 +1428,7 @@ export class Targets {
.map(m => this.getTarget(m));

// Confusing names, it means: dependencies of the dependencies that are modules
const depDeps = depTargets .map(m => m?.deps).flat().filter(d => d.type === `MODULE`);
const depDeps = depTargets.map(m => m?.deps).flat().filter(d => d.type === `MODULE`);

for (const newDep of depDeps) {
if (newDep && !currentTarget.deps.some(d => d.systemName === newDep.systemName && d.type === newDep.type)) {
Expand Down Expand Up @@ -1587,7 +1598,7 @@ export class Targets {
* Sadly the long name is not typically part of the path name, so we need to
* find the name inside of the source code.
*/
sqlObjectDataFromPath(fullPath: string): ObjectRef|undefined {
sqlObjectDataFromPath(fullPath: string): ObjectRef | undefined {
const relativePath = this.getRelative(fullPath);

if (fss.existsSync(fullPath)) {
Expand Down
4 changes: 4 additions & 0 deletions cli/test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ describe.skipIf(files.length === 0)(`company_system tests`, () => {
expect(utilsSrvPgm.systemName).toBe(`UTILS`);
expect(utilsSrvPgm.type).toBe(`SRVPGM`);
expect(utilsSrvPgm.relativePath).toBe(path.join(`qsrvsrc`, `utils.bnd`));

expect(myPgm.headers).toBeDefined();
expect(myPgm.headers.length).toBe(2);
console.log(myPgm.headers);
});

test(`Check utils`, async () => {
Expand Down

0 comments on commit 287e5a3

Please sign in to comment.