|
1 <?xml version="1.0" encoding="UTF-8"?> |
|
2 <!-- |
|
3 ============================================================================ |
|
4 Name : patching.ant.xml |
|
5 Part of : Helium |
|
6 |
|
7 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
8 All rights reserved. |
|
9 This component and the accompanying materials are made available |
|
10 under the terms of the License "Eclipse Public License v1.0" |
|
11 which accompanies this distribution, and is available |
|
12 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
13 |
|
14 Initial Contributors: |
|
15 Nokia Corporation - initial contribution. |
|
16 |
|
17 Contributors: |
|
18 |
|
19 Description: |
|
20 |
|
21 ============================================================================ |
|
22 --> |
|
23 <project name="patching"> |
|
24 <description>Patching of S60 files.</description> |
|
25 |
|
26 <!-- |
|
27 Hack macro this macro enables to hack a file. |
|
28 The macro check if the file needs to be patched if keyword regex doesn't match. |
|
29 |
|
30 Example: |
|
31 <pre> |
|
32 <hlm:hackMacro file="${build.drive}/epoc32/tools/variant/variant.cfg" keyword="ENABLE_ABIV2_MODE" regex="(.hrh$)" replace="\1\nENABLE_ABIV2_MODE"/> |
|
33 </pre> |
|
34 --> |
|
35 <macrodef name="hackMacro" uri="http://www.nokia.com/helium"> |
|
36 <attribute name="file"/> |
|
37 <attribute name="keyword"/> |
|
38 <attribute name="regex"/> |
|
39 <attribute name="replace"/> |
|
40 <attribute name="encoding" default="utf-8"/> |
|
41 <sequential> |
|
42 <script language="jython" setbeans="false"> |
|
43 <![CDATA[ |
|
44 import re |
|
45 import os |
|
46 import codecs |
|
47 import traceback |
|
48 keyword = r'@{keyword}' |
|
49 filename = r'@{file}' |
|
50 regex = r'@{regex}' |
|
51 replace = r'@{replace}' |
|
52 encoding = r'@{encoding}' |
|
53 if os.path.exists(filename): |
|
54 try: |
|
55 f = codecs.open(filename, 'r', encoding) |
|
56 content = f.read() |
|
57 f.close() |
|
58 if re.search(keyword, content, re.M | re.DOTALL) == None: |
|
59 self.log("Hacking %s" % filename) |
|
60 content = re.compile(regex, re.M | re.DOTALL).sub(replace, content) |
|
61 f = codecs.open(filename, 'w+', encoding) |
|
62 f.write(content) |
|
63 f.close() |
|
64 else: |
|
65 self.log(str("File %s matching keyword." % filename)) |
|
66 except Exception, e: |
|
67 print traceback.format_exc() |
|
68 else: |
|
69 self.log(str("Could not find the file %s." % filename)) |
|
70 ]]> |
|
71 </script> |
|
72 </sequential> |
|
73 </macrodef> |
|
74 |
|
75 |
|
76 <!-- Add new iby file includes to s60.iby |
|
77 |
|
78 It uses a property [i]iby.include.list[/i] to list the iby-files (comma separated) that should be included in the s60.iby. |
|
79 |
|
80 Target first removes any existing includes to prevent duplicates. |
|
81 Only problem with this one is that it does this by replacing the existing include with a line separator so the s60.iby will grow all the time. |
|
82 --> |
|
83 <target name="modify-s60-iby"> |
|
84 <!-- Restore backup --> |
|
85 <move file="${build.drive}/epoc32/rom/include/s60.iby.orig" tofile="${build.drive}/epoc32/rom/include/s60.iby" failonerror="false"/> |
|
86 <!-- Create backup --> |
|
87 <copy file="${build.drive}/epoc32/rom/include/s60.iby" tofile="${build.drive}/epoc32/rom/include/s60.iby.orig" failonerror="false"/> |
|
88 <for list="${iby.include.list}" delimiter="," param="iby.name" > |
|
89 <sequential> |
|
90 <!-- First remove iby file include if it already exists to prevent duplicate includes --> |
|
91 <replace file="${build.drive}/epoc32/rom/include/s60.iby" summary="true"> |
|
92 <replacetoken> |
|
93 <![CDATA[#endif]]> |
|
94 </replacetoken> |
|
95 <replacevalue> |
|
96 <![CDATA[#include <@{iby.name}> |
|
97 #endif]]></replacevalue> |
|
98 </replace> |
|
99 </sequential> |
|
100 </for> |
|
101 </target> |
|
102 |
|
103 </project> |