@@ -112,7 +112,7 @@ def _create_kotlin_sources(
112
112
module_name ,
113
113
"-no-stdlib" ,
114
114
"-no-reflect" ,
115
- ] + ctx .attrs .extra_kotlinc_arguments + get_language_version_arg (ctx ),
115
+ ] + ctx .attrs .extra_kotlinc_arguments + get_language_version (ctx ),
116
116
)
117
117
118
118
jvm_target = get_kotlinc_compatible_target (ctx .attrs .target ) if ctx .attrs .target else None
@@ -271,8 +271,9 @@ def _add_plugins(
271
271
272
272
return _PluginCmdArgs (kotlinc_cmd_args = kotlinc_cmd_args , compile_kotlin_cmd = compile_kotlin_cmd )
273
273
274
- def get_language_version (ctx : AnalysisContext ) -> str :
274
+ def get_language_version (ctx : AnalysisContext ) -> list :
275
275
kotlin_toolchain = ctx .attrs ._kotlin_toolchain [KotlinToolchainInfo ]
276
+ language_version_kotlinc_arguments = []
276
277
277
278
# kotlin compiler expects relase version of format 1.6, 1.7, etc. Don't include patch version
278
279
current_kotlin_release_version = "." .join (kotlin_toolchain .kotlin_version .split ("." )[:2 ])
@@ -286,24 +287,17 @@ def get_language_version(ctx: AnalysisContext) -> str:
286
287
if ctx .attrs .k2 == True and kotlin_toolchain .allow_k2_usage :
287
288
if not current_language_version or current_language_version < "2.0" :
288
289
if current_kotlin_release_version < "2.0" :
289
- current_language_version = " 2.0"
290
+ language_version_kotlinc_arguments . append ( "-language-version= 2.0")
290
291
else :
291
- current_language_version = current_kotlin_release_version
292
+ language_version_kotlinc_arguments . append ( "-language-version=" + current_kotlin_release_version )
292
293
else : # use K1
293
294
if not current_language_version or current_language_version >= "2.0" :
294
295
if current_kotlin_release_version >= "2.0" :
295
- current_language_version = " 1.9"
296
+ language_version_kotlinc_arguments . append ( "-language-version= 1.9")
296
297
else :
297
- current_language_version = current_kotlin_release_version
298
+ language_version_kotlinc_arguments . append ( "-language-version=" + current_kotlin_release_version )
298
299
299
- return current_language_version
300
-
301
- def get_language_version_arg (ctx : AnalysisContext ) -> list [str ]:
302
- language_version = get_language_version (ctx )
303
- return ["-language-version=" + language_version ]
304
-
305
- def filter_out_language_version (extra_arguments : list ) -> list :
306
- return [arg for arg in extra_arguments if not (isinstance (arg , str ) and "-language-version" in arg )]
300
+ return language_version_kotlinc_arguments
307
301
308
302
def kotlin_library_impl (ctx : AnalysisContext ) -> list [Provider ]:
309
303
packaging_deps = ctx .attrs .deps + ctx .attrs .exported_deps + ctx .attrs .runtime_deps
@@ -448,7 +442,7 @@ def build_kotlin_library(
448
442
"debug_port" : getattr (ctx .attrs , "debug_port" , None ),
449
443
"deps" : deps + [kotlin_toolchain .kotlin_stdlib ],
450
444
"enable_used_classes" : ctx .attrs .enable_used_classes ,
451
- "extra_kotlinc_arguments" : filter_out_language_version (ctx .attrs .extra_kotlinc_arguments or []),
445
+ "extra_kotlinc_arguments" : (ctx .attrs .extra_kotlinc_arguments or []) + get_language_version ( ctx ),
452
446
"friend_paths" : ctx .attrs .friend_paths ,
453
447
"is_building_android_binary" : ctx .attrs ._is_building_android_binary ,
454
448
"jar_postprocessor" : ctx .attrs .jar_postprocessor [RunInfo ] if hasattr (ctx .attrs , "jar_postprocessor" ) and ctx .attrs .jar_postprocessor else None ,
@@ -457,7 +451,6 @@ def build_kotlin_library(
457
451
"kotlin_compiler_plugins" : ctx .attrs .kotlin_compiler_plugins ,
458
452
"kotlin_toolchain" : kotlin_toolchain ,
459
453
"label" : ctx .label ,
460
- "language_version" : get_language_version (ctx ),
461
454
"manifest_file" : ctx .attrs .manifest_file ,
462
455
"remove_classes" : ctx .attrs .remove_classes ,
463
456
"required_for_source_only_abi" : ctx .attrs .required_for_source_only_abi ,
0 commit comments