Skip to content

Commit

Permalink
Merge pull request #57 from IBM/fix/module_sub_deps
Browse files Browse the repository at this point in the history
Fixes to multi module program depedencies and makefile
  • Loading branch information
worksofliam authored Feb 19, 2024
2 parents dbccf8c + e00f7f6 commit e6af7fc
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 3 deletions.
19 changes: 17 additions & 2 deletions cli/src/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ export class Targets {
newImports.push(possibleSrvPgmDep);
}

} else if (currentTarget.type === `PGM`) {
} else if ([`PGM`, `MODULE`].includes(currentTarget.type)) {
// Perhaps we're looking at a program object, which actually should be a multi
// module program, so we do a lookup for additional modules.
const possibleModuleDep = allModules.find(mod => mod.exports && mod.exports.includes(importName.toUpperCase()))
Expand All @@ -1414,6 +1414,20 @@ export class Targets {
// to be a program made up of many modules, usually done with CRTPGM
if (currentTarget.deps.some(d => d.type === `MODULE`)) {
this.convertBoundProgramToMultiModuleProgram(currentTarget);

// Then, also include any of the modules dep modules into the currentTarget deps!!
const depTargets = currentTarget.deps
.filter(d => d.type === `MODULE`)
.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`);

for (const newDep of depDeps) {
if (newDep && !currentTarget.deps.some(d => d.systemName === newDep.systemName && d.type === newDep.type)) {
currentTarget.deps.push(newDep);
}
}
}
}
}
Expand Down Expand Up @@ -1459,7 +1473,8 @@ export class Targets {
imports: currentTarget.imports,
exports: [],
type: `MODULE`,
relativePath: basePath
relativePath: basePath,
extension: path.extname(basePath).substring(1)
};

// Replace the old resolved object with the module
Expand Down
250 changes: 250 additions & 0 deletions cli/test/fixtures/multi_module_two/rpgle/data.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
**free

ctl-opt nomain;

dcl-s names char(15) dim(78) ctdata;
dcl-s surnames char(15) dim(27) ctdata;
dcl-s streetTypes char(3) dim(9) ctdata;
dcl-s states char(2) dim(50) ctdata;
dcl-s cities char(15) dim(15) ctdata;

dcl-proc random export;
dcl-pi *n int(10);
low packed(7) const;
high packed(7) const;
end-pi;

dcl-s result float(8);
dcl-s range packed(7);
dcl-s seed int(10);

dcl-pr ceeran0 extproc('CEERAN0');
*n int(10);
*n float(8);
*n char(12) options(*omit);
end-pr;

range = (high - low) + 1;
ceeran0(seed:result:*omit);

return %int(result * range);
end-proc;

dcl-proc getFirst export;
dcl-pi *n char(15);
end-pi;

return names(random(1:%elem(names)));
end-proc;

dcl-proc getSurname export;
dcl-pi *n char(15);
end-pi;

return surnames(random(1:%elem(surnames)));
end-proc;

dcl-proc getStreetType export;
dcl-pi *n char(3);
end-pi;

return streetTypes(random(1:%elem(streetTypes)));
end-proc;

dcl-proc getState export;
dcl-pi *n char(2);
end-pi;

return states(random(1:%elem(states)));
end-proc;

dcl-proc getCity export;
dcl-pi *n char(15);
end-pi;

return cities(random(1:%elem(cities)));
end-proc;

**CTDATA names
DAVID
JAMES
JOHN
ROBERT
MICHAEL
WILLIAM
MARY
PATRICIA
LINDA
BARBARA
ELIZABETH
JENNIFER
MARIA
SUSAN
MARGARET
DOROTHY
LISA
NANCY
KAREN
BETTY
HELEN
SANDRA
DONNA
CAROL
RUTH
SHARON
MICHELLE
LAURA
SARAH
KIMBERLY
DEBORAH
JESSICA
SHIRLEY
CYNTHIA
ANGELA
MELISSA
BRENDA
AMY
ANNA
REBECCA
VIRGINIA
KATHLEEN
PAMELA
MARTHA
DEBRA
AMANDA
STEPHANIE
CAROLYN
CHRISTINE
MARIE
JANET
CATHERINE
FRANCES
ANN
JOYCE
DIANE
ALICE
JULIE
HEATHER
TERESA
DORIS
GLORIA
EVELYN
JEAN
CHERYL
MILDRED
KATHERINE
JOAN
ASHLEY
JUDITH
ROSE
JANICE
KELLY
NICOLE
JUDY
CHRISTINA
KATHY
THERESA
**CTDATA surnames
SMITH
JOHNSON
WILLIAMS
JONES
BROWN
DAVIS
MILLER
WILSON
MOORE
TAYLOR
ANDERSON
THOMAS
JACKSON
WHITE
HARRIS
MARTIN
THOMPSON
GARCIA
MARTINEZ
ROBINSON
CLARK
RODRIGUEZ
LEWIS
LEE
WALKER
HALL
ALLEN
**CTDATA streetTypes
ST
AVE
RD
DR
CIR
BLVD
WAY
CT
LANE
**CTDATA states
AL
AK
AZ
AR
CA
CO
CT
DE
FL
GA
HI
ID
IL
IN
IA
KS
KY
LA
ME
MD
MA
MI
MN
MS
MO
MT
NE
NV
NH
NJ
NM
NY
NC
ND
OH
OK
OR
PA
RI
SC
SD
TN
TX
UT
VT
VA
WA
WV
WI
WY
**CTDATA cities
SPARTANBURG
GREENVILLE
COLUMBIA
CHARLESTON
MYRTLE BEACH
ROCK HILL
FLORENCE
ASHEVILLE
HENDERSONVILLE
ANDERSON
GREENWOOD
GAFFNEY
EASLEY
GREENWOOD
56 changes: 56 additions & 0 deletions cli/test/fixtures/multi_module_two/rpgle/db.sqlrpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
**free

ctl-opt nomain;

dcl-pr getFirst char(15) extproc('GETFIRST');
end-pr;

dcl-pr getSurname char(15) extproc('GETSURNAME');
end-pr;

dcl-pr random int(10) extproc('RANDOM');
low packed(7) const;
high packed(7) const;
end-pr;

dcl-pr getStreetType char(3) extproc('GETSTREETTYPE');
end-pr;

dcl-pr getCity char(15) extproc('GETCITY');
end-pr;

dcl-pr getState char(2) extproc('GETSTATE');
end-pr;

dcl-proc createCustomer export;
dcl-pi *n int(10);
type char(1) const;
end-pi;

dcl-f customer qualified keyed usropn usage(*output);
dcl-ds cust likerec(customer.custfmt);

cust.FIRSTNME = getFirst();
cust.LASTNAME = getSurname();
cust.PHONENO = %char(random(1111:9999));
cust.CREATED = %date;
cust.ADDR1 = %char(random(1:9999)) + ' ' + %trimr(getSurname()) + ' ' + getStreetType();
cust.CITY = getCity();
cust.STATE = getState();
cust.ZIP = %char(random(10000:99999));

select;
when (type = '1'); //RLA
OPEN customer;
write customer.CUSTFMT cust;
CLOSE customer;
when (type = '2'); //SQL
EXEC SQL
INSERT INTO CUSTOMER
VALUES(:cust);

other;
return -1;
endsl;

end-proc;
12 changes: 12 additions & 0 deletions cli/test/fixtures/multi_module_two/rpgle/runner.pgm.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**free

dcl-pr createCustomer int(10) extproc('CREATECUSTOMER');
type char(1) const;
end-pr;

ctl-opt dftactgrp(*no);

createCustomer('1');
createCustomer('2');

return;
19 changes: 19 additions & 0 deletions cli/test/fixtures/multi_module_two/sql/customer.table
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- https://www.ibm.com/docs/en/i/7.3?topic=tables-employee-table-employee

CREATE OR REPLACE TABLE CUSTOMER
(CUSNO integer not null GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
FIRSTNME VARCHAR(12) NOT NULL,
LASTNAME VARCHAR(15) NOT NULL,
PHONENO CHAR(4) NOT NULL,
CREATED DATE NOT NULL DEFAULT CURRENT_DATE,
ADDR1 VARCHAR(30) NOT NULL,
ADDR2 VARCHAR(30) NOT NULL,
CITY VARCHAR(20) NOT NULL,
STATE CHAR(2) NOT NULL,
ZIP CHAR(5) NOT NULL,
PRIMARY KEY (CUSNO)
) RCDFMT CUSTFMT;

ALTER TABLE CUSTOMER
ADD CONSTRAINT NUMBER
CHECK (PHONENO >= '0000' AND PHONENO <= '9998');
2 changes: 1 addition & 1 deletion cli/test/make.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test(`Multi-module program and service program`, () => {
'$(PREPATH)/MYWEBAPP.PGM: ',
'\tliblist -c $(BIN_LIB);\\',
'\tliblist -a $(LIBL);\\',
'\tsystem "CRTPGM PGM($(BIN_LIB)/MYWEBAPP) ENTRY(MYWEBAPP) MODULES(HANDLERA HANDLERB MYWEBAPP) TGTRLS(*CURRENT) TGTCCSID(*JOB) BNDDIR($(BNDDIR)) DFTACTGRP(*NO)" > .logs/mywebapp.splf'
'\tsystem "CRTPGM PGM($(BIN_LIB)/MYWEBAPP) ENTMOD(MYWEBAPP) MODULE(HANDLERA HANDLERB MYWEBAPP) TGTRLS(*CURRENT) BNDDIR($(BNDDIR)) ACTGRP(*NEW)" > .logs/mywebapp.splf'
].join());

const webappMod = targets.getTarget({systemName: `MYWEBAPP`, type: `MODULE`});
Expand Down
Loading

0 comments on commit e6af7fc

Please sign in to comment.