From 7585b573d35a23b215854eabf210c4220c701c10 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Mon, 15 Jun 2020 10:42:37 +0200 Subject: [PATCH] cue: warnings for STATIC and misspelled configuration fixes #47 --- cue-test.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ cue.py | 25 +++++++++++++++++-------- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/cue-test.py b/cue-test.py index 18947b5..e25b6c4 100644 --- a/cue-test.py +++ b/cue-test.py @@ -512,6 +512,28 @@ class TestTravisDetectContext(unittest.TestCase): "ci['configuration'] is {0} (expected: shared-optimized)" .format(cue.ci['configuration'])) + def test_StaticGetsWarning(self): + os.environ['TRAVIS'] = 'true' + os.environ['TRAVIS_OS_NAME'] = 'osx' + os.environ['TRAVIS_COMPILER'] = 'clang' + os.environ['STATIC'] = 'YES' + capturedOutput = getStringIO() + sys.stdout = capturedOutput + cue.detect_context() + sys.stdout = sys.__stdout__ + self.assertRegexpMatches(capturedOutput.getvalue(), "Variable 'STATIC' not supported anymore") + + def test_MisspelledBcfgGetsWarning(self): + os.environ['TRAVIS'] = 'true' + os.environ['TRAVIS_OS_NAME'] = 'osx' + os.environ['TRAVIS_COMPILER'] = 'clang' + os.environ['BCFG'] = 'static-dubug' + capturedOutput = getStringIO() + sys.stdout = capturedOutput + cue.detect_context() + sys.stdout = sys.__stdout__ + self.assertRegexpMatches(capturedOutput.getvalue(), "Unrecognized build configuration setting") + @unittest.skipIf(ci_service != 'appveyor', 'Run appveyor tests only on appveyor') class TestAppveyorDetectContext(unittest.TestCase): @@ -689,6 +711,28 @@ class TestAppveyorDetectContext(unittest.TestCase): .format(cue.ci['configuration'])) self.assertIn('make', cue.ci['choco'], "'make' is not in ci['choco']") + def test_StaticGetsWarning(self): + os.environ['APPVEYOR'] = 'True' + os.environ['APPVEYOR_BUILD_WORKER_IMAGE'] = 'Visual Studio 2019' + os.environ['CMP'] = 'vs2019' + os.environ['STATIC'] = 'YES' + capturedOutput = getStringIO() + sys.stdout = capturedOutput + cue.detect_context() + sys.stdout = sys.__stdout__ + self.assertRegexpMatches(capturedOutput.getvalue(), "Variable 'STATIC' not supported anymore") + + def test_MisspelledConfigurationGetsWarning(self): + os.environ['APPVEYOR'] = 'True' + os.environ['APPVEYOR_BUILD_WORKER_IMAGE'] = 'Visual Studio 2019' + os.environ['CMP'] = 'vs2019' + os.environ['CONFIGURATION'] = 'static-dubug' + capturedOutput = getStringIO() + sys.stdout = capturedOutput + cue.detect_context() + sys.stdout = sys.__stdout__ + self.assertRegexpMatches(capturedOutput.getvalue(), "Unrecognized build configuration setting") + class TestSetupForBuild(unittest.TestCase): args = Namespace(paths=[]) diff --git a/cue.py b/cue.py index 98d28a0..a9c2477 100644 --- a/cue.py +++ b/cue.py @@ -16,6 +16,7 @@ logger = logging.getLogger(__name__) # Detect the service and set up context hash accordingly def detect_context(): + buildconfig = 'default' if 'TRAVIS' in os.environ: ci['service'] = 'travis' ci['os'] = os.environ['TRAVIS_OS_NAME'] @@ -27,10 +28,7 @@ def detect_context(): # Only Visual Studio 2017 available ci['compiler'] = 'vs2017' if 'BCFG' in os.environ: - if re.search('static', os.environ['BCFG']): - ci['static'] = True - if re.search('debug', os.environ['BCFG']): - ci['debug'] = True + buildconfig = os.environ['BCFG'].lower() if 'APPVEYOR' in os.environ: ci['service'] = 'appveyor' @@ -43,10 +41,21 @@ def detect_context(): ci['platform'] = os.environ['PLATFORM'].lower() if 'CMP' in os.environ: ci['compiler'] = os.environ['CMP'] - if re.search('static', os.environ['CONFIGURATION']): - ci['static'] = True - if re.search('debug', os.environ['CONFIGURATION']): - ci['debug'] = True + buildconfig = os.environ['CONFIGURATION'].lower() + + if 'STATIC' in os.environ: + print("{0}WARNING: Variable 'STATIC' not supported anymore; use 'BCFG' instead{1}" + .format(ANSI_RED, ANSI_RESET)) + sys.stdout.flush() + if not re.match(r'^((default|static|shared|dynamic|optimized|debug)-?)+$', buildconfig): + print("{0}WARNING: Unrecognized build configuration setting '{1}'{2}" + .format(ANSI_RED, buildconfig, ANSI_RESET)) + sys.stdout.flush() + + if re.search('static', buildconfig): + ci['static'] = True + if re.search('debug', buildconfig): + ci['debug'] = True if ci['static']: ci['configuration'] = 'static'