From 5da902fc6daf630f823e5d76d47ad8f95e54960e Mon Sep 17 00:00:00 2001 From: Robert Clarke Date: Wed, 7 Sep 2016 00:49:12 +0100 Subject: [PATCH 1/4] Adds filter for duplicate targets Fixes issue #14 --- lib/make.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/make.js b/lib/make.js index 555cdd6..c171b79 100644 --- a/lib/make.js +++ b/lib/make.js @@ -77,6 +77,7 @@ export function provideBuilder() { .split(/[\r\n]{1,2}/) .filter(line => /^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/.test(line)) .map(targetLine => targetLine.split(':').shift()) + .filter( (elem, pos, array) => { return array.indexOf(elem) === pos; } ) .map(target => ({ exec: 'make', args: args.concat([ target ]), From ccb6f8173e9cac3eaad16dafcf6f89bdc28f3a45 Mon Sep 17 00:00:00 2001 From: Robert Clarke Date: Wed, 7 Sep 2016 01:50:55 +0100 Subject: [PATCH 2/4] Pretties the line up a bit Uses () => === () => {return } equivalence --- lib/make.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/make.js b/lib/make.js index c171b79..a7e2e77 100644 --- a/lib/make.js +++ b/lib/make.js @@ -77,7 +77,7 @@ export function provideBuilder() { .split(/[\r\n]{1,2}/) .filter(line => /^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/.test(line)) .map(targetLine => targetLine.split(':').shift()) - .filter( (elem, pos, array) => { return array.indexOf(elem) === pos; } ) + .filter( (elem, pos, array) => (array.indexOf(elem) === pos) ) .map(target => ({ exec: 'make', args: args.concat([ target ]), From 78ec67612faf22a770813c9a1eea42ac1ab93c9c Mon Sep 17 00:00:00 2001 From: Robert Clarke Date: Wed, 7 Sep 2016 12:46:58 +0100 Subject: [PATCH 3/4] Adds spec for duplicated targets --- spec/Makefile.withduplicates | 7 +++++++ spec/build-make-spec.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 spec/Makefile.withduplicates diff --git a/spec/Makefile.withduplicates b/spec/Makefile.withduplicates new file mode 100644 index 0000000..c205bd9 --- /dev/null +++ b/spec/Makefile.withduplicates @@ -0,0 +1,7 @@ +all: + @echo "Building all" + +duplicated: all + +duplicated: + @echo "Building duplicated" diff --git a/spec/build-make-spec.js b/spec/build-make-spec.js index 2c3f88c..5f7d4b5 100644 --- a/spec/build-make-spec.js +++ b/spec/build-make-spec.js @@ -66,6 +66,22 @@ describe('make', () => { }); }); + describe('when makefile contains duplicate targets', () => { + beforeEach(() => { + fs.writeFileSync(directory + 'Makefile', fs.readFileSync(`${__dirname}/Makefile.withduplicates`)); + }); + it('should yield only a single target for each duplicate entry',() => { + atom.config.set('build-make.useMake', false); // Not using make to avoid extracting Makefile as pseudotarget + waitsForPromise(() => { + expect(builder.isEligible(directory)).toBe(true); + return Promise.resolve(builder.settings(directory)).then((settings) => { + const targetNames = settings.map(s => s.name).sort(); + expect(targetNames).toEqual([ 'GNU Make: default (no target)', 'GNU Make: all', 'GNU Make: duplicated' ].sort()); + }); + }); + }); + }); + describe('when makefile exists but make can not run', () => { const originalPath = process.env.PATH; beforeEach(() => { From 137eb086a5d59a8f55282279959c008dd6f469f6 Mon Sep 17 00:00:00 2001 From: Robert Clarke Date: Wed, 7 Sep 2016 13:29:45 +0100 Subject: [PATCH 4/4] Fixes linter issue Ran linter locally and found no issues --- spec/build-make-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/build-make-spec.js b/spec/build-make-spec.js index 5f7d4b5..a547f01 100644 --- a/spec/build-make-spec.js +++ b/spec/build-make-spec.js @@ -70,7 +70,7 @@ describe('make', () => { beforeEach(() => { fs.writeFileSync(directory + 'Makefile', fs.readFileSync(`${__dirname}/Makefile.withduplicates`)); }); - it('should yield only a single target for each duplicate entry',() => { + it('should yield only a single target for each duplicate entry', () => { atom.config.set('build-make.useMake', false); // Not using make to avoid extracting Makefile as pseudotarget waitsForPromise(() => { expect(builder.isEligible(directory)).toBe(true);