Skip to content

Commit 139b258

Browse files
committed
Support COPY_FILE in ya ide gradle, refactor templates
Support COPY_FILE in ya ide gradle, refactor templates commit_hash:1ba3f61a354cf8ab6bc8fefeceb71cf601adbd00
1 parent c92f471 commit 139b258

File tree

6 files changed

+104
-44
lines changed

6 files changed

+104
-44
lines changed

build/export_generators/ide-gradle/build.gradle.kts.jinja

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
{%- endif -%}
1313
{%- endmacro -%}
1414

15+
{%- macro Depends(prefix, index) -%}
16+
{%- if proto_template %}
17+
tasks.getByName("prepareMainProtos").dependsOn({{ prefix }}{{ index }})
18+
{%- endif %}
19+
tasks.compileJava.configure {
20+
dependsOn({{ prefix }}{{ index }})
21+
}
22+
tasks.compileTestJava.configure {
23+
dependsOn({{ prefix }}{{ index }})
24+
}
25+
{%- if with_kotlin %}
26+
tasks.compileKotlin.configure {
27+
dependsOn({{ prefix }}{{ index }})
28+
}
29+
tasks.compileTestKotlin.configure {
30+
dependsOn({{ prefix }}{{ index }})
31+
}
32+
{% endif -%}
33+
{%- endmacro -%}
34+
1535
{%- include "[generator]/vars.jinja" -%}
1636
{%- include "[generator]/import.jinja" -%}
1737
{%- include "[generator]/repositories.jinja" -%}
@@ -29,6 +49,7 @@
2949
{%- include "[generator]/run_program.jinja" -%}
3050
{%- include "[generator]/run_java_program.jinja" -%}
3151
{%- include "[generator]/run_common.jinja" -%}
52+
{%- include "[generator]/copy_file.jinja" -%}
3253
{%- include "[generator]/dependencies.jinja" -%}
3354
{%- include "extra-tests.gradle.kts" ignore missing -%}
3455
{%- if publish -%}

build/export_generators/ide-gradle/build.gradle.kts.proto.jinja

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
{%- endif -%}
1313
{%- endmacro -%}
1414

15+
{%- macro Depends(prefix, index) -%}
16+
{%- if proto_template %}
17+
tasks.getByName("prepareMainProtos").dependsOn({{ prefix }}{{ index }})
18+
{%- endif %}
19+
tasks.compileJava.configure {
20+
dependsOn({{ prefix }}{{ index }})
21+
}
22+
tasks.compileTestJava.configure {
23+
dependsOn({{ prefix }}{{ index }})
24+
}
25+
{%- if with_kotlin %}
26+
tasks.compileKotlin.configure {
27+
dependsOn({{ prefix }}{{ index }})
28+
}
29+
tasks.compileTestKotlin.configure {
30+
dependsOn({{ prefix }}{{ index }})
31+
}
32+
{% endif -%}
33+
{%- endmacro -%}
34+
1535
{%- macro PatchGeneratedProto(arg, relative = false) -%}
1636
{%- if relative -%}
1737
"{{ arg|replace(export_root + "/", "")|replace(arcadia_root + "/", "") }}"
@@ -35,6 +55,7 @@
3555
{%- include "[generator]/run_program.jinja" -%}
3656
{%- include "[generator]/run_java_program.jinja" -%}
3757
{%- include "[generator]/run_common.jinja" -%}
58+
{%- include "[generator]/copy_file.jinja" -%}
3859
{%- include "[generator]/javadoc.jinja" -%}
3960
{%- include "[generator]/proto_dependencies.jinja" -%}
4061
{%- include "[generator]/debug.jinja" ignore missing -%}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{%- set copies = target.target_commands|selectattr("macro", "eq", "copy_file") -%}
2+
{%- if copies|length -%}
3+
{%- for copy in copies -%}
4+
{%- set src = copy.args[0] -%}
5+
{%- set srcs = [ src ] -%}
6+
{%- set from_arcadia = srcs|select("startsWith", arcadia_root)|length -%}
7+
{%- set from_build = srcs|select("startsWith", export_root)|length -%}
8+
{%- set dst = copy.args[1] -%}
9+
{%- set dsts = [ dst ] -%}
10+
{%- set to_arcadia = dsts|select("startsWith", arcadia_root)|length -%}
11+
{%- set to_build = dsts|select("startsWith", export_root)|length -%}
12+
{%- if (from_arcadia or from_build) and (to_arcadia or to_build) -%}
13+
{%- set src_split = rsplit(src, "/", 2) -%}
14+
{%- set src_path = src_split[0] -%}
15+
{%- set src_name = src_split[1] -%}
16+
{%- set dst_split = rsplit(dst, "/", 2) -%}
17+
{%- set dst_path = dst_split[0] -%}
18+
{%- set dst_name = dst_split[1] %}
19+
20+
val copy{{ loop.index }} = tasks.register<Copy>("copy{{ loop.index }}") {
21+
from({{ PatchRoots(src_path) }}) {
22+
include("{{ src_name }}")
23+
}
24+
into({{ PatchRoots(dst_path) }})
25+
{%- if src_name != dst_name %}
26+
rename("{{ src_name }}", "{{ dst_name }}")
27+
{%- endif %}
28+
}
29+
{%- set copy_index = loop.index %}
30+
{%- if target.runs|length -%}
31+
{%- for run in target.runs %}
32+
{%- if from_arcadia %}
33+
runJav{{ loop.index }}.dependsOn(copy{{ copy_index }})
34+
{%- else %}
35+
copy{{ copy_index }}.dependsOn(runJav{{ loop.index }})
36+
{%- endif -%}
37+
{% endfor -%}
38+
{%- endif -%}
39+
{%- if target.custom_runs|length -%}
40+
{%- for custom_run in target.custom_runs %}
41+
{%- if from_arcadia %}
42+
runProg{{ loop.index }}.dependsOn(copy{{ copy_index }})
43+
{%- else %}
44+
copy{{ copy_index }}.dependsOn(runProg{{ loop.index }})
45+
{%- endif -%}
46+
{% endfor -%}
47+
{%- endif -%}
48+
{%- if from_build -%}
49+
{{ Depends("copy", loop.index) }}
50+
{%- endif -%}
51+
{%- endif -%}
52+
{%- endfor -%}
53+
{%- endif -%}

