diff --git a/cmake/std/PullRequestLinuxDriverTest.py b/cmake/std/PullRequestLinuxDriverTest.py index 6cba5eb4d7be..8bb388d86af8 100755 --- a/cmake/std/PullRequestLinuxDriverTest.py +++ b/cmake/std/PullRequestLinuxDriverTest.py @@ -419,6 +419,43 @@ def compute_n(): 'Trilinos_pullrequest_python_3': 'PullRequestLinuxPython3.cmake'} +def createPackageEnables(arguments): + enable_map = {'Trilinos_pullrequest_python_2': 'TrilinosFrameworkTests', + 'Trilinos_pullrequest_python_3': 'TrilinosFrameworkTests'} + + try: + if arguments.job_base_name not in enable_map: + subprocess.check_call([os.path.join(arguments.workspaceDir, + 'Trilinos', + 'commonTools', + 'framework', + 'get-changed-trilinos-packages.sh'), + os.path.join('origin', arguments.targetBranch), + 'HEAD', + 'packageEnables.cmake']) + else: + with open('packageEnables.cmake', 'w') as f_out: + f_out.write(''' +MACRO(PR_ENABLE_BOOL VAR_NAME VAR_VAL) + MESSAGE("-- Setting ${VAR_NAME} = ${VAR_VAL}") + SET(${VAR_NAME} ${VAR_VAL} CACHE BOOL "Set in $CMAKE_PACKAGE_ENABLES_OUT") +ENDMACRO() + +PR_ENABLE_BOOL(Trilinos_ENABLE_''' + enable_map[arguments.job_base_name] + ''' ON) +''') + print('Enabled packages:') + cmake_rstring = subprocess.check_output(['cmake', + '-P', + 'packageEnables.cmake'], + stderr=subprocess.STDOUT) + if sys.version_info.major is not 3: + print(cmake_rstring) + else: + print(str(cmake_rstring, 'ASCII')) + except subprocess.CalledProcessError as cpe: + print('There was an issue generating packageEnables.cmake. ' + 'The error code was: {}'.format(cpe.returncode)) + def run(): return_value = True arguments = parse_args() @@ -448,6 +485,8 @@ def run(): CDash_Track = getCDashTrack() + createPackageEnables(arguments) + parallel_level = compute_n() build_name = "PR-{PULLREQUESTNUM}-test-{JOB_BASE_NAME}-{BUILD_NUMBER}". \ diff --git a/cmake/std/unittests/TestPullRequestLinuxDriverTest.py b/cmake/std/unittests/TestPullRequestLinuxDriverTest.py index 8d6edf351619..27e3b23c24c3 100755 --- a/cmake/std/unittests/TestPullRequestLinuxDriverTest.py +++ b/cmake/std/unittests/TestPullRequestLinuxDriverTest.py @@ -24,7 +24,7 @@ import unittest.mock as mock from argparse import Namespace -# from subprocess import CalledProcessError +from subprocess import CalledProcessError import PullRequestLinuxDriverTest @@ -79,7 +79,8 @@ def test_verifyGit_fails_with_old_version(self): else: with self.assertRaisesRegex(SystemExit, bad_git_string): PullRequestLinuxDriverTest.confirmGitVersion() - m_check_out.assert_called_once_with(['git', '--version']) + + m_check_out.assert_called_once_with(['git', '--version']) def test_verifyGit_passes_with_2_10(self): @@ -87,13 +88,9 @@ def test_verifyGit_passes_with_2_10(self): with self.m_check_out as m_check_out: m_check_out.return_value='git version 2.10.1' - if sys.version_info.major is not 3: - with self.IOredirect: - PullRequestLinuxDriverTest.confirmGitVersion() - else: - with self.IOredirect: - PullRequestLinuxDriverTest.confirmGitVersion() - m_check_out.assert_called_once_with(['git', '--version']) + with self.IOredirect: + PullRequestLinuxDriverTest.confirmGitVersion() + m_check_out.assert_called_once_with(['git', '--version']) def test_verifyGit_passes_with_2_12(self): @@ -101,12 +98,8 @@ def test_verifyGit_passes_with_2_12(self): with self.m_check_out as m_check_out: m_check_out.return_value='git version 2.12.4' - if sys.version_info.major is not 3: - with self.IOredirect: - PullRequestLinuxDriverTest.confirmGitVersion() - else: - with self.IOredirect: - PullRequestLinuxDriverTest.confirmGitVersion() + with self.IOredirect: + PullRequestLinuxDriverTest.confirmGitVersion() m_check_out.assert_called_once_with(['git', '--version']) @@ -115,12 +108,8 @@ def test_verifyGit_passes_with_3_x(self): with self.m_check_out as m_check_out: m_check_out.return_value='git version 3.6.1' - if sys.version_info.major is not 3: - with self.IOredirect: - PullRequestLinuxDriverTest.confirmGitVersion() - else: - with self.IOredirect: - PullRequestLinuxDriverTest.confirmGitVersion() + with self.IOredirect: + PullRequestLinuxDriverTest.confirmGitVersion() m_check_out.assert_called_once_with(['git', '--version']) @@ -202,6 +191,7 @@ def test_verifyTargetBranch_passes_with_master_target_mm_source(self): self.m_check_call as m_call, \ l_argv, \ self.m_environ, \ + mock.patch('PullRequestLinuxDriverTest.createPackageEnables'), \ mock.patch('PullRequestLinuxDriverTest.setBuildEnviron'), \ mock.patch('PullRequestLinuxDriverTest.getCDashTrack'): PullRequestLinuxDriverTest.run() @@ -258,6 +248,7 @@ def test_verifyTargetBranch_passes_with_develop_target(self): self.m_check_call as m_call, \ l_argv, \ self.m_environ, \ + mock.patch('PullRequestLinuxDriverTest.createPackageEnables'), \ mock.patch('PullRequestLinuxDriverTest.setBuildEnviron'), \ mock.patch('PullRequestLinuxDriverTest.getCDashTrack', return_value='testTrack'): @@ -277,6 +268,95 @@ def test_verifyTargetBranch_passes_with_develop_target(self): '-Dsubprojects_file=../TFW_single_configure_support_scripts/package_subproject_list.cmake']) +class Test_createPackageEnables(unittest.TestCase): + + def setUp(self): + self.source_branch = 'incoming_branch' + self.source_url = '/dev/null/source/Trilinos.git' + self.target_branch = 'base_branch' + self.target_url = '/dev/null/target/Trilinos.git' + self.job_base_name = 'JenkinsBaseName' + self.github_pr_number = '8888' + self.jenkins_build_number = '7777' + self.jenkins_workspace='/dev/null/workspace' + + self.arguments = Namespace() + setattr(self.arguments, 'sourceBranch', self.source_branch) + setattr(self.arguments, 'sourceRepo', self.source_url) + setattr(self.arguments, 'targetBranch', self.target_branch) + setattr(self.arguments, 'targetRepo', self.target_url) + setattr(self.arguments, 'job_base_name', self.job_base_name) + setattr(self.arguments, 'github_pr_number', self.github_pr_number) + setattr(self.arguments, 'workspaceDir', self.jenkins_workspace) + + + def success_side_effect(self): + with open('packageEnables.cmake', 'w') as f_out: + f_out.write(''' +MACRO(PR_ENABLE_BOOL VAR_NAME VAR_VAL) + MESSAGE("-- Setting ${VAR_NAME} = ${VAR_VAL}") + SET(${VAR_NAME} ${VAR_VAL} CACHE BOOL "Set in $CMAKE_PACKAGE_ENABLES_OUT") +ENDMACRO() +''') + f_out.write("PR_ENABLE_BOOL(Trilinos_ENABLE_FooPackageBar ON)") + + def test_call_success(self): + expected_output = '''Enabled packages: +-- Setting Trilinos_ENABLE_FooPackageBar = ON + +''' + with mock.patch('subprocess.check_call', + side_effect=self.success_side_effect()) as m_out, \ + mock.patch('sys.stdout', + new_callable=StringIO) as m_stdout: + PullRequestLinuxDriverTest.createPackageEnables(self.arguments) + m_out.assert_called_once_with([os.path.join(self.jenkins_workspace, + 'Trilinos', + 'commonTools', + 'framework', + 'get-changed-trilinos-packages.sh'), + os.path.join('origin', + self.target_branch), + 'HEAD', 'packageEnables.cmake']) + self.assertEqual(expected_output, m_stdout.getvalue()) + os.unlink('packageEnables.cmake') + + def test_call_python2(self): + expected_output = '''Enabled packages: +-- Setting Trilinos_ENABLE_TrilinosFrameworkTests = ON + +''' + + l_arguments = self.arguments + l_arguments.job_base_name = 'Trilinos_pullrequest_python_2' + with mock.patch('subprocess.check_call', + side_effect=self.success_side_effect()) as m_out, \ + mock.patch('sys.stdout', new_callable=StringIO) as m_stdout: + PullRequestLinuxDriverTest.createPackageEnables(l_arguments) + m_out.assert_not_called() + self.assertEqual(expected_output, m_stdout.getvalue()) + os.unlink('packageEnables.cmake') + + def test_call_failure(self): + expected_output = '''There was an issue generating packageEnables.cmake. The error code was: 39 +''' + with mock.patch('subprocess.check_call', + side_effect=CalledProcessError(cmd='cmake', + returncode=39)) as m_out, \ + mock.patch('sys.stdout', + new_callable=StringIO) as m_stdout: + PullRequestLinuxDriverTest.createPackageEnables(self.arguments) + m_out.assert_called_once_with([os.path.join(self.jenkins_workspace, + 'Trilinos', + 'commonTools', + 'framework', + 'get-changed-trilinos-packages.sh'), + os.path.join('origin', + self.target_branch), + 'HEAD', 'packageEnables.cmake']) + self.assertEqual(expected_output, m_stdout.getvalue()) + + class Test_setEnviron(unittest.TestCase): """Does the script exist?"""