-
-
Notifications
You must be signed in to change notification settings - Fork 25
A few changes that made mutate_cpp working on Ubuntu 16.04 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .idea | ||
| venv | ||
| *.pyc | ||
| *.db |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| import subprocess | ||
| from threading import Timer, Thread | ||
| import psutil | ||
| from app.models import Patch, Run | ||
| from app.models import Patch, Run, File | ||
| import tempfile | ||
| import os | ||
| import datetime | ||
|
|
@@ -74,33 +74,37 @@ def killer(process): | |
|
|
||
| def workflow(self, patch: Patch): | ||
| assert self.__current_patch is None, 'no auto-concurrency!' | ||
| self.__current_patch = patch | ||
|
|
||
| # step 1: write patch to temp file | ||
| patchfile = tempfile.NamedTemporaryFile(delete=False, mode='w') | ||
| patchfile.write(patch.patch) | ||
| patchfile.close() | ||
|
|
||
| # step 2: apply patch | ||
| self.__execute_command_timeout('patch -p1 --input={patchfile}'.format(patchfile=patchfile.name), cwd='/') | ||
|
|
||
| # step 3: command pipeline | ||
| success = self.__apply_command(patch, 'build_command') and \ | ||
| self.__apply_command(patch, 'quickcheck_command') and \ | ||
| self.__apply_command(patch, 'test_command') | ||
|
|
||
| if success: | ||
| patch.state = 'survived' | ||
| db.session.commit() | ||
|
|
||
| # step 4: revert patch | ||
| self.__execute_command_timeout('patch -p1 --reverse --input={patchfile}'.format(patchfile=patchfile.name), | ||
|
|
||
| file = File.query.get(patch.file_id) | ||
|
|
||
| if file is not None: | ||
| self.__current_patch = patch | ||
|
|
||
| # step 1: write patch to temp file | ||
| patchfile = tempfile.NamedTemporaryFile(delete=False, mode='w') | ||
| patchfile.write(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='/') | ||
|
|
||
| # step 3: command pipeline | ||
| success = self.__apply_command(patch, 'build_command') and \ | ||
| self.__apply_command(patch, 'quickcheck_command') and \ | ||
| self.__apply_command(patch, 'test_command') | ||
|
|
||
| if success: | ||
| patch.state = 'survived' | ||
| db.session.commit() | ||
|
|
||
| # step 4: revert patch | ||
| self.__execute_command_timeout('patch -p1 --reverse --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), | ||
| cwd='/') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the rationale for this changed block?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed to work properly on Ubuntu 16.04. If launch |
||
|
|
||
| # step 6: delete patch file | ||
| os.remove(patchfile.name) | ||
| # step 6: delete patch file | ||
| os.remove(patchfile.name) | ||
|
|
||
| self.__current_patch = None | ||
| self.__current_patch = None | ||
|
|
||
| def __apply_command(self, patch: Patch, step: str): | ||
| print(patch, step) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,14 +117,14 @@ def __create_patch(self, line_number: int, replacement: Replacement) -> str: | |
| )) | ||
|
|
||
| # lines: context before | ||
| patch_lines += [' ' + x + '\n' for x in context_before] | ||
| patch_lines += [' ' + x + "\r\n" for x in context_before] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Git can clone files with different line endings mode. By default, as I guess, git clone with |
||
| # line: the old value | ||
| patch_lines.append('-' + old_line + '\n') | ||
| patch_lines.append('-' + old_line + "\r\n") | ||
| # line: the new value | ||
| if replacement.new_val is not None: | ||
| patch_lines.append('+' + new_line + '\n') | ||
| patch_lines.append('+' + new_line + "\r\n") | ||
| # lines: context after | ||
| patch_lines += [' ' + x + '\n' for x in context_after] | ||
| patch_lines += [' ' + x + "\r\n" for x in context_after] | ||
|
|
||
| patch_text = ''.join(patch_lines) | ||
| return patch_text | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| # coding=utf-8 | ||
|
|
||
| from migrate.versioning import api | ||
| from config import SQLALCHEMY_DATABASE_URI | ||
| from config import SQLALCHEMY_MIGRATE_REPO | ||
| from app.config import SQLALCHEMY_DATABASE_URI | ||
| from app.config import SQLALCHEMY_MIGRATE_REPO | ||
| from app import db | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't these changes also be required in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so. I didn't use these scripts, so didn't make any changes to them. |
||
| import os.path | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never needed that so far. Is this to make the code robust against the working directory?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this line is for
create_db.pyto be working when launched exactly from the root directory of the repository. I had problems withfrom config import ...Python couldn't find moduleconfig. And when I added this line toapp/__init__.pycreate_db.pybecame working.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, user can tune python's environment so all will work without this line. But I'm not sure about
from config import ...., why notfrom app.config import ....?