Skip to content

Commit

Permalink
Revert D69399086: pass language version as a parameter
Browse files Browse the repository at this point in the history
Differential Revision:
D69399086

Original commit changeset: c40baeb6d327

Original Phabricator Diff: D69399086

fbshipit-source-id: ef333d53fb51d0ecd31182591eb03b9faba136c1
  • Loading branch information
Daniel9z authored and facebook-github-bot committed Feb 14, 2025
1 parent 1c1a05b commit 0c3f9d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
25 changes: 9 additions & 16 deletions prelude/kotlin/kotlin_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _create_kotlin_sources(
module_name,
"-no-stdlib",
"-no-reflect",
] + ctx.attrs.extra_kotlinc_arguments + get_language_version_arg(ctx),
] + ctx.attrs.extra_kotlinc_arguments + get_language_version(ctx),
)

jvm_target = get_kotlinc_compatible_target(ctx.attrs.target) if ctx.attrs.target else None
Expand Down Expand Up @@ -271,8 +271,9 @@ def _add_plugins(

return _PluginCmdArgs(kotlinc_cmd_args = kotlinc_cmd_args, compile_kotlin_cmd = compile_kotlin_cmd)

def get_language_version(ctx: AnalysisContext) -> str:
def get_language_version(ctx: AnalysisContext) -> list:
kotlin_toolchain = ctx.attrs._kotlin_toolchain[KotlinToolchainInfo]
language_version_kotlinc_arguments = []

# kotlin compiler expects relase version of format 1.6, 1.7, etc. Don't include patch version
current_kotlin_release_version = ".".join(kotlin_toolchain.kotlin_version.split(".")[:2])
Expand All @@ -286,24 +287,17 @@ def get_language_version(ctx: AnalysisContext) -> str:
if ctx.attrs.k2 == True and kotlin_toolchain.allow_k2_usage:
if not current_language_version or current_language_version < "2.0":
if current_kotlin_release_version < "2.0":
current_language_version = "2.0"
language_version_kotlinc_arguments.append("-language-version=2.0")
else:
current_language_version = current_kotlin_release_version
language_version_kotlinc_arguments.append("-language-version=" + current_kotlin_release_version)
else: # use K1
if not current_language_version or current_language_version >= "2.0":
if current_kotlin_release_version >= "2.0":
current_language_version = "1.9"
language_version_kotlinc_arguments.append("-language-version=1.9")
else:
current_language_version = current_kotlin_release_version
language_version_kotlinc_arguments.append("-language-version=" + current_kotlin_release_version)

return current_language_version

def get_language_version_arg(ctx: AnalysisContext) -> list[str]:
language_version = get_language_version(ctx)
return ["-language-version=" + language_version]

def filter_out_language_version(extra_arguments: list) -> list:
return [arg for arg in extra_arguments if not (isinstance(arg, str) and "-language-version" in arg)]
return language_version_kotlinc_arguments

def kotlin_library_impl(ctx: AnalysisContext) -> list[Provider]:
packaging_deps = ctx.attrs.deps + ctx.attrs.exported_deps + ctx.attrs.runtime_deps
Expand Down Expand Up @@ -448,7 +442,7 @@ def build_kotlin_library(
"debug_port": getattr(ctx.attrs, "debug_port", None),
"deps": deps + [kotlin_toolchain.kotlin_stdlib],
"enable_used_classes": ctx.attrs.enable_used_classes,
"extra_kotlinc_arguments": filter_out_language_version(ctx.attrs.extra_kotlinc_arguments or []),
"extra_kotlinc_arguments": (ctx.attrs.extra_kotlinc_arguments or []) + get_language_version(ctx),
"friend_paths": ctx.attrs.friend_paths,
"is_building_android_binary": ctx.attrs._is_building_android_binary,
"jar_postprocessor": ctx.attrs.jar_postprocessor[RunInfo] if hasattr(ctx.attrs, "jar_postprocessor") and ctx.attrs.jar_postprocessor else None,
Expand All @@ -457,7 +451,6 @@ def build_kotlin_library(
"kotlin_compiler_plugins": ctx.attrs.kotlin_compiler_plugins,
"kotlin_toolchain": kotlin_toolchain,
"label": ctx.label,
"language_version": get_language_version(ctx),
"manifest_file": ctx.attrs.manifest_file,
"remove_classes": ctx.attrs.remove_classes,
"required_for_source_only_abi": ctx.attrs.required_for_source_only_abi,
Expand Down
7 changes: 1 addition & 6 deletions prelude/kotlin/kotlincd_jar_creator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def create_jar_artifact_kotlincd(
extra_kotlinc_arguments: list,
incremental: bool,
enable_used_classes: bool,
language_version: str,
is_creating_subtarget: bool = False,
optional_dirs: list[OutputArtifact] = [],
jar_postprocessor: [RunInfo, None] = None,
Expand Down Expand Up @@ -159,7 +158,6 @@ def create_jar_artifact_kotlincd(
actual_abi_generation_mode = actual_abi_generation_mode,
should_kotlinc_run_incrementally = should_kotlinc_run_incrementally,
incremental_state_dir = incremental_state_dir,
language_version = language_version,
)

library_command_builder = command_builder(
Expand Down Expand Up @@ -212,7 +210,6 @@ def create_jar_artifact_kotlincd(
actual_abi_generation_mode = actual_abi_generation_mode,
should_kotlinc_run_incrementally = False,
incremental_state_dir = None,
language_version = language_version,
)
abi_command_builder = command_builder(
kotlin_extra_params = kotlin_extra_params,
Expand Down Expand Up @@ -272,8 +269,7 @@ def _encode_kotlin_extra_params(
should_use_jvm_abi_gen: bool,
actual_abi_generation_mode: AbiGenerationMode,
should_kotlinc_run_incrementally: bool,
incremental_state_dir: Artifact | None,
language_version: str):
incremental_state_dir: Artifact | None):
kosabiPluginOptionsMap = {}
if kotlin_toolchain.kosabi_stubs_gen_plugin != None:
kosabiPluginOptionsMap["kosabi_stubs_gen_plugin"] = kotlin_toolchain.kosabi_stubs_gen_plugin
Expand Down Expand Up @@ -307,7 +303,6 @@ def _encode_kotlin_extra_params(
shouldKotlincRunIncrementally = should_kotlinc_run_incrementally,
incrementalStateDir = incremental_state_dir.as_output() if incremental_state_dir else None,
shouldUseStandaloneKosabi = kotlin_toolchain.kosabi_standalone,
languageVersion = language_version,
)

def _command_builder(
Expand Down

0 comments on commit 0c3f9d9

Please sign in to comment.