Skip to content

Commit

Permalink
add method for compiling code in a branch
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Aug 17, 2022
1 parent 5362733 commit 6893303
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions py/desiutil/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,28 @@ def get_extra(self):
raise DesiInstallException(message)
return

def compile_branch(self):
"""Certain packages need C/C++ code compiled even for a branch install.
"""
if self.is_branch:
compile_script = os.path.join(self.install_dir, 'etc',
'{0}_compile.sh'.format(self.baseproduct))
if os.path.exists(compile_script):
self.log.debug("Detected compile script: %s.", compile_script)
if self.options.test:
self.log.debug('Test Mode. Skipping compile script.')
else:
proc = Popen([compile_script, sys.executable], universal_newlines=True,
stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
status = proc.returncode
self.log.debug(out)
if status != 0 and len(err) > 0:
message = "Error compiling code: {0}".format(err)
self.log.critical(message)
raise DesiInstallException(message)
return

def verify_bootstrap(self):
"""Make sure that desiutil/desiInstall was installed with
an explicit Python executable path.
Expand Down Expand Up @@ -1026,6 +1048,7 @@ def run(self): # pragma: no cover
self.prepare_environment()
self.install()
self.get_extra()
self.compile_branch()
self.verify_bootstrap()
self.permissions()
except DesiInstallException:
Expand Down
34 changes: 34 additions & 0 deletions py/desiutil/test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
"""Test desiutil.install.
"""
import sys
import unittest
from unittest.mock import patch, call, MagicMock, mock_open
from os import chdir, environ, getcwd, mkdir, remove, rmdir
Expand Down Expand Up @@ -507,6 +508,39 @@ def test_get_extra(self, mock_popen, mock_exists):
self.assertLog(-1, message)
self.assertEqual(str(cm.exception), message)

@patch('os.path.exists')
@patch('desiutil.install.Popen')
def test_compile_branch(self, mock_popen, mock_exists):
"""Test compiling code in certain cases.
"""
options = self.desiInstall.get_options(['fiberassign', 'branches/main'])
self.desiInstall.baseproduct = 'fiberassign'
self.desiInstall.is_branch = True
self.desiInstall.install_dir = join(self.data_dir, 'fiberassign')
mock_exists.return_value = True
mock_proc = mock_popen()
mock_proc.returncode = 0
mock_proc.communicate.return_value = ('out', 'err')
self.desiInstall.compile_branch()
# mock_exists.assert_called_once_with(join(self.desiInstall.install_dir, 'etc', 'fiberassign_compile.sh'),
# sys.executable)
mock_popen.assert_has_calls([call([join(self.desiInstall.install_dir, 'etc', 'fiberassign_compile.sh'), sys.executable],
stderr=-1, stdout=-1, universal_newlines=True)], any_order=True)
mock_popen.reset_mock()
self.desiInstall.options.test = True
self.desiInstall.compile_branch()
self.assertLog(-1, 'Test Mode. Skipping compile script.')
mock_popen.reset_mock()
self.desiInstall.options.test = False
mock_proc = mock_popen()
mock_proc.returncode = 1
mock_proc.communicate.return_value = ('out', 'err')
with self.assertRaises(DesiInstallException) as cm:
self.desiInstall.compile_branch()
message = "Error compiling code: err"
self.assertLog(-1, message)
self.assertEqual(str(cm.exception), message)

def test_verify_bootstrap(self):
"""Test proper installation of the desiInstall executable.
"""
Expand Down

0 comments on commit 6893303

Please sign in to comment.