From cfea4f7ad71439f4b1eac0801602e5ae422b880c Mon Sep 17 00:00:00 2001 From: Nabil Ghodbane Date: Mon, 15 Jul 2019 14:12:43 +0200 Subject: [PATCH] scs #13189: report des modifications pour que SAT fonctionne sous windows --- commands/config.py | 4 ++++ commands/package.py | 19 +++++++++++++++---- src/architecture.py | 2 +- src/compilation.py | 1 + src/environment.py | 36 +++++++++++++++++++++++++++--------- src/fileEnviron.py | 43 +++++++++++++++++++++++++++++++++++++------ src/product.py | 12 ++++++++++++ src/system.py | 29 ++++++++++++++++++++++++----- 8 files changed, 121 insertions(+), 25 deletions(-) diff --git a/commands/config.py b/commands/config.py index 50ad5f7..3d44311 100644 --- a/commands/config.py +++ b/commands/config.py @@ -135,6 +135,10 @@ class ConfigManager: var['srcDir'] = osJoin(var['salometoolsway'], 'src') var['internal_dir'] = osJoin(var['srcDir'], 'internal_config') var['sep']= os.path.sep + if src.architecture.is_windows(): + var['scriptExtension'] = '.bat' + else: + var['scriptExtension'] = '.sh' # datadir has a default location var['datadir'] = osJoin(var['salometoolsway'], 'data') diff --git a/commands/package.py b/commands/package.py index ec2a16c..267a293 100644 --- a/commands/package.py +++ b/commands/package.py @@ -342,10 +342,17 @@ def produce_relative_env_files(config, file_dir, src_root=None) + if src.architecture.is_windows(): + shell = "bat" + filename = "env_launch.bat" + else: + shell = "bash" + filename = "env_launch.sh" + # Write - filepath = writer.write_env_file("env_launch.sh", + filepath = writer.write_env_file(filename, False, # for launch - "bash", + shell, for_package = binaries_dir_name) # Little hack to put out_dir_Path as environment variable @@ -674,8 +681,12 @@ WARNING: existing binaries directory from previous detar installation: tmp_working_dir, binaries_dir_name) - d_products["environment file"] = (env_file, "env_launch.sh") - + if src.architecture.is_windows(): + filename = "env_launch.bat" + else: + filename = "env_launch.sh" + d_products["environment file"] = (env_file, filename) + return d_products def source_package(sat, config, logger, options, tmp_working_dir): diff --git a/src/architecture.py b/src/architecture.py index 5b8711b..d540482 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -54,7 +54,7 @@ def get_distribution(codes): :rtype: str ''' if is_windows(): - return "Win" + return "W" # in order to fulfill the 8196 length constraint! # else get linux distribution description from platform, and encode it with code lin_distrib = platform.dist()[0].lower() diff --git a/src/compilation.py b/src/compilation.py index 4951c55..48a5620 100644 --- a/src/compilation.py +++ b/src/compilation.py @@ -454,6 +454,7 @@ CC=\\"hack_libtool\\"%g" libtool''' assert self.build_environ is not None # pass additional variables to environment # (may be used by the build script) + self.build_environ.set("APPLICATION_NAME", self.config.APPLICATION.name) self.build_environ.set("SOURCE_DIR", str(self.source_dir)) self.build_environ.set("INSTALL_DIR", str(self.install_dir)) self.build_environ.set("PRODUCT_INSTALL", str(self.install_dir)) diff --git a/src/environment.py b/src/environment.py index f4816e7..ae27354 100644 --- a/src/environment.py +++ b/src/environment.py @@ -73,8 +73,17 @@ class Environ: :param value str: the value to append to key :param sep str: the separator string """ - for c in [";", ":"]: # windows or linux path separators - if c in value: + if src.architecture.is_windows(): + separators = [';'] + else: + separators = [':'] + for c in separators: # windows or linux path separators + isOK = True + if c in value and not src.architecture.is_windows(): + isOK = False + elif c in value and src.architecture.is_windows() and value.count(':') > 1: + isOK = False + if not isOK: raise Exception("Environ append key '%s' value '%s' contains forbidden character '%s'" % (key, value, c)) # check if the key is already in the environment if key in self.environ: @@ -111,8 +120,17 @@ class Environ: :param value str: the value to prepend to key :param sep str: the separator string """ - for c in [";", ":"]: # windows or linux path separators - if c in value: + if src.architecture.is_windows(): + separators = [';'] + else: + separators = [':'] + for c in separators: # windows or linux path separators + isOK = True + if c in value and not src.architecture.is_windows(): + isOK = False + elif c in value and src.architecture.is_windows() and value.count(':') > 1: + isOK = False + if not isOK: raise Exception("Environ prepend key '%s' value '%s' contains forbidden character '%s'" % (key, value, c)) # check if the key is already in the environment if key in self.environ: @@ -499,11 +517,11 @@ class SalomeEnviron: self.prepend('LD_LIBRARY_PATH', lib_path) l = [ bin_path, lib_path ] - if self.has_python: - l.append(pylib1_path) - l.append(pylib2_path) - - self.prepend('PYTHONPATH', l) + if not src.product.product_is_wheel(pi): + if self.has_python: + l.append(pylib1_path) + l.append(pylib2_path) + self.prepend('PYTHONPATH', l) def set_cpp_env(self, product_info): """\ diff --git a/src/fileEnviron.py b/src/fileEnviron.py index ab79916..468b0e8 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -19,6 +19,7 @@ import os import pprint as PP import src.debug as DBG +import src.architecture bat_header="""\ @echo off @@ -180,8 +181,18 @@ class FileEnviron(object): :param value str: the value to append to key :param sep str: the separator string """ - for c in [";", ":"]: # windows or linux path separators - if c in value: + separators = [] + if src.architecture.is_windows(): + separators = [':'] + else: + separators = [';'] + for c in separators: # windows or linux path separators + isOK = True + if c in value and not src.architecture.is_windows(): + isOK = False + elif c in value and src.architecture.is_windows() and value.count(':') > 1: + isOK = False + if not isOK: raise Exception("FileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, c)) self.set(key, self.get(key) + sep + value) if (key, sep) not in self.toclean: @@ -210,8 +221,18 @@ class FileEnviron(object): :param value str: the value to prepend to key :param sep str: the separator string """ - for c in [";", ":"]: # windows or linux path separators - if c in value: + separators = [] + if src.architecture.is_windows(): + separators = [':'] + else: + separators = [';'] + for c in separators: # windows or linux path separators + isOK = True + if c in value and not src.architecture.is_windows(): + isOK = False + elif c in value and src.architecture.is_windows() and value.count(':') > 1: + isOK = False + if not isOK: raise Exception("FileEnviron prepend key '%s' value '%s' contains forbidden character '%s'" % (key, value, c)) self.set(key, value + sep + self.get(key)) if (key, sep) not in self.toclean: @@ -555,8 +576,18 @@ class LauncherFileEnviron: :param value str: the value to append to key :param sep str: the separator string """ - for c in [";", ":"]: # windows or linux path separators - if c in value: + separators = [] + if src.architecture.is_windows(): + separators = [':'] + else: + separators = [';'] + for c in separators: # windows or linux path separators + isOK = True + if c in value and not src.architecture.is_windows(): + isOK = False + elif c in value and src.architecture.is_windows() and value.count(':') > 1: + isOK = False + if not isOK: raise Exception("LauncherFileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, c)) if self.is_defined(key) : self.add(key, value) diff --git a/src/product.py b/src/product.py index 44d20e9..f6c8cc2 100644 --- a/src/product.py +++ b/src/product.py @@ -1089,3 +1089,15 @@ def get_product_components(product_info): compo_list = [ compo_list ] return compo_list +def product_is_wheel(product_info): + """ tells whether a product is a wheel + + :param product_info Config: The configuration specific to + the product + :return: True if the product has a wheel, else False + :rtype: Boolean + """ + return ("properties" in product_info and + "is_wheel" in product_info.properties and + product_info.properties.is_wheel == "yes") + diff --git a/src/system.py b/src/system.py index 6b79339..73f9c18 100644 --- a/src/system.py +++ b/src/system.py @@ -28,6 +28,7 @@ import tarfile import debug as DBG import utilsSat as UTS +import src from . import printcolors @@ -85,7 +86,10 @@ def git_extract(from_what, tag, where, logger, environment=None): if not where.exists(): where.make() if tag == "master" or tag == "HEAD": - cmd = r""" + if src.architecture.is_windows(): + cmd = "git clone %(remote)s %(where)s" + else: + cmd = r""" set -x git clone %(remote)s %(where)s """ @@ -94,8 +98,10 @@ git clone %(remote)s %(where)s # NOTICE: this command only works with recent version of git # because --work-tree does not work with an absolute path where_git = os.path.join(str(where), ".git") - - cmd = r""" + if src.architecture.is_windows(): + cmd = "rmdir %(where)s && git clone %(remote)s %(where)s && git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s" + else: + cmd = r""" set -x rmdir %(where)s git clone %(remote)s %(where)s && \ @@ -159,8 +165,8 @@ def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None 'tmpWhere': tmpWhere, } DBG.write("git_extract_sub_dir", aDict) - - cmd = r""" + if not src.architecture.is_windows(): + cmd = r""" set -x export tmpDir=%(tmpWhere)s && \ rm -rf $tmpDir @@ -171,6 +177,19 @@ mv %(sub_dir)s %(where)s && \ git log -1 > %(where)s/README_git_log.txt && \ rm -rf $tmpDir """ % aDict + else: + cmd = r""" + +set tmpDir=%(tmpWhere)s && \ +rm -rf $tmpDir +git clone %(remote)s $tmpDir && \ +cd $tmpDir && \ +git checkout %(tag)s && \ +mv %(sub_dir)s %(where)s && \ +git log -1 > %(where)s/README_git_log.txt && \ +rm -rf $tmpDir +""" % aDict + DBG.write("cmd", cmd) for nbtry in range(0,3): # retries case of network problem -- 2.39.2