示例#1
0
 def __init__(self, ctl, ccver, platform, config, logfile, verbose):
     self.clsname = self.__class__.__name__
     self.version = 1.0
     #
     self.ctl = ctl
     self.ccver = ccver
     self.platform = platform
     self.config = config
     self.logfile = logfile
     self.verbose = verbose
     #
     # このファイルは ".../core/test/bin" に置くこと
     script_dir = os.path.abspath(__file__).split(os.sep)[:-1]
     script_dir = os.sep.join(script_dir)
     setup_file = script_dir + '../../../src/setup.conf'
     setup_file = os.path.abspath(setup_file)
     self.setup_file_exists = False
     if os.path.exists(setup_file):
         print('  setup file exists')
         self.setup_file_exists = True
         self.sf = SetupFile(setup_file)
         self.sf.setenv()
     #
     self.generator = self.__find_generator(ccver)
     self.error = Error(self.clsname)
示例#2
0
class CMake:
    #  Class constant.section
    #
    GENERATOR = {
        'unix': '"Unix Makefiles"',
        2015: '"Visual Studio 14 2015" -A x64',
        2017: '"Visual Studio 15 2017" -A x64',
        2019: '"Visual Studio 16 2019" -A x64'
    }

    #  Class initializer
    #
    def __init__(self, ctl, ccver, platform, config, logfile, verbose):
        self.clsname = self.__class__.__name__
        self.version = 1.0
        #
        self.ctl = ctl
        self.ccver = ccver
        self.platform = platform
        self.config = config
        self.logfile = logfile
        self.verbose = verbose
        #
        # このファイルは ".../core/test/bin" に置くこと
        script_dir = os.path.abspath(__file__).split(os.sep)[:-1]
        script_dir = os.sep.join(script_dir)
        setup_file = script_dir + '../../../src/setup.conf'
        setup_file = os.path.abspath(setup_file)
        self.setup_file_exists = False
        if os.path.exists(setup_file):
            print('  setup file exists')
            self.setup_file_exists = True
            self.sf = SetupFile(setup_file)
            self.sf.setenv()
        #
        self.generator = self.__find_generator(ccver)
        self.error = Error(self.clsname)

    #  Prepare CMake environment.
    #
    def preparation(self):
        # ======================================================
        #  If "CMakeLists.txt.dist" exists here, we must be
        #  in a Springhead Library creating step.
        # ======================================================
        if self.verbose:
            print('cmake: preparation')
        cwd = os.getcwd()
        srcfile = '%s/CMakeLists.txt.dist' % cwd
        dstfile = '%s/CMakeLists.txt' % cwd
        status = 0
        if os.path.exists(srcfile):
            #  Need to copy dist file to CMakeLists.txt.
            status = FileOp(verbose=0).cp(srcfile, dstfile)
        elif not os.path.exists(dstfile):
            status = -1
            srcfile = dstfile
        if status != 0:
            self.error.error('"%s" not found' % srcfile)
        return status

    #  Configure and generate solution file.
    #
    def config_and_generate(self):
        if self.verbose:
            print('cmake: generation start')
        #  Create work directory if not exists.
        #
        blddir = self.ctl.get(CFK.CMAKE_BLDDIR)
        if self.verbose and not os.path.exists(blddir):
            cwd = Util.pathconv(os.getcwd(), to='unix')
            if self.verbose:
                print('  create directory %s/%s' % (cwd, blddir))
        os.makedirs(blddir, exist_ok=True)

        #  Execuete cmake.
        #
        libtype = self.ctl.get(CFK.LIB_TYPE)
        topdir = self.ctl.get(CFK.CMAKE_TOPDIR)
        blddir = self.ctl.get(CFK.CMAKE_BLDDIR)
        conf = self.ctl.get(CFK.CMAKE_CONF_FILE)
        opts = self.ctl.get(CFK.CMAKE_OPTS_FILE)
        cmake_options = self.ctl.get(CFK.CMAKE_OPTIONS)
        #
        cmnd = 'cmake'
        if self.setup_file_exists:
            cmnd = self.sf.getenv('cmake')
        if topdir: cmnd += ' -D TOPDIR=%s' % topdir
        if conf: cmnd += ' -D CONF=%s' % conf
        if opts: cmnd += ' -D OPTS=%s' % opts
        if cmake_options:
            cmnd += ' ' + cmake_options
        if not libtype:
            libtype = 'STATIC'
        cmnd += ' -B %s' % blddir
        cmnd += ' -G %s' % self.generator
        cmnd += ' -D LIBTYPE=%s -D SPRLIBTYPE=%s' % (libtype, libtype)
        #
        logobj = self.__open(self.logfile)
        proc = Proc(verbose=0)  #self.verbose)
        status = proc.execute(cmnd,
                              shell=True,
                              stdout=logobj,
                              stderr=proc.STDOUT).wait()
        logobj.close()
        if self.verbose:
            print('  configure/generate done with code %d' % status)
        if status != 0:
            return None
        #
        if (Util.is_unix()):
            return "Makefile"
        slnfile = self.__find_slnfile()
        if slnfile is None:
            self.error.error('found more than two solution files')
        if self.verbose:
            print('  solution file is %s' % slnfile)
            print('cmake: generation end')
        return slnfile

    # --------------------------------------------------------------
    #  For class private use
    # --------------------------------------------------------------

    ##  Find generator string.
    #
    def __find_generator(self, ccver):
        if (Util.is_unix()):
            return self.GENERATOR['unix']
        generator = 2015  # default
        if ccver in ['14.0', '14', 'v140', '2015']:
            ccver = 2015
        elif ccver in ['15.0', '15', 'v141', '2017']:
            ccver = 2017
        elif ccver in ['16.0', '16', 'v142', '2019']:
            ccver = 2019
        return self.GENERATOR[ccver]

    ##  Find solution file name.
    #
    def __find_slnfile(self):
        names = glob.glob('%s/*.sln' % self.ctl.get(CFK.CMAKE_BLDDIR))
        return names[0] if len(names) == 1 else None

    ##  Open logfile (directory is created if necessary).
    #
    def __open(self, logpath):
        path = logpath.split('/')
        if (Util.is_unix()):
            path = path[1:]
        if len(path) > 1:
            os.makedirs(path[:-1][0], exist_ok=True)
        return open(logpath, 'a')
