appveyor: first version (source_set, update_release_local)

This commit is contained in:
Ralph Lange
2020-02-11 15:57:11 +00:00
parent 761152babe
commit b15d9bb62e
2 changed files with 127 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
# SET=test00 in .appveyor.yml runs the tests in this script
# all other jobs are started as compile jobs
import sys, os
import sys, os, fileinput
import unittest
sys.path.append('appveyor')
@@ -56,11 +56,63 @@ class TestSourceSet(unittest.TestCase):
self.assertEqual(do.setup['SNCSEQ'], 'R2-2-7', 'Setup test01 was not included')
class TestUpdateReleaseLocal(unittest.TestCase):
release_local = os.path.join(do.cachedir, 'RELEASE.local')
def setUp(self):
if os.path.exists(self.release_local):
os.remove(self.release_local)
def test_SetModule(self):
do.update_release_local('MOD1', '/foo/bar')
found = 0
for line in fileinput.input(self.release_local, inplace=1):
if 'MOD1=' in line:
self.assertEqual(line.strip(), 'MOD1=/foo/bar', 'MOD1 not set correctly')
found += 1
fileinput.close()
self.assertEqual(found, 1, 'MOD1 not written once to RELEASE.local (found {0})'.format(found))
def test_SetBaseAndMultipleModules(self):
do.update_release_local('EPICS_BASE', '/bar/foo')
do.update_release_local('MOD1', '/foo/bar')
do.update_release_local('MOD2', '/foo/bar2')
do.update_release_local('MOD1', '/foo/bar1')
foundmod1 = 0
foundmod2 = 0
foundbase = 0
for line in fileinput.input(self.release_local, inplace=1):
if 'MOD1=' in line:
self.assertEqual(line.strip(), 'MOD1=/foo/bar1',
'MOD1 not set correctly (expected \'MOD1=/foo/bar1\' found \'{0}\')'
.format(line))
foundmod1 += 1
foundmod1at = fileinput.filelineno()
if 'MOD2=' in line:
self.assertEqual(line.strip(), 'MOD2=/foo/bar2',
'MOD2 not set correctly (expected \'MOD2=/foo/bar2\' found \'{0}\')'
.format(line))
foundmod2 += 1
foundmod2at = fileinput.filelineno()
if 'EPICS_BASE=' in line:
self.assertEqual(line.strip(), 'EPICS_BASE=/bar/foo',
'EPICS_BASE not set correctly (expected \'EPICS_BASE=/bar/foo\' found \'{0}\')'
.format(line))
foundbase += 1
foundbaseat = fileinput.filelineno()
fileinput.close()
self.assertEqual(foundmod1, 1, 'MOD1 does not appear once in RELEASE.local (found {0})'.format(foundmod1))
self.assertEqual(foundmod2, 1, 'MOD2 does not appear once in RELEASE.local (found {0})'.format(foundmod2))
self.assertEqual(foundbase, 1, 'EPICS_BASE does not appear once in RELEASE.local (found {0})'.format(foundbase))
self.assertGreater(foundbaseat, foundmod2at,
'EPICS_BASE (line {0}) appears before MOD2 (line {1})'.format(foundbaseat, foundmod2at))
self.assertGreater(foundmod2at, foundmod1at,
'MOD2 (line {0}) appears before MOD1 (line {1})'.format(foundmod2at, foundmod1at))
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestSourceSet)
unittest.TextTestRunner(verbosity=2).run(suite)
# unittest.main()
# suite = unittest.TestLoader().loadTestsFromTestCase(TestUpdateReleaseLocal)
# unittest.TextTestRunner(verbosity=2).run(suite)
unittest.main()

View File

