CPP-434 Split [python-community] into [python-community] and [python-community-ide...
[idea/community.git] / python / build / pycharm_community_build.gant
1 import org.jetbrains.jps.LayoutInfo
2
3 import static org.jetbrains.jps.idea.IdeaProjectLoader.guessHome
4
5 setProperty("home", guessHome(this as Script))
6
7 includeTargets << new File("${guessHome(this as Script)}/build/scripts/utils.gant")
8 includeTargets << new File("${guessHome(this)}/build/scripts/libLicenses.gant")
9
10 requireProperty("buildNumber", requireProperty("build.number", snapshot))
11
12 setProperty("ch", home)
13 setProperty("pythonCommunityHome", "$home/python")
14
15 // load ApplicationInfo.xml properties
16 ant.xmlproperty(file: "$pythonCommunityHome/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml", collapseAttributes: "true")
17
18 setProperty("system_selector", "PyCharmCE${p("component.version.major")}0")
19 setProperty("dryRun", false)
20 setProperty("jdk16", guessJdk())
21
22 //modules to compile
23 setProperty("pluginFilter", new File("$pythonCommunityHome/build/plugin-list.txt").readLines())
24
25 private List<String> pycharmPlatformApiModules() {
26   return [platformApiModules, "dom-openapi"].flatten()
27 }
28
29
30 private List pycharmImplementationModules() {   //modules to put into pycharm.jar
31   return [platformImplementationModules, "dom-impl", "python-community", "python-community-ide-resources",
32     "python-ide-community", "python-configure", "python-openapi", "python-psi-api", "platform-main"].flatten()
33 }
34
35 private List modules() {
36   return [
37     "python-pydev", "colorSchemes", pycharmPlatformApiModules(), pycharmImplementationModules(), pluginFilter
38   ].flatten()
39 }
40
41 private List approvedJars() {
42   def normalizedHome = ch.replace('\\', '/')
43   def normalizedPythonHome = pythonCommunityHome.replace('\\', '/')
44   return ["$normalizedHome/lib/", "$normalizedPythonHome/lib/", "$normalizedHome/xml/relaxng/lib/"]
45 }
46
47 class Paths {
48   final sandbox
49   final distAll
50   final distWin
51   final distMac
52   final distUnix
53   final artifacts
54   final ideaSystem
55   final ideaConfig
56
57   def Paths(String home) {
58     sandbox = "$home/out/pycharmCE"
59
60     distAll = "$sandbox/layout"
61     distWin = "$sandbox/win"
62     distMac = "$sandbox/mac"
63     distUnix = "$sandbox/unix"
64     artifacts = "$sandbox/artifacts"
65
66     ideaSystem = "$sandbox/system"
67     ideaConfig = "$sandbox/config"
68   }
69 }
70
71 setProperty("paths", new Paths(home))
72 setProperty("buildName", "PC-$buildNumber")
73
74 target('default': "Build artifacts") {
75
76   loadProject()
77
78   projectBuilder.stage("Cleaning up sandbox folder")
79
80   projectBuilder.targetFolder = "${paths.sandbox}/classes"
81   projectBuilder.dryRun = dryRun
82
83   if (!dryRun) {
84     forceDelete(paths.sandbox)
85     ant.mkdir(dir: paths.sandbox)
86   }
87
88   ant.tstamp() {
89     format(property: "todayYear", pattern: "yyyy")
90   }
91
92   ant.patternset(id: "resources.included") {
93     include(name: "**/*.properties")
94     include(name: "fileTemplates/**/*")
95     include(name: "inspectionDescriptions/**/*")
96     include(name: "intentionDescriptions/**/*")
97     include(name: "tips/**/*")
98     include(name: "search/**/*")
99   }
100
101   ant.patternset(id: "resources.excluded") {
102     exclude(name: "**/*.properties")
103     exclude(name: "fileTemplates/**/*")
104     exclude(name: "fileTemplates")
105     exclude(name: "inspectionDescriptions/**/*")
106     exclude(name: "inspectionDescriptions")
107     exclude(name: "intentionDescriptions/**/*")
108     exclude(name: "intentionDescriptions")
109     exclude(name: "tips/**/*")
110     exclude(name: "tips")
111   }
112
113   zipSources(home, paths.artifacts)
114
115   def usedJars = buildModulesAndCollectUsedJars(modules(), approvedJars(), ["/ant/"])
116
117   layoutCommunity("${paths.sandbox}/classes/production", usedJars)
118
119   /*
120   buildNSIS([paths.distAll, paths.distWin],
121             "$home/python/build/strings.nsi", "$home/python/build/paths.nsi",
122             "pycharm", false, true, system_selector)
123   */
124
125   /*
126   signMacZip("pycharm")
127   buildDmg("pycharm", "${home}/python/build/DMG_background.png")
128   */
129 }
130
131 public layoutCommunity(String classesPath, Set usedJars) {
132   setProperty("pluginFilter", new File("$pythonCommunityHome/build/plugin-list.txt").readLines())
133
134   if (usedJars == null) {
135     usedJars = collectUsedJars(modules(), approvedJars(), ["/ant/"], null)
136   }
137
138   def appInfo = appInfoFile(classesPath)
139   def paths = new Paths(home)
140   buildSearchableOptions("${projectBuilder.moduleOutput(findModule("platform-resources"))}/search", [], {
141     projectBuilder.moduleRuntimeClasspath(findModule("main_pycharm_ce"), false).each {
142       ant.pathelement(location: it)
143     }
144   }, "-Didea.platform.prefix=PyCharmCore -Didea.no.jre.check=true")
145
146   if (!dryRun) {
147     wireBuildDate("PC-${buildNumber}", appInfo)
148   }
149
150   Map args = [
151     buildNumber: "PC-${buildNumber}",
152     system_selector: system_selector,
153     ide_jvm_args: "-Didea.platform.prefix=PyCharmCore -Didea.no.jre.check=true"]
154
155   LayoutInfo layoutInfo = layoutFull(args, paths.distAll, usedJars)
156   generateLicensesTable("$paths.artifacts/third-party-libraries.txt", layoutInfo.usedModules);
157
158   layoutWin(args, paths.distWin)
159   layoutUnix(args, paths.distUnix)
160   layoutMac(args, paths.distMac)
161
162   ant.echo(message: "PC-${buildNumber}", file: "${paths.distAll}/build.txt")
163
164   def launcher = "${paths.distWin}/bin/pycharm.exe"
165   def launcher64 = "${paths.distWin}/bin/pycharm64.exe"
166   List resourcePaths = ["$ch/community-resources/src",
167     "$ch/platform/icons/src",
168     "$pythonCommunityHome/python-community-ide-resources/resources",
169     "$pythonCommunityHome/resources"]
170   buildWinLauncher("$ch", "$ch/bin/WinLauncher/WinLauncher.exe", launcher,
171                    appInfo, "$pythonCommunityHome/build/pycharm_community_launcher.properties", system_selector, resourcePaths)
172   buildWinLauncher("$ch", "$ch/bin/WinLauncher/WinLauncher64.exe", launcher64,
173                    appInfo, "$pythonCommunityHome/build/pycharm64_community_launcher.properties", system_selector, resourcePaths)
174
175   List pathsDist = new File("${home}/out/pycharm/jdk.win/jre").exists() ? [paths.distAll, paths.distWin, "${home}/out/pycharm/jdk.win"] : [paths.distAll, paths.distWin]
176   buildWinZip("${paths.artifacts}/pycharmPC-${buildNumber}.zip", pathsDist)
177
178   String tarRoot = isEap() ? "pycharm-community-$buildNumber" : "pycharm-community-${p("component.version.major")}.${p("component.version.minor")}"
179   buildTarGz(tarRoot, "$paths.artifacts/pycharmPC-${buildNumber}-no-jdk.tar", [paths.distAll, paths.distUnix])
180   if (p("jdk.linux") != "false") {
181     buildTarGz(tarRoot, "$paths.artifacts/pycharmPC-${buildName}.tar", [paths.distAll, paths.distUnix, "${home}/out/pycharm/jdk.linux"], ["jre/jre/bin/*"])
182   }
183
184   String macAppRoot = isEap() ? "PyCharm CE ${p("component.version.major")}.${p("component.version.minor")} EAP.app/Contents" : "PyCharm CE.app/Contents"
185   buildMacZip(macAppRoot, "${paths.artifacts}/pycharmPC-${buildNumber}.mac.zip", [paths.distAll], paths.distMac)
186 }
187
188 private layoutPlugins(layouts) {
189   dir("plugins") {
190     layouts.layoutPlugin("rest")
191     layouts.layoutPlugin("python-rest")
192     layouts.layoutPlugin("ipnb") {
193       fileset(dir: "$pythonCommunityHome/ipnb/lib")
194     }
195   }
196
197   layouts.layoutCommunityPlugins(ch)
198 }
199
200 private String appInfoFile(String classesPath) {
201   return "$classesPath/python-community/idea/PyCharmCoreApplicationInfo.xml"
202 }
203
204 private layoutFull(Map args, String target, Set usedJars) {
205   def openapiModules = pycharmPlatformApiModules()
206   def superLayouts = includeFile("$ch/build/scripts/layouts.gant")
207
208   reassignAltClickToMultipleCarets("$ch")
209   
210   def result = layout(target) {
211     dir("lib") {
212       jar("util.jar") {
213         module("util")
214         module("util-rt")
215       }
216
217       jar("openapi.jar") {
218         openapiModules.each { module it }
219       }
220
221       jar("annotations.jar") {
222         module("annotations-common")
223         module("annotations")
224       }
225       jar("extensions.jar") { module("extensions") }
226
227       jar(([name: "pycharm.jar", duplicate: "preserve"])) {
228         pycharmImplementationModules().each {
229           module(it) {
230             exclude(name: "**/tips/**")
231           }
232         }
233       }
234
235       jar("pycharm-pydev.jar") {
236         module("python-pydev")
237       }
238
239       jar("bootstrap.jar") { module("bootstrap") }
240       jar("resources.jar") {
241         module("platform-resources")
242         module("colorSchemes")
243       }
244
245       jar("forms_rt.jar") {
246         module("forms_rt")
247       }
248
249       //noinspection GroovyAssignabilityCheck
250       jar([name: "resources_en.jar", duplicate: "preserve"]) {
251         // custom resources should go first
252         module("python-community-ide-resources") {
253           ant.patternset {
254             include(name: "**/tips/**")
255           }
256         }
257         module("platform-resources-en") {
258           ant.patternset {
259             exclude(name: "tips/images/switcher.png")
260             exclude(name: "tips/images/navigateToFilePath.gif")
261           }
262         }
263       }
264
265       jar("icons.jar") { module("icons") }
266       jar("boot.jar") { module("boot") }
267
268       usedJars.each {
269         fileset(file: it)
270       }
271
272       fileset(dir: "$ch/build/kotlinc/lib") {
273         include(name: "kotlin-runtime.jar")
274         include(name: "kotlin-reflect.jar")
275       }
276
277       dir("libpty") {
278         fileset(dir: "$ch/lib/libpty") {
279           exclude(name: "*.txt")
280         }
281       }
282
283       dir("ext") {
284         fileset(dir: "$ch/lib") {
285           include(name: "cglib*.jar")
286         }
287       }
288
289       dir("src") {
290         fileset(dir: "$ch/lib/src") {
291           include(name: "trove4j_changes.txt")
292           include(name: "trove4j_src.jar")
293         }
294
295         jar("pycharm-pydev-src.zip") {
296           fileset(dir: "$pythonCommunityHome/pydevSrc")
297         }
298         jar("pycharm-openapi-src.zip") {
299           fileset(dir: "$pythonCommunityHome/openapi/src")
300           fileset(dir: "$pythonCommunityHome/psi-api/src")
301         }
302       }
303     }
304
305     dir("help") {
306       fileset(dir: "$home/python/help") {
307         include(name: "*.pdf")
308       }
309     }
310
311     dir("helpers") {
312       fileset(dir: "$pythonCommunityHome/helpers")
313     }
314
315     dir("license") {
316       fileset(dir: "$ch/license")
317       fileset(dir: "$ch") {
318         include(name: "LICENSE.txt")
319         include(name: "NOTICE.txt")
320       }
321     }
322
323     layoutPlugins(superLayouts)
324
325     dir("bin") {
326       fileset(dir: "$ch/bin") {
327         exclude(name: "appletviewer.policy")
328         include(name: "*.*")
329       }
330     }
331   }
332   patchPropertiesFile(target, args + [appendices: ["$home/build/conf/ideaJNC.properties"]])
333   return result
334 }
335
336 private layoutWin(Map args, String target) {
337   layout(target) {
338     dir("bin") {
339       fileset(dir: "$ch/bin/win") {
340         exclude(name: "breakgen*")
341       }
342     }
343
344     dir("skeletons") {
345       fileset(dir: "$pythonCommunityHome/skeletons") {
346         include(name: "skeletons-win*.zip")
347       }
348     }
349   }
350
351   winScripts(target, ch, "pycharm.bat", args)
352   winVMOptions(target, null, "pycharm.exe", "pycharm64.exe")
353   ant.copy(file: "$home/python/help/pycharmhelp.jar", todir: "$target/help", failonerror: false)
354 }
355
356 private layoutUnix(Map args, String target) {
357   layout(target) {
358     dir("bin") {
359       fileset(dir: "$ch/bin/linux") {
360         exclude(name: "libbreakgen*")
361       }
362     }
363   }
364
365   ant.copy(file: "$pythonCommunityHome/resources/PyCharmCore128.png", tofile: "$target/bin/pycharm.png")
366
367   unixScripts(target, ch, "pycharm.sh", args)
368   unixVMOptions(target, "pycharm")
369
370   ant.copy(file: "$home/python/help/pycharmhelp.jar", todir: "$target/help", failonerror: false)
371 }
372
373 private layoutMac(Map _args, String target) {
374   layout(target) {
375     dir("bin") {
376       fileset(dir: "$home/bin") {
377         include(name: "*.jnilib")
378       }
379     }
380
381     dir("skeletons") {
382       fileset(dir: "$pythonCommunityHome/skeletons") {
383         include(name: "skeletons-mac*.zip")
384       }
385     }
386   }
387
388   Map args = new HashMap(_args)
389   args.icns = "$pythonCommunityHome/resources/PyCharmCore.icns"
390   args.bundleIdentifier = "com.jetbrains.pycharm"
391   args.platform_prefix = "PyCharmCore"
392   args.help_id = "PY"
393   args."idea.properties.path" = "${paths.distAll}/bin/idea.properties"
394   args."idea.properties" = ["idea.no.jre.check": true, "ide.mac.useNativeClipboard": "false"];
395   args.executable = "pycharm"
396   layoutMacApp(target, ch, args)
397 }