示例#3
0
    srcdir = 'src'
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++
sys.path.append(libdir)
from SetupFile import *
from KvFile import *
from Util import *
from Proc import *
from Error import *

# ----------------------------------------------------------------------
#  Set environment variables
#
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++
if SetupExists:
    print('%s: 移行処理' % prog)
    sf = SetupFile('%s/setup.conf' % SrcDir, verbose=1)
    sf.setenv()
    python = sf.getenv('python')
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++

# ----------------------------------------------------------------------
#  Options
#
usage = 'Usage: %prog [options]'
parser = OptionParser(usage=usage)
parser.add_option('-d',
                  '--srctop',
                  dest='srctop',
                  default=srcdir,
                  metavar='DIR',
                  help='top directory of src tree [default: %default]')
示例#4
0
#  Springhead python library の導入
#
libdir = '%s/RunSwig/pythonlib' % SrcDir
sys.path.append(libdir)
from SetupFile import *
from TextFio import *
from FileOp import *
from Error import *
from Util import *
from Proc import *

# ------------------------------------------------------------------
#  セットアップファイルが存在するならば準備をしておく
#
if SetupExists:
    sf = SetupFile('%s/setup.conf' % SrcDir, verbose=1)
    sf.setenv()

# ----------------------------------------------------------------------
#  ディレクトリパスには絶対パスを使用する (cmake 使用時の混乱を避けるため)
#
sprtop = os.path.abspath('%s/../..' % SrcDir)
bindir = '%s/core/bin' % sprtop
incdir = '%s/core/include' % sprtop
srcdir = '%s/core/src' % sprtop
framework_dir = '%s/Framework' % srcdir
tmpdir = '%s/core/swigtmp' % sprtop
tmpdir = '%s/core/src/RunSwig/tmp' % sprtop

# ----------------------------------------------------------------------
#  モジュール名定義
示例#5
0
#
prog_registered = {}
vers_registered = {}
prog_scanned = {}
vers_scanned = {}
progs_lacking = []

if repository is not None:
    os.chdir(os.path.abspath('../../../%s/core/src' % repository))

if os.path.exists(setup_file):
    ##print()
    print('setup file ("%s") exists.' % U.upath(setup_file))

    # ファイル内容の整合性の検査
    sf = SetupFile(setup_file, verbose=verbose, register=True)
    keys_prog = sf.get_keys(sf.PROG)
    keys_path = sf.get_keys(sf.PATH)

    for prog in required:
        print('-- checking path for %s ... ' % prog, end='')
        if not prog in keys_prog:
            prog_registered[prog] = None
            vers_registered[prog] = SetupFile.NOTFOUND
            print('%s' % SetupFile.NOTFOUND)
            progs_lacking.append(prog)
            continue
        path = sf.get_prog(prog)
        prog_registered[prog] = path
        if path == SetupFile.NOTFOUND:
            print('%s' % path)
