Commit 630bb71b authored by Mats Wichmann's avatar Mats Wichmann Committed by C.J. Collier

Prepare for scons3: change prints and more

A previous change updated all the scons scripts:

https://gerrit.iotivity.org/gerrit/#/c/22525/

This change picks up the semi-external scripts that are called
by the build, and thus are run in the scons context and need updating.

Print statements are surrounded with parens so they look like function
calls.  This is an scons3 syntax requirement even if still using Python 2.

The old exception format "except FooErr, err" is no longer supported
in Python 3; since the Python 3 format "except FooErr as err" has been
available since Python 2.6, there is no problem switching these and it
makes sense to remove one way things could fail if Py3 is used.

A few comparisons which used <> are changed to the preferred != form.

Reformatted Builder call without changing it, and added a comment in the
forked version to help explain why there are two copies of UnpackAll.py.

With these changes, a full build completes successfully using scons3.0.

Change-Id: Ia8df28d12c6504d6466dcf793779535d1ad3aa8b
Signed-off-by: default avatarMats Wichmann <mats@linux.com>
(cherry picked from commit b34da4aa)
parent 231614df
...@@ -37,9 +37,10 @@ def _check_for_broken_gcc_headers(context, flag): ...@@ -37,9 +37,10 @@ def _check_for_broken_gcc_headers(context, flag):
context.Result(ret) context.Result(ret)
if ret: if ret:
print('Warning: detected pre-C++11 GCC C header bugs. See:') print('''
print(' https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34032') Warning: detected pre-C++11 GCC C header bugs.
print(' for related details.') See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34032 for details.
''')
def _inform_user_of_broken_gcc_headers(context, flag): def _inform_user_of_broken_gcc_headers(context, flag):
# Informative tests used to inform the user of broken GCC headers. # Informative tests used to inform the user of broken GCC headers.
......
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
############################################################################ ############################################################################
# iotivity note: this is a forked copy of the UnpackBuilder elsewhere
# in the tree, which instead of defining a Builder, adds a method UnpackAll.
# The Unpack Builder can be used for unpacking archives (eg Zip, TGZ, BZ, ... ). # The Unpack Builder can be used for unpacking archives (eg Zip, TGZ, BZ, ... ).
...@@ -193,7 +195,7 @@ def __getExtractor( source, env ) : ...@@ -193,7 +195,7 @@ def __getExtractor( source, env ) :
# @param source source name # @param source source name
# @param env environment object # @param env environment object
def __message( s, target, source, env ) : def __message( s, target, source, env ) :
print "extract [%s] ..." % (source[0]) print("extract [%s] ..." % (source[0]))
# action function for extracting of the data # action function for extracting of the data
...@@ -220,7 +222,7 @@ def __action( target, source, env ) : ...@@ -220,7 +222,7 @@ def __action( target, source, env ) :
devnull = open(os.devnull, "wb") devnull = open(os.devnull, "wb")
handle = subprocess.Popen( cmd, shell=True, stdout=devnull ) handle = subprocess.Popen( cmd, shell=True, stdout=devnull )
if handle.wait() <> 0 : if handle.wait() != 0 :
raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) ) raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) )
...@@ -257,7 +259,7 @@ def __emitter( target, source, env ) : ...@@ -257,7 +259,7 @@ def __emitter( target, source, env ) :
handle = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE ) handle = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
target = handle.stdout.readlines() target = handle.stdout.readlines()
handle.communicate() handle.communicate()
if handle.returncode <> 0 : if handle.returncode != 0 :
raise SCons.Errors.StopError("error on running list command [%s] of the source file [%s]" % (cmd, source[0]) ) raise SCons.Errors.StopError("error on running list command [%s] of the source file [%s]" % (cmd, source[0]) )
# if the returning output exists and the listseperator is a callable structure # if the returning output exists and the listseperator is a callable structure
...@@ -265,8 +267,8 @@ def __emitter( target, source, env ) : ...@@ -265,8 +267,8 @@ def __emitter( target, source, env ) :
# a string we push it back to the target list # a string we push it back to the target list
try : try :
if callable(extractor["LISTEXTRACTOR"]) : if callable(extractor["LISTEXTRACTOR"]) :
target = filter( lambda s : SCons.Util.is_String(s), [ extractor["LISTEXTRACTOR"]( env, len(target), no, i) for no, i in enumerate(target) ] ) target = filter(lambda s: SCons.Util.is_String(s), [extractor["LISTEXTRACTOR"](env, len(target), no, i) for no, i in enumerate(target)])
except Exception, e : except Exception as e :
raise SCons.Errors.StopError( "%s" % (e) ) raise SCons.Errors.StopError( "%s" % (e) )
# the line removes duplicated names - we need this line, otherwise an cyclic dependency error will occured, # the line removes duplicated names - we need this line, otherwise an cyclic dependency error will occured,
...@@ -276,7 +278,7 @@ def __emitter( target, source, env ) : ...@@ -276,7 +278,7 @@ def __emitter( target, source, env ) :
SCons.Warnings.warn(UnpackWarning, "emitter file list on target [%s] is empty, please check your extractor list function [%s]" % (source[0], cmd) ) SCons.Warnings.warn(UnpackWarning, "emitter file list on target [%s] is empty, please check your extractor list function [%s]" % (source[0], cmd) )
# we append the extractdir to each target if is not absolut # we append the extractdir to each target if is not absolut
if env["UNPACK"]["EXTRACTDIR"] <> "." : if env["UNPACK"]["EXTRACTDIR"] != "." :
target = [i if os.path.isabs(i) else os.path.join(env["UNPACK"]["EXTRACTDIR"], i) for i in target] target = [i if os.path.isabs(i) else os.path.join(env["UNPACK"]["EXTRACTDIR"], i) for i in target]
return target, source return target, source
...@@ -285,7 +287,7 @@ def __unpack_all(env, target, source) : ...@@ -285,7 +287,7 @@ def __unpack_all(env, target, source) :
if os.path.exists(target): if os.path.exists(target):
return return
print "Unpacking %s ..." % source print("Unpacking %s ..." % source)
__action(target, source, env) __action(target, source, env)
# generate function, that adds the builder to the environment # generate function, that adds the builder to the environment
...@@ -378,7 +380,7 @@ def generate( env ) : ...@@ -378,7 +380,7 @@ def generate( env ) :
} }
# read tools for Windows system # read tools for Windows system
if env["PLATFORM"] <> "darwin" and "win" in env["PLATFORM"] : if env["PLATFORM"] != "darwin" and "win" in env["PLATFORM"] :
if env.WhereIs('7z', env.get('PATH')): if env.WhereIs('7z', env.get('PATH')):
toolset["EXTRACTOR"]["TARGZ"]["RUN"] = "7z" toolset["EXTRACTOR"]["TARGZ"]["RUN"] = "7z"
...@@ -423,12 +425,13 @@ def generate( env ) : ...@@ -423,12 +425,13 @@ def generate( env ) :
toolset["EXTRACTOR"]["TAR"]["EXTRACTFLAGS"] = "x" toolset["EXTRACTOR"]["TAR"]["EXTRACTFLAGS"] = "x"
toolset["EXTRACTOR"]["TAR"]["EXTRACTSUFFIX"] = "-y -ttar -o${UNPACK['EXTRACTDIR']}" toolset["EXTRACTOR"]["TAR"]["EXTRACTSUFFIX"] = "-y -ttar -o${UNPACK['EXTRACTDIR']}"
else: else:
print '''*********************** Error ************************ print('''
*********************** Error ************************
* * * *
* Please make sure that 7-zip is in your System PATH * * Please make sure that 7-zip is in your System PATH *
* * * *
****************************************************** ******************************************************
''' ''')
# here can add some other Windows tools, that can handle the archive files # here can add some other Windows tools, that can handle the archive files
# but I don't know which ones can handle all file types # but I don't know which ones can handle all file types
...@@ -477,12 +480,19 @@ def generate( env ) : ...@@ -477,12 +480,19 @@ def generate( env ) :
else : else :
raise SCons.Errors.StopError("Unpack tool detection on this platform [%s] unkown" % (env["PLATFORM"])) raise SCons.Errors.StopError("Unpack tool detection on this platform [%s] unkown" % (env["PLATFORM"]))
# the target_factory must be a "Entry", because the target list can be files and dirs, so we can not specified the targetfactory explicite # the target_factory must be an "Entry", because the target list can be
# files and dirs, so we can not specify the targetfactory explicitly
env.Replace(UNPACK = toolset) env.Replace(UNPACK = toolset)
#env["BUILDERS"]["UnpackAll"] = SCons.Builder.Builder(
# action=__action,
# emitter=__emitter,
# target_factory=SCons.Node.FS.Entry,
# source_factory=SCons.Node.FS.File,
# single_source=True,
# PRINT_CMD_LINE_FUNC=__message
#)
env.AddMethod(__unpack_all, 'UnpackAll') env.AddMethod(__unpack_all, 'UnpackAll')
# env["BUILDERS"]["UnpackAll"] = SCons.Builder.Builder( action = __action, emitter = __emitter, target_factory = SCons.Node.FS.Entry, source_factory = SCons.Node.FS.File, single_source = True, PRINT_CMD_LINE_FUNC = __message )
# existing function of the builder # existing function of the builder
# @param env environment object # @param env environment object
......
...@@ -32,7 +32,7 @@ import SCons.Builder, SCons.Node, SCons.Errors ...@@ -32,7 +32,7 @@ import SCons.Builder, SCons.Node, SCons.Errors
# @param source source name # @param source source name
# @param env environment object # @param env environment object
def __message( s, target, source, env ) : def __message( s, target, source, env ) :
print 'bootstrapping using [%s] ...' % (source[0]) print('bootstrapping using [%s] ...' % (source[0]))
# Create the builder action which executes the bootstrap script # Create the builder action which executes the bootstrap script
...@@ -64,7 +64,7 @@ def __action( target, source, env ) : ...@@ -64,7 +64,7 @@ def __action( target, source, env ) :
devnull = open(os.devnull, 'wb') devnull = open(os.devnull, 'wb')
handle = subprocess.Popen( cmd, shell=True, cwd=cwd, stdout=devnull ) handle = subprocess.Popen( cmd, shell=True, cwd=cwd, stdout=devnull )
if handle.wait() <> 0 : if handle.wait() != 0 :
raise SCons.Errors.BuildError( 'Bootstrapping script [%s] on the source [%s]' % (cmd, source[0]) ) raise SCons.Errors.BuildError( 'Bootstrapping script [%s] on the source [%s]' % (cmd, source[0]) )
# Define the emitter of the builder # Define the emitter of the builder
......
...@@ -35,7 +35,7 @@ import SCons.Builder, SCons.Node, SCons.Errors ...@@ -35,7 +35,7 @@ import SCons.Builder, SCons.Node, SCons.Errors
# @param source source name # @param source source name
# @param env environment object # @param env environment object
def __message( s, target, source, env ) : def __message( s, target, source, env ) :
print "building boost from [%s] for ..." % (source[0]) print("building boost from [%s] for ..." % (source[0]))
# Create the builder action which constructs a user-config.jam based # Create the builder action which constructs a user-config.jam based
...@@ -136,7 +136,7 @@ def __action( target, source, env ) : ...@@ -136,7 +136,7 @@ def __action( target, source, env ) :
devnull = open(os.devnull, "wb") devnull = open(os.devnull, "wb")
handle = subprocess.Popen( cmd, env=penv, cwd=cwd ) #, stdout=devnull ) handle = subprocess.Popen( cmd, env=penv, cwd=cwd ) #, stdout=devnull )
if handle.wait() <> 0 : if handle.wait() != 0 :
raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, source[0]) ) raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, source[0]) )
# Define the emitter of the builder # Define the emitter of the builder
......
...@@ -32,7 +32,7 @@ import SCons.Builder, SCons.Node, SCons.Errors ...@@ -32,7 +32,7 @@ import SCons.Builder, SCons.Node, SCons.Errors
# @param source source name # @param source source name
# @param env environment object # @param env environment object
def __message( s, target, source, env ) : def __message( s, target, source, env ) :
print "Configuring using [%s] ..." % (source[0]) print("Configuring using [%s] ..." % (source[0]))
# Create the action # Create the action
# #
...@@ -63,7 +63,7 @@ def __action( target, source, env ) : ...@@ -63,7 +63,7 @@ def __action( target, source, env ) :
devnull = open(os.devnull, "wb") devnull = open(os.devnull, "wb")
handle = subprocess.Popen( cmd, shell=True, cwd=cwd, stdout=devnull ) handle = subprocess.Popen( cmd, shell=True, cwd=cwd, stdout=devnull )
if handle.wait() <> 0 : if handle.wait() != 0 :
raise SCons.Errors.BuildError( "Configuring script [%s] on the source [%s]" % (cmd, source[0]) ) raise SCons.Errors.BuildError( "Configuring script [%s] on the source [%s]" % (cmd, source[0]) )
# Define the builder's emitter # Define the builder's emitter
......
...@@ -106,7 +106,7 @@ def run_uwp_wack_test(env, cert_file, appx_file, report_output_path): ...@@ -106,7 +106,7 @@ def run_uwp_wack_test(env, cert_file, appx_file, report_output_path):
command += ' && certutil %s | for /f "delims=: tokens=1*" %%i in (\'findstr "Serial Number:"\') do (certutil -delstore root %%j)' % (cert_file) command += ' && certutil %s | for /f "delims=: tokens=1*" %%i in (\'findstr "Serial Number:"\') do (certutil -delstore root %%j)' % (cert_file)
command += ' && findstr OVERALL_RESULT=.PASS %s' % (report_output_file) command += ' && findstr OVERALL_RESULT=.PASS %s' % (report_output_file)
print 'Running WACK Test' print('Running WACK Test')
wack_test = env.Command(report_output_file, appx_file, command) wack_test = env.Command(report_output_file, appx_file, command)
env.AlwaysBuild(wack_test) env.AlwaysBuild(wack_test)
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
# the URLDownload-Builder can be download any data from an URL into a target file # the URLDownload-Builder can be download any data from an URL into a target file
# and can replace the target file name with the URL filename (the setting variable # and can replace the target file name with the URL filename (the setting variable
# within the environment object is a boolean type with the name "URLDOWNLOAD_USEURLFILENAM", # within the environment object is a boolean type with the name "URLDOWNLOAD_USEURLFILENAME",
# default setting replaces the target name with the URL filename) # default setting replaces the target name with the URL filename)
...@@ -77,26 +77,26 @@ class URLNode(SCons.Node.Python.Value) : ...@@ -77,26 +77,26 @@ class URLNode(SCons.Node.Python.Value) :
# overload the get_csig (copy the source from the # overload the get_csig (copy the source from the
# Python.Value node and append the data of the URL header # Python.Value node and append the data of the URL header
def get_csig(self, calc=None): def get_csig(self, calc=None):
try: try:
return self.ninfo.csig return self.ninfo.csig
except AttributeError: except AttributeError:
pass pass
try : try :
response = urllib2.urlopen( str(self.value) ).info() response = urllib2.urlopen( str(self.value) ).info()
except Exception, e : except Exception, e :
raise SCons.Errors.StopError( "%s [%s]" % (e, self.value) ) raise SCons.Errors.StopError( "%s [%s]" % (e, self.value) )
contents = "" contents = ""
if "Last-Modified" in response : if "Last-Modified" in response :
contents = contents + response["Last-Modified"] contents = contents + response["Last-Modified"]
if "Content-Length" in response : if "Content-Length" in response :
contents = contents + response["Content-Length"] contents = contents + response["Content-Length"]
if not contents : if not contents :
contents = self.get_contents() contents = self.get_contents()
self.get_ninfo().csig = contents self.get_ninfo().csig = contents
return contents return contents
...@@ -105,8 +105,8 @@ class URLNode(SCons.Node.Python.Value) : ...@@ -105,8 +105,8 @@ class URLNode(SCons.Node.Python.Value) :
# @param target target name # @param target target name
# @param source source name # @param source source name
# @param env environment object # @param env environment object
def __message( s, target, source, env ) : def __message( s, target, source, env ):
print "downloading [%s] to [%s] ..." % (source[0], target[0]) print("downloading [%s] to [%s] ..." % (source[0], target[0]))
# the download function, which reads the data from the URL # the download function, which reads the data from the URL
...@@ -116,12 +116,12 @@ def __message( s, target, source, env ) : ...@@ -116,12 +116,12 @@ def __message( s, target, source, env ) :
# @@param env environment object # @@param env environment object
def __action( target, source, env ) : def __action( target, source, env ) :
try : try :
stream = urllib2.urlopen( str(source[0]) ) stream = urllib2.urlopen(str(source[0]))
file = open( str(target[0]), "wb" ) file = open( str(target[0]), "wb" )
file.write(stream.read()) file.write(stream.read())
file.close() file.close()
stream.close() stream.close()
except Exception, e : except Exception as e:
raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) ) raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) )
...@@ -138,8 +138,8 @@ def __emitter( target, source, env ) : ...@@ -138,8 +138,8 @@ def __emitter( target, source, env ) :
return target, source return target, source
try : try :
url = urlparse.urlparse( urllib2.urlopen( str(source[0]) ).geturl() ) url = urlparse.urlparse(urllib2.urlopen(str(source[0])).geturl())
except Exception, e : except Exception as e:
raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) ) raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) )
return url.path.split("/")[-1], source return url.path.split("/")[-1], source
...@@ -148,7 +148,7 @@ def __emitter( target, source, env ) : ...@@ -148,7 +148,7 @@ def __emitter( target, source, env ) :
# generate function, that adds the builder to the environment, # generate function, that adds the builder to the environment,
# the value "DOWNLOAD_USEFILENAME" replaces the target name with # the value "DOWNLOAD_USEUSRFILENAME" replaces the target name with
# the filename of the URL # the filename of the URL
# @param env environment object # @param env environment object
def generate( env ) : def generate( env ) :
...@@ -160,4 +160,4 @@ def generate( env ) : ...@@ -160,4 +160,4 @@ def generate( env ) :
# @param env environment object # @param env environment object
# @return true # @return true
def exists(env) : def exists(env) :
return 1 return 1
\ No newline at end of file
...@@ -193,7 +193,7 @@ def __getExtractor( source, env ) : ...@@ -193,7 +193,7 @@ def __getExtractor( source, env ) :
# @param source source name # @param source source name
# @param env environment object # @param env environment object
def __message( s, target, source, env ) : def __message( s, target, source, env ) :
print "extract [%s] ..." % (source[0]) print("extract [%s] ..." % (source[0]))
# action function for extracting of the data # action function for extracting of the data
...@@ -225,7 +225,7 @@ def __action( target, source, env ) : ...@@ -225,7 +225,7 @@ def __action( target, source, env ) :
devnull = open(os.devnull, "wb") devnull = open(os.devnull, "wb")
handle = subprocess.Popen( cmd, shell=True, stdout=devnull, cwd=cwd) handle = subprocess.Popen( cmd, shell=True, stdout=devnull, cwd=cwd)
if handle.wait() <> 0 : if handle.wait() != 0 :
raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) ) raise SCons.Errors.BuildError( "error running extractor [%s] on the source [%s]" % (cmd, source[0]) )
fhandle = open(target_path, 'a') fhandle = open(target_path, 'a')
...@@ -336,7 +336,7 @@ def generate( env ) : ...@@ -336,7 +336,7 @@ def generate( env ) :
} }
# read tools for Windows system # read tools for Windows system
if env["PLATFORM"] <> "darwin" and "win" in env["PLATFORM"] : if env["PLATFORM"] != "darwin" and "win" in env["PLATFORM"] :
if env.WhereIs("7z"): if env.WhereIs("7z"):
toolset["EXTRACTOR"]["TARGZ"]["RUN"] = "7z" toolset["EXTRACTOR"]["TARGZ"]["RUN"] = "7z"
...@@ -428,9 +428,17 @@ def generate( env ) : ...@@ -428,9 +428,17 @@ def generate( env ) :
else : else :
raise SCons.Errors.StopError("Unpack tool detection on this platform [%s] unkown" % (env["PLATFORM"])) raise SCons.Errors.StopError("Unpack tool detection on this platform [%s] unkown" % (env["PLATFORM"]))
# the target_factory must be a "Entry", because the target list can be files and dirs, so we can not specified the targetfactory explicite # the target_factory must be an "Entry", because the target list can be
# files and dirs, so we can not specify the targetfactory explicitly
env.Replace(UNPACK = toolset) env.Replace(UNPACK = toolset)
env["BUILDERS"]["UnpackAll"] = SCons.Builder.Builder( action = __action, emitter = __emitter, target_factory = SCons.Node.FS.Entry, source_factory = SCons.Node.FS.File, single_source = True, PRINT_CMD_LINE_FUNC = __message ) env["BUILDERS"]["UnpackAll"] = SCons.Builder.Builder(
action=__action,
emitter=__emitter,
target_factory=SCons.Node.FS.Entry,
source_factory=SCons.Node.FS.File,
single_source=True,
PRINT_CMD_LINE_FUNC=__message
)
# existing function of the builder # existing function of the builder
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment