-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from IBM/feature/handle_metadata
Feature/handle_metadata
- Loading branch information
Showing
18 changed files
with
719 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { warningOut } from "../../cli"; | ||
import { ObjectType, Targets } from "../../targets"; | ||
import { getFiles } from "../../utils"; | ||
import { readFileSync } from "fs"; | ||
import * as path from "path"; | ||
import { MakeProject } from "."; | ||
|
||
/** | ||
* Scan for all rules.mk files and read attributes and custom | ||
* dependencies into the targets. | ||
*/ | ||
export function readAllRules(targets: Targets, project: MakeProject) { | ||
// getFiles is case insensitive | ||
const rulesFiles = getFiles(targets.getCwd(), `**/rules.mk`); | ||
|
||
const settings = project.getSettings(); | ||
|
||
for (const rulesFile of rulesFiles) { | ||
const relative = targets.getRelative(rulesFile); | ||
|
||
try { | ||
const content = readFileSync(rulesFile, { encoding: `utf-8` }); | ||
const lines = content.split(`\n`); | ||
|
||
for (const line of lines) { | ||
if (line.trim().length === 0) continue; // Skip empty lines | ||
if (line[0] === `#`) continue; // Skip comments | ||
if (line[0] === ` ` || line[0] === `\t`) continue; // Skip lines that start with a space or tab | ||
|
||
const nameSplit = line.indexOf(`:`); | ||
if (nameSplit < 0) continue; | ||
|
||
const name = line.substring(0, nameSplit).trim().toUpperCase(); | ||
const value = line.substring(nameSplit + 1).trim(); | ||
|
||
let assignmentSplit = -1; | ||
let assignmentSplitLength = 0; | ||
|
||
// Assignment can be with multiple operators | ||
const assignmentOps = [`:=`, `=`]; | ||
for (const op of assignmentOps) { | ||
assignmentSplit = value.indexOf(op); | ||
if (assignmentSplit >= 0) { | ||
assignmentSplitLength = op.length; | ||
break; | ||
} | ||
} | ||
|
||
if (assignmentSplit >= 0) { | ||
// If there is an assignment value, this means we're | ||
// setting a compile parameter on a specific object | ||
const key = value.substring(0, assignmentSplit).trim().toLowerCase(); | ||
const val = value.substring(assignmentSplit + assignmentSplitLength).trim(); | ||
|
||
if (!settings.objectAttributes[name]) settings.objectAttributes[name] = {}; | ||
|
||
settings.objectAttributes[name][key] = val; | ||
|
||
} else { | ||
// Otherwise, we're overriding the deps with hardcoded deps | ||
|
||
const nameParts = name.split(`.`); | ||
const targetName = nameParts[0]; | ||
const targetType = nameParts[1] as ObjectType; | ||
|
||
if (targetName && targetType) { | ||
const currentTarget = targets.getTarget({systemName: targetName, type: targetType}); | ||
|
||
if (currentTarget) { | ||
// We set this to empty since we're overriding them | ||
currentTarget.deps = []; | ||
|
||
const parts = value.split(` `).map(p => p.trim()).filter(p => p.length > 0); | ||
|
||
// We always skip the first because ibmi-bob wants the first entry to be the source name. | ||
for (let i = 1; i < parts.length; i++) { | ||
const part = parts[i]; | ||
const partSplit = part.split(`.`); | ||
const objName = partSplit[0]; | ||
const objType = partSplit[1] as ObjectType; | ||
|
||
if (objName && objType) { | ||
const obj = targets.searchForObject({systemName: objName, type: objType}, undefined); | ||
|
||
if (obj) { | ||
currentTarget.deps.push(obj); | ||
} else { | ||
warningOut(`make: Failed to find '${part}' in '${relative}'`); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
} catch (e) { | ||
warningOut(`make: Failed to read ${relative}.`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as path from "path"; | ||
import { getFiles } from "../../utils"; | ||
import { readFileSync } from "fs"; | ||
import { warningOut } from "../../cli"; | ||
|
||
export interface FolderOptions { | ||
version?: "0.0.1", | ||
build?: { | ||
// objlib?: string, We don't support objlib | ||
tgtCcsid?: string | ||
} | ||
} | ||
|
||
/** | ||
* Fetch the folder specific settings for a project | ||
*/ | ||
export function getFolderOptions(cwd: string) { | ||
// Then fetch the directory specific settings | ||
const ibmiFiles = getFiles(cwd, `**/.ibmi.json`); | ||
|
||
let folderSettings: { [key: string]: FolderOptions } = {}; | ||
|
||
for (const ibmiFile of ibmiFiles) { | ||
const relative = path.relative(cwd, ibmiFile); | ||
const folder = path.dirname(relative); | ||
|
||
try { | ||
folderSettings[folder] = JSON.parse(readFileSync(ibmiFile, { encoding: `utf-8` })); | ||
} catch (e) { | ||
warningOut(`make: Failed to read ${relative}.`); | ||
} | ||
} | ||
|
||
return folderSettings; | ||
} |
Oops, something went wrong.