Skip to content

Commit

Permalink
Implementing support for compile-args in C and C++ (gcc) environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Mar 13, 2022
1 parent 95a771d commit 1a1f095
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ const createFilesNamesIndex = defaultMemoize(
files => files && new Set(deepReduce(files, [null, 'name']).filter(name => name))
);

const someValuesHaveNozeroLength = (obj, ...keys) => {
if (!obj || typeof obj !== 'object') {
return false;
}

for (const key of keys) {
if (key in obj) {
for (const val of Object.values(obj[key])) {
if (val && val.length > 0) {
return true;
}
}
}
}
return false;
};

/**
* Make sure file(s) in form data (specified by given path) exist.
* If not, proper form error message(s) is/are filled.
Expand Down Expand Up @@ -230,13 +247,19 @@ class EditExerciseSimpleConfigForm extends Component {
.sort((a, b) => a.name.localeCompare(b.name, locale))
.map((test, idx) => {
const testData = formValues && formValues.config && formValues.config[encodeNumId(test.id)];
const hasCompilationSetting = someValuesHaveNozeroLength(
testData,
'extra-files',
'jar-files',
'compile-args'
);
return (
<EditExerciseSimpleConfigTest
change={change}
environmentsWithEntryPoints={environmentsWithEntryPoints}
exercise={exercise}
extraFiles={testData && testData['extra-files']}
jarFiles={testData && testData['jar-files']}
compilationInitiallyOpened={hasCompilationSetting}
key={idx}
smartFill={
idx === 0 && exerciseTests.length > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class EditExerciseSimpleConfigTest extends Component {
environmentsWithEntryPoints,
exercise,
extraFiles,
jarFiles,
compilationInitiallyOpened,
smartFill,
supplementaryFiles,
test,
Expand Down Expand Up @@ -100,7 +100,7 @@ class EditExerciseSimpleConfigTest extends Component {
environmentsWithEntryPoints={environmentsWithEntryPoints}
exercise={exercise}
extraFiles={extraFiles}
jarFiles={jarFiles}
compilationInitiallyOpened={compilationInitiallyOpened}
smartFillCompilation={smartFill ? smartFill.compilation : null}
supplementaryFiles={supplementaryFiles}
test={test}
Expand Down Expand Up @@ -222,7 +222,7 @@ EditExerciseSimpleConfigTest.propTypes = {
exercise: PropTypes.object,
exerciseTests: PropTypes.array,
extraFiles: PropTypes.object,
jarFiles: PropTypes.object,
compilationInitiallyOpened: PropTypes.bool,
smartFill: PropTypes.object,
supplementaryFiles: PropTypes.array.isRequired,
test: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Field, FieldArray } from 'redux-form';
import { Container, Row, Col } from 'react-bootstrap';
import { Container, Row, Col, OverlayTrigger, Tooltip } from 'react-bootstrap';
import { FormattedMessage, injectIntl } from 'react-intl';

import EnvironmentsListItem from '../../helpers/EnvironmentsList/EnvironmentsListItem';
import { EMPTY_ARRAY } from '../../../helpers/common';
import Button from '../../widgets/TheButton';
import InsetPanel from '../../widgets/InsetPanel';
import Icon, { ExpandCollapseIcon } from '../../icons';
import { SelectField, ExpandingInputFilesField, ExpandingSelectField } from '../Fields';
import Icon, { ExpandCollapseIcon, WarningIcon } from '../../icons';
import { SelectField, ExpandingInputFilesField, ExpandingSelectField, ExpandingTextField } from '../Fields';
import Confirm from '../../forms/Confirm';
import { ENV_JAVA_ID } from '../../../helpers/exercise/environments';
import Explanation from '../../widgets/Explanation';
import { ENV_JAVA_ID, ENV_C_GCC_ID, ENV_CPP_GCC_ID } from '../../../helpers/exercise/environments';

class EditExerciseSimpleConfigTestCompilation extends Component {
constructor(props) {
Expand Down Expand Up @@ -45,30 +46,6 @@ class EditExerciseSimpleConfigTestCompilation extends Component {
.sort((a, b) => a.name.localeCompare(b.name, intl.locale));
};

hasCompilationExtraFiles() {
const { extraFiles, jarFiles } = this.props;
if (!extraFiles && !jarFiles) {
return false;
}

if (extraFiles) {
for (const files of Object.values(extraFiles)) {
if (files && files.length > 0) {
return true;
}
}
}

if (jarFiles) {
for (const files of Object.values(jarFiles)) {
if (files && files.length > 0) {
return true;
}
}
}
return false;
}

render() {
const {
change,
Expand All @@ -79,11 +56,11 @@ class EditExerciseSimpleConfigTestCompilation extends Component {
testErrors,
intl,
readOnly = false,
compilationInitiallyOpened = false,
} = this.props;
return (
<>
{this.state.compilationOpen === true ||
(this.state.compilationOpen === null && this.hasCompilationExtraFiles()) ? (
{this.state.compilationOpen === true || (this.state.compilationOpen === null && compilationInitiallyOpened) ? (
<InsetPanel>
<h4 className="compilation-close" onClick={this.compilationClose}>
<ExpandCollapseIcon isOpen={true} gapRight />
Expand Down Expand Up @@ -148,7 +125,60 @@ class EditExerciseSimpleConfigTestCompilation extends Component {
*/
}