@@ -2,11 +2,12 @@
"""Windows (AppVeyor) ci build script
"""
import sys, os
from __future__ import print_function
import sys, os, fileinput
import logging
import subprocess as SP
import distutils.util
from glob import glob
#logging.basicConfig(level=logging.DEBUG)
@@ -20,6 +21,12 @@ ANSI_CLEAR = "\033[0K"
seen_setups = []
setup = {}
if 'HomeDrive' in os.environ:
cachedir = os.path.join(os.getenv('HomeDrive'), os.getenv('HomePath'), '.cache')
elif 'HOME' in os.environ:
cachedir = os.path.join(os.getenv('HOME'), '.cache')
else:
cachedir = os.path.join('.', '.cache')
# Used from unittests
def clear_lists():
@@ -30,7 +37,7 @@ def clear_lists():
#
# Source a settings file (extension .set) found in the setup_dirs path
# May be called recursively (from within a setup file)
def source_set(args):
def source_set(set):
found = False
setup_dirs = os.getenv('SETUP_PATH', "").replace(':', ' ').split()
@@ -38,7 +45,7 @@ def source_set(args):
raise NameError("{0}Search path for setup files (SETUP_PATH) is empty{1}".format(ANSI_RED,ANSI_RESET))
for set_dir in setup_dirs:
set_file = os.path.join(set_dir, args) + ".set"
set_file = os.path.join(set_dir, set) + ".set"
if set_file in seen_setups:
print("Ignoring already included setup file {0}".format(set_file))
@@ -70,6 +77,66 @@ def source_set(args):
raise NameError("{0}Setup file {1} does not exist in SETUP_PATH search path ({2}){3}"
.format(ANSI_RED,set_file,setup_dirs,ANSI_RESET))
# update_release_local(var, place)
# var name of the variable to set in RELEASE.local
# place place (absolute path) of where variable should point to
#
# Manipulate RELEASE.local in the cache location:
# - replace "$var=$place" line if it exists and has changed
# - otherwise add "$var=$place" line and possibly move EPICS_BASE=... line to the end
def update_release_local(var, place):
release_local = os.path.join(cachedir, 'RELEASE.local')
updated_line = '{0}={1}'.format(var, place)
if not os.path.exists(release_local):
logging.debug('RELEASE.local does not exist, creating it')
try:
os.makedirs(cachedir)
except:
pass
fout = open(release_local, 'w')
fout.close()
base_line = ''
found = False
logging.debug('Opening RELEASE.local for adding {0}={1}'.format(var, place))
for line in fileinput.input(release_local, inplace=1):
if 'EPICS_BASE=' in line:
logging.debug('Found EPICS_BASE line \'{0}\', not writing it'.format(line.strip()))
base_line = line.strip()
continue
elif '{0}='.format(var) in line:
logging.debug('Found \'{0}=\' line, replacing'.format(var))
found = True
line = updated_line
logging.debug('Writing line to RELEASE.local: \'{0}\''.format(line))
print(line)
fileinput.close()
fout = open(release_local,"a")
if not found:
logging.debug('Adding new definition: \'{0}\''.format(updated_line))
print(updated_line, file=fout)
if base_line:
logging.debug('Writing EPICS_BASE line: \'{0}\''.format(base_line))
print(base_line, file=fout)
fout.close()
# add_dependency(dep, tag)
#
# Add a dependency to the cache area:
# - check out (recursive if configured) in the CACHE area unless it already exists and the
# required commit has been built
# - Defaults:
# $dep_DIRNAME = lower case ($dep)
# $dep_REPONAME = lower case ($dep)
# $dep_REPOURL = GitHub / $dep_REPOOWNER (or $REPOOWNER or epics-modules) / $dep_REPONAME .git
# $dep_VARNAME = $dep
# $dep_DEPTH = 5
# $dep_RECURSIVE = 1/YES (0/NO to for a flat clone)
# - Add $dep_VARNAME line to the RELEASE.local file in the cache area (unless already there)
# - Add full path to $modules_to_compile
def add_dependency(dep, tag):
pass
def prepare(args):
print(sys.version)
print('PYTHONPATH')