blob: d5686009568a6a6535e178c677cf25bf18f31e9b [file] [log] [blame] [raw]
Patrick Quista2eed582020-09-27 00:26:02 +02001// Copyright (c) 2017, Windel Bouwman & Compiler Explorer Authors
RabsRincon02122d82018-01-28 21:25:25 +01002// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// * Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23// POSSIBILITY OF SUCH DAMAGE.
24
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050025import {BaseCompiler} from '../base-compiler';
Austin Morton044dcfb2020-09-26 16:59:26 -040026import * as exec from '../exec';
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050027import {logger} from '../logger';
RabsRincon02122d82018-01-28 21:25:25 +010028
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050029const forbiddenOptions = new Set(['--report', '--text-report', '--html-report']);
Austin Mortone2595f32019-10-09 17:02:31 -040030
Austin Morton044dcfb2020-09-26 16:59:26 -040031export class PPCICompiler extends BaseCompiler {
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050032 static get key() {
33 return 'ppci';
34 }
Austin Mortonbac07fe2020-09-25 11:21:30 -040035
Partoufc8be4752018-03-07 20:39:13 +010036 filterUserOptions(args) {
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050037 return args.filter(item => {
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020038 if (typeof item !== 'string') return true;
Partouf28c29012018-03-07 21:03:18 +010039
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020040 return !forbiddenOptions.has(item.toLowerCase());
Partoufa412d5a2018-03-07 19:40:41 +010041 });
42 }
43
RabsRincon02122d82018-01-28 21:25:25 +010044 exec(compiler, args, options) {
45 if (compiler.endsWith('.py')) {
46 const python = this.env.ceProps('python3');
47 options = options || {};
48
49 const matches = compiler.match(/^(.*)(\/ppci\/)(.*).py/);
50 if (matches) {
51 const pythonPath = matches[1];
52 const ppciName = `ppci.${matches[3].replace('/', '.')}`;
53 options.env = {PYTHONPATH: pythonPath};
54 let python_args = ['-m', ppciName].concat(args);
55 return exec.execute(python, python_args, options);
56 }
57 logger.error(`Invalid ppci path ${compiler}`);
58 } else {
59 return super.exec(compiler, args, options);
60 }
61 }
62}