Skip to content

Commit

Permalink
fix: Makefile variables assigned with := are interpreted as rules. [f…
Browse files Browse the repository at this point in the history
…ixes #146]
  • Loading branch information
spmeesseman committed Jun 6, 2021
1 parent 3716ca7 commit 7b878d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
48 changes: 10 additions & 38 deletions src/providers/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { TaskExplorerDefinition } from "../taskDefinition";

export class MakeTaskProvider extends TaskExplorerProvider implements TaskExplorerProvider
{

private suffixRuleTargets = /^(\.\w+|\.\w+\.\w+)$/;
private patternRuleTargets = /^(%\.\w+|%)$/;
private ruleTargetExp = /^([\w-.\/ ]+)\s*:[^=]/mg; // note does not disallow leading '.', this must be checked separately.
// See: https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
private specialTargets = new Set([
".PHONY",
Expand All @@ -36,7 +36,6 @@ export class MakeTaskProvider extends TaskExplorerProvider implements TaskExplor
".MAKE",
]);


constructor() { super("make"); }


Expand Down Expand Up @@ -119,38 +118,22 @@ export class MakeTaskProvider extends TaskExplorerProvider implements TaskExplor
log.write(logPad + "find makefile targets");

const contents = util.readFileSync(fsPath);
let idx = 0;
let eol = contents.indexOf("\n", 0);

while (eol !== -1)
let match;
while (match = this.ruleTargetExp.exec(contents))
{
const line: string = contents.substring(idx, eol);
//
// Target names always start at position 0 of the line.
//
// TODO = Skip targets that are environment variable names, for now. Need to
// parse value if set in makefile and apply here for $() target names.
//
if (line.length > 0 && !line.startsWith("\t") && !line.startsWith(" ") &&
!line.startsWith("#") && !line.startsWith("$") && line.indexOf(":") > 0)
const tgtName = match[1];
if (tgtName.startsWith(".")) // skip special targets
{
const { tgtName, dependsName } = this.parseTargetLine(line);

//
// Don't include object targets
//
if (tgtName.indexOf("/") === -1 && tgtName.indexOf("=") === -1 && tgtName.indexOf("\\") === -1 &&
tgtName.indexOf("(") === -1 && tgtName.indexOf("$") === -1 && this.isNormalTarget(tgtName))
{
continue;
}
if (!scripts.includes(tgtName)) // avoid duplicates
{
if (this.isNormalTarget(tgtName)) {
scripts.push(tgtName);
log.write(logPad + " found makefile target");
log.value(logPad + " name", tgtName);
log.value(logPad + " depends target", dependsName);
}
}

idx = eol + 1;
eol = contents.indexOf("\n", idx);
}

log.write(logPad + "find makefile targets complete", 1);
Expand Down Expand Up @@ -193,17 +176,6 @@ export class MakeTaskProvider extends TaskExplorerProvider implements TaskExplor
}


private parseTargetLine(line: string)
{
const tgtNames = line.split(":")[0].trim();
const tgtName = tgtNames.split(" ").slice(-1)[0];

const dependsName = line.substring(line.indexOf(":") + 1).trim();

return { tgtName, dependsName };
}


public async readTasks(logPad = ""): Promise<Task[]>
{
log.methodStart("detect make files", 1, logPad, true);
Expand Down
15 changes: 15 additions & 0 deletions test-files/make/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ coverage:
deno test --import-map=import_map.json --no-check --coverage=cov_profile
deno coverage cov_profile
rm -rf cov_profile

rule1: rule2
@echo rule1

rule2:
@echo rule2

# The ":=" referenced in ticket 146 must not be a windows nmake thing,
# get 'invalid character '='' errors when uncommented. but they are no
# longer parsed as tasks.
# VAR4:=foo
# VAR5 := foo
# else
# VAR4:=bar
# VAR5 := bar

0 comments on commit 7b878d8

Please sign in to comment.