Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/templates/v2_generate_patches.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ <h1>Generate patches for file {{ file.filename|basename }}</h1>
</div>
</div>
<div class="form-group row">
<label for="fist_line" class="col-sm-2 col-form-label">last line</label>
<label for="last_line" class="col-sm-2 col-form-label">last line</label>
<div class="col-sm-10">
<input name="last_line" type="number" class="form-control" id="last_line" placeholder="last line">
</div>
</div>
<div class="form-group row">
<label for="ignore_regex" class="col-sm-2 col-form-label">Ignore lines matching regex</label>
<div class="col-sm-10">
<input name="ignore_regex" type="text" class="form-control" id="ignore_regex" placeholder="^std::cout.*$|^std::cerr.*$">
</div>
</div>
{% for mutator_name, mutator in mutators.items() %}
<div class="form-check">
<label class="form-check-label">
Expand Down
4 changes: 2 additions & 2 deletions app/utils/Executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def workflow(self, patch: Patch):
patchfile.close()

# step 2: apply patch
self.__execute_command_timeout('patch -p1 --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), cwd='/')
self.__execute_command_timeout('patch --ignore-whitespace -p1 --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), cwd='/')

# step 3: command pipeline
success = self.__apply_command(patch, 'build_command') and \
Expand All @@ -100,7 +100,7 @@ def workflow(self, patch: Patch):
db.session.commit()

# step 4: revert patch
self.__execute_command_timeout('patch -p1 --reverse --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename),
self.__execute_command_timeout('patch --ignore-whitespace -p1 --reverse --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename),
cwd='/')

# step 6: delete patch file
Expand Down
7 changes: 6 additions & 1 deletion app/utils/SourceFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from app import db
import os
import re
from datetime import datetime
from app.utils.Mutation import get_mutators
from app.utils.Replacement import Replacement
from app.models import File, Patch


class SourceFile:
def __init__(self, file: File, first_line, last_line):
def __init__(self, file: File, first_line, last_line, ignore_regex):
self.file = file
self.filename = file.filename
self.full_content = [x.rstrip() for x in file.content.split('\n')]
Expand All @@ -18,6 +19,7 @@ def __init__(self, file: File, first_line, last_line):
# self.full_content, we need to subtract -1
self.first_line = first_line
self.last_line = last_line
self.ignore_regex = ignore_regex

if self.last_line == -1:
self.last_line = len(self.full_content)
Expand Down Expand Up @@ -83,6 +85,9 @@ def __get_lines(self):
if line_stripped.endswith('*/'):
in_comment = False
continue

if re.fullmatch(self.ignore_regex, line_stripped):
continue

# return line to mutate
if not in_comment:
Expand Down
7 changes: 6 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ def route_v2_project_project_id_files_file_id_generate(project_id, file_id):
except ValueError:
last_line = -1

s = SourceFile(file, first_line, last_line)
try:
ignore_regex = request.form.get('ignore_regex')
except ValueError:
ignore_regex = ""

s = SourceFile(file, first_line, last_line, ignore_regex)
s.generate_patches()
flash('Successfully created patches.', category='message')
return redirect(url_for('route_v2_project_project_id', project_id=project.id))
Expand Down