<Col lg={exercise.runtimeEnvironments.length === 1 && env.id === ENV_JAVA_ID ? 6 : 12}>
{
(env.id === ENV_C_GCC_ID || env.id === ENV_CPP_GCC_ID) && (
/*
* A special case for C/C++ only !!!
*/
<Col lg={exercise.runtimeEnvironments.length === 1 ? 6 : 12}>
<FieldArray
name={`${test}.compile-args.${env.id}`}
component={ExpandingTextField}
maxLength={1024}
readOnly={readOnly}
label={
<>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.compilationArguments"
defaultMessage="Compilation arguments:"
/>
<Explanation id={`${test}.compile-args-explanation.${env.id}`}>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.compilationArgumentsExplanation"
defaultMessage="Please, place individual arguments into individual input boxes. Any whitespace inside the input box will be treated as a regular part of the argument value (not as a separator of arguments). These arguments will be appended after the default arguments set in the compilation pipeline."
/>
</Explanation>

<OverlayTrigger
placement="right"
overlay={
<Tooltip id={`${test}.compile-args-warning.${env.id}`}>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.compileArgsWarning"
defaultMessage="Setting compilation arguments is potentially error-prone. Make sure you know how the pipelines and the workers are configured before adding any custom compilation arguments."
/>
</Tooltip>
}>
<WarningIcon className="text-warning" />
</OverlayTrigger>
</>
}
/>
{exercise.runtimeEnvironments.length !== 1 && <hr />}
</Col>
)
/*
* End of special case.
*/
}

<Col
lg={
exercise.runtimeEnvironments.length === 1 &&
(env.id === ENV_JAVA_ID || env.id === ENV_C_GCC_ID || env.id === ENV_CPP_GCC_ID)
? 6
: 12
}>
<FieldArray
name={`${test}.extra-files.${env.id}`}
component={ExpandingInputFilesField}
Expand All @@ -166,6 +196,12 @@ class EditExerciseSimpleConfigTestCompilation extends Component {
defaultMessage="Rename as:"
/>
}
noItemsLabel={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.extraFilesNoItemsLabel"
defaultMessage="Extra files:"
/>
}
noItems={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.noExtraFiles"
Expand Down Expand Up @@ -243,7 +279,7 @@ EditExerciseSimpleConfigTestCompilation.propTypes = {
supplementaryFiles: PropTypes.array.isRequired,
exerciseTests: PropTypes.array,
extraFiles: PropTypes.object,
jarFiles: PropTypes.object,
compilationInitiallyOpened: PropTypes.bool,
useOutFile: PropTypes.bool,
useCustomJudge: PropTypes.bool,
environmentsWithEntryPoints: PropTypes.array.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const EditExerciseSimpleConfigTestExecArgs = ({ smartFillArgs, test, testErrors,
<FieldArray
name={`${test}.run-args`}
component={ExpandingTextField}
maxLength={64}
maxLength={256}
readOnly={readOnly}
label={
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const EditExerciseSimpleConfigTestExtraFiles = ({
rightLabel={
<FormattedMessage id="app.editExerciseSimpleConfigTests.extraFilesRename" defaultMessage="Rename as:" />
}
noItemsLabel={
<FormattedMessage id="app.editExerciseSimpleConfigTests.extraFilesNoItemsLabel" defaultMessage="Extra files:" />
}
noItems={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.noExtraFiles"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const EditExerciseSimpleConfigTestInputs = ({
rightLabel={
<FormattedMessage id="app.editExerciseSimpleConfigTests.inputFilesRename" defaultMessage="Rename as:" />
}
noItemsLabel={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputFilesNoItemsLabel"
defaultMessage="Input files:"
/>
}
/>
)}

Expand Down
Loading

0 comments on commit 1a1f095

Please sign in to comment.