aboutsummaryrefslogtreecommitdiffstats
path: root/build/export_generators/ide-gradle/jvm_args.jinja
blob: 5694e1a6cf70d4aeba4922a1f79a2c776e051a73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{%- macro JvmArgs(jvm_args) -%}
{%-     if jvm_args|length -%}
{%-         set jnis_args = jvm_args|select('startsWith', 'jnis=') -%}
{%-         set other_jvm_args = jvm_args|reject('startsWith', 'jnis=') -%}
{%-         set ep_jvm_args = other_jvm_args|select('eq', '--enable-preview') -%}
{%-         set ea_jvm_args = other_jvm_args|select('eq', '-ea') -%}
{%-         set other_jvm_args = other_jvm_args|reject('eq', '--enable-preview')|reject('eq', '-ea') -%}
{%-         if jnis_args|length %}
    val library_path = listOf(
{%-             for jnis_arg in jnis_args -%}
{%-                 set jnis = split(jnis_arg|replace('jnis=', ''), ',') -%}
{%-                 for jni in jnis -%}
{%-                     set path_and_name = rsplit(jni, "/", 2) %}
        "$arcadia_root/{{ path_and_name[0] }}",
{%-                 endfor -%}
{%-             endfor %}
    ).joinToString(":")
{%          endif %}
    jvmArgs = mutableListOf(
{%-         if jnis_args|length -%}
{#-             Increase heap, else happened java.lang.OutOfMemoryError #}
        "-Xmx2048m",
        "-Djava.library.path=$library_path",
{%-         endif -%}
{%-         if ep_jvm_args|length %}
        "{{ ep_jvm_args|first }}",
{%-         endif -%}
{%-         if ea_jvm_args|length %}
        "{{ ea_jvm_args|first }}",
{%-         endif -%}
{%-         if other_jvm_args|length -%}
{%-             for jvm_arg in other_jvm_args %}
        "{{ jvm_arg|replace("$", "\\$") }}",
{%-             endfor -%}
{%-         endif %}
    )
{%      endif -%}
{%- endmacro -%}

{%- set jvm_args = [] -%}
{%- if target.enable_preview -%}
{%-     set jvm_args = jvm_args + ["--enable-preview"] -%}
{%- endif -%}
{%- if jnis|length -%}
{%-     set jvm_args = jvm_args + ["jnis=" + jnis|join(",")] -%}
{%- endif %}
{%- if target.jvm_args|length %}
{%-     set jvm_args = jvm_args + target.jvm_args -%}
{%- endif -%}
{%- if jvm_args|length %}

tasks.withType<JavaExec> {
{#- glue -#}
{{ JvmArgs(jvm_args) }}
{#- glue -#}
}
{%- endif -%}

{%- set test_jvm_args = jvm_args -%}
{%- set extra_jvm_args = extra_targets|selectattr('jvm_args')|map(attribute='jvm_args')|sum -%}
{%- if extra_jvm_args|length and test_jvm_args|join('|') != extra_jvm_args|join('|') %}
{%-     set test_jvm_args = test_jvm_args + extra_jvm_args -%}
{%- endif -%}
{%- set test_cwds = extra_targets|selectattr('test_cwd')|map(attribute='test_cwd')|sum|unique -%}
{%- if test_jvm_args|length or test_cwds|length %}

tasks.withType<Test> {
{#- glue -#}
{{ JvmArgs(test_jvm_args) }}
{%- if target.enable_preview -%}
    environment["JAVA_TOOL_OPTIONS"] = "--enable-preview"
{%  endif -%}
{%- if test_cwds|length -%}
{%-     if test_cwds|length > 1 %}
// Use first of found TEST_CWDs: {%- for tcwd in test_cwds -%}{{ tcwd }}{%- if not loop.last -%}, {%- endif -%}{%- endfor -%}
{%-     endif -%}
{%-     set test_cwd = test_cwds|first -%}
{%-     if test_cwd[0] != '/' -%}
{%-         set test_cwd = '$arcadia_root/' + test_cwd -%}
{%-     endif %}
    workingDir({{ PatchRoots(test_cwd) }})
{%  endif -%}
}
{%- endif -%}