10891b7e637e3e7eb0423943898b657aceba27f5
[idea/community.git] / python / build / python_plugin_build.gant
1 import static org.jetbrains.jps.idea.IdeaProjectLoader.guessHome
2
3 setProperty("projectHome", guessHome(this as Script))
4 setProperty("home", projectHome)
5
6 includeTargets << new File("${projectHome}/build/scripts/utils.gant")
7
8 setProperty("outDir", "${projectHome}/out/python")
9 setProperty("ideaDir", "${outDir}/ideaCE")
10 requireProperty("ideaPath", ideaDir)
11
12 setProperty("pluginHelp", "${outDir}/help")
13
14 setProperty("buildNumber", requireProperty("build.number", snapshot))
15 setProperty("ideaBuildNumber", requireProperty("idea.build.number"))
16
17 setProperty("ideaSinceBuildNumber", ("${ideaBuildNumber}" =~ /(\d+\.[A-Z0-9]+)/)[0][1])
18
19 setProperty("ideaHomePacked", "${ideaDir}/jdk16") //compiled idea
20 setProperty("ideaHome", "${ideaDir}/jdk16/idea-IC-${ideaBuildNumber}") //compiled idea
21
22 setProperty("pluginHome", "${projectHome}/python")
23 setProperty("pluginRevision", "${buildNumber}")
24
25 setProperty("ideaLib", "${ideaHome}/lib")
26 setProperty("ideaPlugins", "${ideaHome}/plugins") //compiled plugins
27
28
29 setProperty("output", "${projectHome}/python/distCE")
30
31 setProperty("zipdir", "${output}/zip")
32 setProperty("plugindir", "${zipdir}/python")
33 setProperty("zipname", "python-community-${pluginRevision}.zip")
34
35 setProperty("srcDir", "${pluginHome}/src")
36
37 setProperty("classesRootDir", "${outDir}/classes")
38 setProperty("classesDir", "${classesRootDir}/python")
39
40 //Compiler options
41 setProperty("compilerDebug", "on")
42 setProperty("compilerGenerateNoWarnings", "off")
43 setProperty("compilerArgs", "")
44 setProperty("compilerMaxMemory", "256m")
45
46 ant.patternset(id: "resources.pt") {
47   include(name: "**/?*.properties")
48   include(name: "**/?*.template")
49   include(name: "**/?*.xml")
50   include(name: "**/?*.gif")
51   include(name: "**/?*.png")
52   include(name: "**/?*.txt")
53   include(name: "**/?*.jpeg")
54   include(name: "**/?*.jpg")
55   include(name: "**/?*.html")
56   include(name: "**/?*.dtd")
57   include(name: "**/?*.tld")
58   include(name: "**/?*.py")
59   include(name: "**/?*.ft")
60   include(name: "**/?*.dic")
61   exclude(name: "**/plugin.xml")
62 }
63
64 target(name: "clean", description: "Cleanup output") {
65   ant.echo("Cleaning ${output}")
66   ant.delete(dir: "${output}", failonerror: "false")
67   ant.echo("Cleaning ${classesRootDir}")
68   ant.delete(dir: "${classesRootDir}", failonerror: "false")
69   ant.echo("Cleaning ${ideaHome}")
70   ant.delete(dir: "${ideaHome}", failonerror: "false")          // out/python/idea/
71 }
72
73 target(name: "unzip") {
74   ant.mkdir(dir: "${ideaHomePacked}")
75   ant.gunzip(src: "${ideaPath}/ideaIC-${ideaBuildNumber}.tar.gz")
76   ant.untar(src: "${ideaPath}/ideaIC-${ideaBuildNumber}.tar", dest: "${ideaHomePacked}")
77 }
78
79 target(name: "compile", description: "Compile module python") {
80   depends("unzip")
81
82   ant.path(id: "classpath.lib") {
83     fileset(dir: "${ideaLib}") {
84       include(name: "?*.jar")
85     }
86     fileset(dir: "${ideaPlugins}/terminal/lib") {
87       include(name: "*.jar")
88     }
89     fileset(dir: "${ideaPlugins}/IntelliLang/lib") {
90       include(name: "*.jar")
91     }
92     fileset(dir: "${pluginHome}/ipnb/lib") {
93       include(name: "*.jar")
94     }
95   }
96
97   ant.path(id: "sourcepath") {
98     dirset(dir: "${pluginHome}") {
99       include(name: "src")
100       include(name: "gen")
101       include(name: "pluginCore")
102       include(name: "pluginJava")
103       include(name: "pydevSrc")
104       include(name: "openapi/src")
105       include(name: "psi-api/src")
106       include(name: "IntelliLang-python/src")
107       include(name: "ipnb/src")
108     }
109   }
110   //The task requires the following libraries from IntelliJ IDEA distribution:
111   //javac2.jar; jdom.jar; asm.jar; asm-commons.jar
112   ant.taskdef(name: "javac2", classname: "com.intellij.ant.Javac2") {
113     classpath {
114       fileset(dir: "${ideaLib}") {
115         include(name: "?*.jar")
116       }
117     }
118   }
119
120   ant.mkdir(dir: "${classesDir}")
121
122   //compile
123   ant.javac2(destdir: "${classesDir}",
124              debug: "${compilerDebug}",
125              nowarn: "${compilerGenerateNoWarnings}",
126              memorymaximumsize: "${compilerMaxMemory}",
127              fork: "true") {
128     compilerarg(line: "${compilerArgs}")
129     classpath(refid: "classpath.lib")
130     src(refid: "sourcepath")
131   }
132
133   //copy resources
134   ant.copy(todir: "${classesDir}") {
135     fileset(dir: "${pluginHome}/resources") {
136       patternset(refid: "resources.pt")
137       type(type: "file")
138     }
139     fileset(dir: "${pluginHome}/python-community-ide-resources/resources") {
140       patternset(refid: "resources.pt")
141       type(type: "file")
142     }
143     fileset(dir: "${pluginHome}/src") {
144       patternset(refid: "resources.pt")
145       type(type: "file")
146     }
147     fileset(dir: "${pluginHome}/psi-api/resources") {
148       patternset(refid: "resources.pt")
149       type(type: "file")
150     }
151     fileset(dir: "${pluginHome}/IntelliLang-python/resources") {
152       patternset(refid: "resources.pt")
153       type(type: "file")
154     }
155     fileset(dir: "${pluginHome}/IntelliLang-python/src") {
156       include(name: "resources/*.xml")
157     }
158     fileset(dir: "${pluginHome}/ipnb/resources") {
159       patternset(refid: "resources.pt")
160       type(type: "file")
161     }
162   }
163
164   //copy plugin.xml
165   ant.mkdir(dir: "${classesDir}/META-INF")
166   ant.copy(todir: "${classesDir}/META-INF") {
167     fileset(file: "${pluginHome}/pluginCore/META-INF/python-community-plugin-core.xml")
168     fileset(file: "${pluginHome}/pluginJava/META-INF/python-community-plugin-java.xml")
169     fileset(file: "${pluginHome}/pluginResources/META-INF/plugin.xml")
170     fileset(file: "${pluginHome}/build/python-plugin-dependencies.xml")
171   }
172
173   // set version to PyCharm current version from ApplicationInfo.xml
174   ant.loadfile(property: "appInfo", srcFile: "${pluginHome}/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml") {
175   }
176
177   major = ("${appInfo}" =~ /major\s*=\s*\"([^"])\"/)[0][1]
178   minor = ("${appInfo}" =~ /minor\s*=\s*\"([^"])\"/)[0][1]
179
180
181   ant.replaceregexp(file: "${classesDir}/META-INF/plugin.xml",
182                     match: "@@PYCHARM_VERSION@@",
183                     replace: "${major}.${minor}")
184
185   // set since-build to the current idea build number
186   ant.replace(file: "${classesDir}/META-INF/plugin.xml") {
187     replacefilter(token: "@@BUILD_NUMBER@@", value: "${buildNumber}")
188   }
189
190   ant.replaceregexp(file: "${classesDir}/META-INF/plugin.xml",
191                     match: "since-build=\"\\d+\\.\\d+\"",
192                     replace: "since-build=\"${ideaSinceBuildNumber}\"")
193 }
194
195 target(name: "jar", description: "Generate jar file") {
196   depends("compile")
197   ant.mkdir(dir: "${output}")
198   ant.jar(destfile: "${output}/python-community.jar", basedir: "${classesDir}") {
199     manifest() {
200       attribute(name: "Revision", value: "${pluginRevision}")
201       //<!--<attribute name="Build" value="${plugin.version}"/>-->
202     }
203   }
204 }
205
206 target(name: "zip", description: "Generate zip plugin file") {
207   depends("jar")
208
209   ant.mkdir(dir: "${zipdir}")
210
211   // copy plugin jar
212   ant.mkdir(dir: "${plugindir}/lib")
213   ant.move(file: "${output}/python-community.jar", todir: "${plugindir}/lib")
214
215   ant.copy(todir: "${plugindir}/lib") {
216     fileset(dir: "${pluginHome}/ipnb/lib") {
217       include(name: "*.jar")
218     }
219   }
220
221   ant.mkdir(dir: "${plugindir}/helpers")
222   ant.copy(todir: "${plugindir}/helpers") {
223     fileset(dir: "${pluginHome}/helpers") {
224       include(name: "**/*")
225     }
226   }
227
228   ant.mkdir(dir: "${plugindir}/help")
229   ant.copy(file: "${pluginHelp}/pytonpluginhelp.jar", tofile: "${plugindir}/help/pythonpluginhelp.jar", failonerror: false)
230   ant.copy(file: "${pluginHelp}/pytonpluginhelp_mac.jar", tofile: "${plugindir}/help/pythonpluginhelp_mac.jar", failonerror: false)
231
232   ant.zip(basedir: "${zipdir}", destfile: "${output}/${zipname}")
233 }
234
235 target(name: "build") {
236   depends("unzip")
237   depends("compile")
238 }
239
240 target(name: "dist", description: "main target") {
241   depends("clean")
242   depends("build")
243   depends("zip")
244 }
245
246 target('default': "Build artifacts") {
247   depends("dist")
248 }