build/export_generators/ide-gradle/generator.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ custom_runs-cmake_packages-components="list"
8484
javac-flags="list"
8585
kotlinc-flags="list"
8686

87+
target_commands="list"
88+
target_commands-ITEM="dict"
89+
target_commands-macro="str"
90+
target_commands-args="list"
91+
target_commands-args_escaped="list"
92+
8793
[attrs.root]
8894

8995
[attrs.dir]

build/export_generators/ide-gradle/run_java_program.jinja

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ val runJav{{ loop.index }} = task<JavaExec>("runJavaProgram{{ loop.index }}") {
3434
{%- else %}
3535
{{ PatchRoots(arg, false, true) }},
3636
{%- endif %}
37-
{%- elif run.tool|select("in", arg)|length or run.in|select("eq", arg)|length or run.in_dir|select("eq", arg)|length %}
37+
{%- elif run.tool|select("in", arg)|length %}
3838
{{ PatchRoots(arg, true) }},
3939
{%- else %}
4040
{{ PatchRoots(arg) }},
@@ -88,27 +88,6 @@ val runJav{{ loop.index }} = task<JavaExec>("runJavaProgram{{ loop.index }}") {
8888
run-tool="list"
8989
#}
9090
}
91-
92-
{%- if proto_template %}
93-
94-
tasks.getByName("prepareMainProtos").dependsOn(runJav{{ loop.index }})
95-
{%- endif %}
96-
97-
tasks.compileJava.configure {
98-
dependsOn(runJav{{ loop.index }})
99-
}
100-
tasks.compileTestJava.configure {
101-
dependsOn(runJav{{ loop.index }})
102-
}
103-
{%- if with_kotlin %}
104-
105-
tasks.compileKotlin.configure {
106-
dependsOn(runJav{{ loop.index }})
107-
}
108-
109-
tasks.compileTestKotlin.configure {
110-
dependsOn(runJav{{ loop.index }})
111-
}
112-
{%- endif -%}
91+
{{ Depends("runJav", loop.index) }}
11392
{%- endfor -%}
11493
{%- endif -%}

build/export_generators/ide-gradle/run_program.jinja

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,6 @@ val runProg{{ loop.index }} = task<Exec>("runProgram{{ loop.index }}") {
5050
custom_run-env="list"
5151
#}
5252
}
53-
54-
{%- if proto_template %}
55-
56-
tasks.getByName("prepareMainProtos").dependsOn(runProg{{ loop.index }})
57-
{%- endif %}
58-
59-
tasks.compileJava.configure {
60-
dependsOn(runProg{{ loop.index }})
61-
}
62-
tasks.compileTestJava.configure {
63-
dependsOn(runProg{{ loop.index }})
64-
}
65-
{%- if with_kotlin %}
66-
67-
tasks.compileKotlin.configure {
68-
dependsOn(runProg{{ loop.index }})
69-
}
70-
tasks.compileTestKotlin.configure {
71-
dependsOn(runProg{{ loop.index }})
72-
}
73-
{% endif -%}
53+
{{ Depends("runProg", loop.index) }}
7454
{%- endfor -%}
7555
{%- endif -%}

0 commit comments

Comments
 (0)