sbsv2/raptor/test/smoke_suite/test_resources/scripts/delete_on_failed_compile.py
changeset 18 de5b887c98f7
equal deleted inserted replaced
14:eb060913c963 18:de5b887c98f7
       
     1 #
       
     2 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # delete_on_failed_compile.py
       
    16 # This is a test module for verifying the delete on failed compile 
       
    17 # work around for RVCT 2.2. It creates a dummy object file and 
       
    18 # exits with an error code which should result in object files being deleted.
       
    19 # It takes the same arguments as armcc, but ignores them all apart from -o.
       
    20 #
       
    21 
       
    22 import sys
       
    23 import os
       
    24 import re
       
    25 
       
    26 # Parse for -o argument.
       
    27 objectfile_re = re.compile(".*-o\s(\S*\.(o|pre))\s.*", re.I)
       
    28 res = objectfile_re.match(" ".join(sys.argv[1:]))
       
    29 
       
    30 if res:
       
    31 	objectpath = res.group(1)
       
    32 	print "Found object file %s" % objectpath
       
    33 	objectdirectory = os.path.dirname(objectpath)
       
    34 	
       
    35 	# Make the directory if it doesn't exist
       
    36 	if not os.path.isdir(objectdirectory):
       
    37 		try:
       
    38 			os.makedirs(objectdirectory)
       
    39 		except:
       
    40 			print "Not making directory %s" % objectdirectory
       
    41 	
       
    42 	# Try to write something to the .o file
       
    43 	try:
       
    44 		fh = open(objectpath, "w")
       
    45 		fh.write("Fake object file for delete on failed compile test\n")
       
    46 		fh.close()
       
    47 	except Exception as error:
       
    48 		print "Failed to created object file %s; error was: %s" % (objectfile, str(error))
       
    49 else:
       
    50 	print "Failed to determine object filename. Commandline used was: %s" % " ".join(sys.argv[1:])
       
    51 
       
    52 # Always exit with an error
       
    53 print "Exiting with non-zero exit code." 
       
    54 sys.exit(1)
       
    55