示例#6
0
sys.path.append('..')
from SetupFile import *

# ----------------------------------------------------------------------
prog = sys.argv[0].split(os.sep)[-1].split('.')[0]
verbose = 1
setupfile = 'test/setup.conf'


# ----------------------------------------------------------------------
def Print(msg, indent=2):
    print('%s%s' % (' ' * indent, msg))


# ----------------------------------------------------------------------
S = SetupFile(setupfile, verbose=1, register=True)
print('Test program for class: %s, Ver %s\n' % (S.clsname, S.version))

# remove setup file if exists
if os.path.exists(setupfile):
    print('-- remove existent file --')
    os.remove(setupfile)

# make new setup file
#
print('-- setup new data --')
S.add_prog('prog1', '/home/usr/foo/bin/prog1')
S.add_prog('prog2', 'C:\\Users\\usr\\bar\\bin\\prog2')

S.add_path('path1', '/home/usr/foo/bin')
S.add_path('path2', 'C:\\Users\\usr\\bar\\bin')
示例#7
0
    if python_path is None:
        Error(prog).abort('can not found python path')
    print('using %s' % Util.upath(python_path))

    # setup paths
    cmnd = '%s setup.py -c %s' % (python_path, python_path)
    stat = proc.execute(cmnd, shell=True).wait()
    os.chdir(cwd)
    if stat == -1:
        Error(prog).info('can\'t setup test environment.')
        Error(prog).info('execute "%s" first.' % setup_script)
        sys.exit(1)
    if stat < 0:
        Error(prog).abort('botch: setup file not found')
    #
    sf = SetupFile(setup_file)
    sf.setenv()
    python = os.getenv('python')
    print()
    print('using setup file "%s"' % setup_file)

elif os.path.exists('%s/Python/python.exe' % ToolsDir):
    # DailyBuild のための特別措置
    python = '%s/Python/python.exe' % ToolsDir
    print('using "%s"' % python)
else:
    Error(prog).warn('setup file "%s" not found' % setup_file)

# ----------------------------------------------------------------------
#  5th step: Execute DailyBuild test.
#
# ----------------------------------------------------------------------
#  Springhead python library の導入
#
libdir = '%s/RunSwig/pythonlib' % SrcDir
sys.path.append(libdir)
from SetupFile import *
from TextFio import *
from Proc import *
from Util import *
from Error import *

# ----------------------------------------------------------------------
#  セットアップファイルが存在するならば準備をしておく
#
if SetupExists:
	sf = SetupFile('%s/setup.conf' % SrcDir, verbose=1)
	sf.setenv()

# ----------------------------------------------------------------------
#  ディレクトリパスには絶対パスを使用する (cmake 使用時の混乱を避けるため)
#
basedir = os.path.abspath('%s/..' % SrcDir)
bindir	= '%s/bin' % basedir
srcdir	= '%s/src' % basedir
incdir	= '%s/include' % basedir
etcdir	= '%s/RunSwig' % srcdir
embpythondir = '.'

# ----------------------------------------------------------------------
#  依存関係にはないと見做すファイルの一覧
#
示例#9
0
def RunSwig(module, dept='', verbose=0, dry_run=False):
	prog = sys._getframe().f_code.co_name
	trace =  Trace().flag('RunSwig')
	if trace:
		print('ENTER: %s(%s, %s)' % (prog, module, dept))
		sys.stdout.flush()

	incdir_rel = Util.upath(os.path.relpath(incdir))
	srcdir_rel = Util.upath(os.path.relpath(srcdir))

	args = [module]
	args.extend(dept.split(','))
	target_list = args[::-1]		# 逆順にした

	# ----------------------------------------------------------------------
	#  Springhead 拡張版の swig を起動するためのパス.
	#
	addpath = os.pathsep.join([swigbindir, bindir])

	# ----------------------------------------------------------------------
	#  生成するファイル名
	#
	interfacefile = '%s.i' % module
	makefile = '%sStub.makefile' % module
	stubfile = '%sStub.cpp' % module

	# ----------------------------------------------------------------------
	#  ヘッダファイル情報を収集する.
	#
	incf_names = ['Springhead.h', 'Base/Env.h', 'Base/BaseDebug.h']
	srcf_names = []		# ['Foundation/UTTypeDesc.h']
	auxdep_inc = list(map(lambda x: '%s/%s' % (incdir_rel, x), incf_names))
	auxdep_src = list(map(lambda x: '%s/%s' % (srcdir_rel, x), srcf_names))
	auxdep = copy.deepcopy(auxdep_inc)
	auxdep.extend(auxdep_src)

	srcinf = []
	srcimp = []
	srcinfdep = []
	srcimpdep = []
	for target in target_list:
		srcinf.extend(glob.glob('%s/%s/*.h' % (incdir_rel, target)))
		srcimp.extend(glob.glob('%s/%s/*.h' % (srcdir_rel, target)))
		srcinfdep.extend(glob.glob('%s/%s/*.h' % (incdir_rel, target)))
		srcimpdep.extend(glob.glob('%s/%s/*.h' % (srcdir_rel, target)))
	srcinf = Util.upath(srcinf)
	srcimp = Util.upath(srcimp)
	srcinfdep = Util.upath(srcinfdep)
	srcimpdep = Util.upath(srcimpdep)
	if verbose:
		print('srcinf: %s' % srcinf)
		print('srcimp: %s' % srcimp)
		print('srcinfdep: %s' % srcinfdep)
		print('srcimpdep: %s' % srcimpdep)

	# ----------------------------------------------------------------------
	#  インターフェイスファイルを生成する.
	#
	lines = []
	lines.append('#\tDo not edit. RunSwig.py will update this file.')
	lines.append('%%module %s' % module)
	lines.append('#define DOUBLECOLON ::')
	for fname in auxdep_inc:
		lines.append('%%include "%s"' % fname)
	for fname in srcinf:
		lines.append('%%include "%s"' % fname)
	for fname in auxdep_src:
		lines.append('%%include "%s"' % fname)
	for fname in srcimp:
		lines.append('%%include "%s"' % fname)
	#
	#
	path = '%s/%s' % (os.getcwd(), interfacefile)
	print('\t%s: generating "%s"' % (prog, Util.upath(path)))
	sys.stdout.flush()
	output(interfacefile, lines, verbose)

	# ----------------------------------------------------------------------
	#  make で使用する外部スクリプト
	#
	if SetupExists:
		sf = SetupFile('%s/setup.conf' % SrcDir, verbose=1)
		sf.setenv()
		python = sf.getenv('python')
		if Util.is_unix():
			make = sf.getenv('gmake')
		else:
			make = '%s /NOLOGO' % sf.getenv('nmake')
		swig = sf.getenv('swig')
	else:
		python = 'python'
		make = 'gmake' if Util.is_unix() else 'nmake /NOLOGO'
		swig = 'swig'

	# ----------------------------------------------------------------------
	#  makefile を生成する.
	#
	deptlist = []
	deptlist.extend(auxdep)
	deptlist.extend(srcinfdep)
	deptlist.extend(srcimpdep)
	lines = []
	lines.append('#\tDo not edit. RunSwig.py will update this file.')
	lines.append('all:\t%s' % stubfile)
	lines.append('')
	lines.append('%s:\t\\' % stubfile)
	lines.append('\t%s' % '\\\n\t'.join(Util.pathconv(deptlist)))
	line = Util.pathconv('\t%s -I%s/Lib' % (swig, swigbindir))
	line += ' -spr -w305,312,319,325,401,402'
	line += ' -DSWIG_%s -c++ %s' % (module, interfacefile)
	if Util.is_unix():
		lines.append('\t@echo "%s"' % line)
	lines.append(line)
	#
	path = '%s/%s' % (os.getcwd(), makefile)
	print('\t%s: generating "%s"' % (prog, Util.upath(path)))
	sys.stdout.flush()
	output(makefile, lines, verbose)

	# ----------------------------------------------------------------------
	#  make を実行する(ここで必要ならば swig が実行される).
	#
	cmd = '%s -f %s' % (make, Util.pathconv(makefile))
	proc = Proc(dry_run=dry_run)
	proc.execute(cmd, addpath=addpath, shell=True)
	status = proc.wait()
	if status != 0:
		msg = '%s failed (%d)' % (make, status)
		Error(prog).put(msg, exitcode=0, alive=True)
	
	if trace:
		print('LEAVE: %s' % prog)
		sys.stdout.flush()
	return status