Skip to content

Commit 6834258

Browse files
authored
Restore the modified project files after testing. (#247)
Revert all the applied patched and restore all the modified files. JSRemoteTest-DCO-1.0-Signed-off-by: Roland Takacs [email protected]
1 parent 30b0f32 commit 6834258

File tree

5 files changed

+76
-31
lines changed

5 files changed

+76
-31
lines changed

jstest/__main__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from jstest import flasher, paths, pseudo_terminal, twisted_server, utils
2525

2626

27+
EXIT_SUCCESS = 0
28+
EXIT_FAILURE = 1
29+
30+
2731
def parse_options():
2832
'''
2933
Parse the given options.
@@ -210,6 +214,7 @@ def main():
210214
'''
211215
user_options = adjust_options(parse_options())
212216
testresult = TestResult(user_options)
217+
exitcode = EXIT_SUCCESS
213218

214219
try:
215220
# Execute all the jobs defined in the runnable.jobs file.
@@ -230,11 +235,16 @@ def main():
230235
testresult.upload()
231236

232237
except (Exception, KeyboardInterrupt) as e:
233-
jstest.resources.patch_modules(env, revert=True)
234-
jstest.console.error('[%s] %s' % (type(e).__name__, str(e)))
235-
traceback.print_exc()
238+
# Don't print backtrace for keyboard interrupt.
239+
if isinstance(e, Exception):
240+
traceback.print_exc()
241+
242+
exitcode = EXIT_FAILURE
243+
244+
# Revert all the patches and restore all the modified files.
245+
jstest.resources.finalize(env)
236246

237-
sys.exit(1)
247+
sys.exit(exitcode)
238248

239249

240250
if __name__ == '__main__':

jstest/builder/builder.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def __init__(self, env):
6868
return
6969

7070
# Fetch and configure the modules before build.
71-
resources.fetch_modules(env)
72-
resources.config_modules(env)
73-
resources.patch_modules(env)
71+
resources.initialize(env)
7472

7573
def build(self):
7674
'''
@@ -87,8 +85,6 @@ def build(self):
8785

8886
# Create build information.
8987
builder_utils.create_build_info(self.env)
90-
# Revert all the patches from the projects.
91-
resources.patch_modules(self.env, revert=True)
9288

9389
def should_build(self, build_info):
9490
'''

jstest/common/utils.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,41 @@ def is_broken_symlink(path):
433433
return True
434434

435435

436+
def remove(fpath):
437+
'''
438+
Remove the resource file.
439+
'''
440+
resource = os.path.normpath(fpath)
441+
442+
if exists(resource):
443+
if os.path.islink(resource):
444+
os.unlink(resource)
445+
446+
elif os.path.isfile(resource):
447+
remove_file(resource)
448+
449+
else:
450+
rmtree(resource)
451+
452+
elif is_broken_symlink(resource):
453+
os.unlink(resource)
454+
455+
456+
def restore_file(project, fpath):
457+
'''
458+
Restore the modified project files.
459+
'''
460+
project_files, _ = execute(project, 'git', ['ls-files'], quiet=True)
461+
resource_name = relpath(fpath, project)
462+
463+
if resource_name in project_files:
464+
execute(project, 'git', ['checkout', fpath], quiet=True)
465+
466+
else:
467+
# The file doesn't belong to the project, so that can be removed.
468+
remove(fpath)
469+
470+
436471
def symlink(src, dst):
437472
'''
438473
Create a symlink at dst pointing to src
@@ -445,14 +480,6 @@ def symlink(src, dst):
445480
dst = os.path.normpath(dst)
446481

447482
# Existing dst needs to be deleted, since symlink requires non-existing dst.
448-
if exists(dst):
449-
if os.path.islink(dst):
450-
os.unlink(dst)
451-
elif os.path.isfile(dst):
452-
remove_file(dst)
453-
else:
454-
rmtree(dst)
455-
elif is_broken_symlink(dst):
456-
os.unlink(dst)
483+
remove(dst)
457484

458485
os.symlink(src, dst)

jstest/resources/__init__.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def fetch_modules(env):
3333
utils.execute(module['src'], 'git', ['submodule', 'update', '--init'])
3434

3535

36-
def config_modules(env):
36+
def config_modules(env, revert=False):
3737
'''
3838
Configure all the required modules.
3939
'''
@@ -45,7 +45,11 @@ def config_modules(env):
4545
if not eval(condition):
4646
continue
4747

48-
utils.symlink(config['src'], config['dst'])
48+
if revert:
49+
utils.restore_file(module['src'], config['dst'])
50+
51+
else:
52+
utils.symlink(config['src'], config['dst'])
4953

5054

5155
def patch_modules(env, revert=False):
@@ -61,14 +65,24 @@ def patch_modules(env, revert=False):
6165
if not eval(condition):
6266
continue
6367

64-
revertable = patch.get('revert', True)
65-
# Note: some patches should not be removed
66-
# because sometimes the testing requires the
67-
# modifications.
68-
if revert and not revertable:
69-
continue
70-
7168
# By default, the project is patched. If there is a
7269
# submodule information, the subproject will be patched.
7370
project = patch.get('submodule', module['src'])
7471
utils.patch(project, patch['file'], revert)
72+
73+
74+
def initialize(env):
75+
'''
76+
Public method to initialize the project.
77+
'''
78+
fetch_modules(env)
79+
config_modules(env)
80+
patch_modules(env)
81+
82+
83+
def finalize(env):
84+
'''
85+
Public method to restore the project files.
86+
'''
87+
config_modules(env, revert=True)
88+
patch_modules(env, revert=True)

jstest/resources/resources.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@
8484
"file": "%{patches}/tizenrt-coverage.diff"
8585
},
8686
{
87-
"file": "%{patches}/tizenrt-openocd.diff",
88-
"revert": false
87+
"file": "%{patches}/tizenrt-openocd.diff"
8988
}
9089
]
9190
}
@@ -234,8 +233,7 @@
234233
{
235234
"condition": "'%{device}' in ['artik053', 'artik530', 'rpi2'] and %{coverage}",
236235
"file": "%{patches}/coverage-client.diff",
237-
"submodule": "%{iotjs}/deps/jerry/",
238-
"revert": false
236+
"submodule": "%{iotjs}/deps/jerry/"
239237
},
240238
{
241239
"condition": "'%{device}' in ['artik530', 'rpi2'] and %{memstat}",

0 commit comments

Comments
 (0)