Skip to content

Commit

Permalink
Remove tree artifacts (#287)
Browse files Browse the repository at this point in the history
remove the generation of unused tree artifacts from the compile step. Tree artifacts, (created by declare_directory) are only useful when an action produces an unknown number of outputs. It this case, this would only result in extra overhead of bundling the produced directories in archives with ever using them.

Co-authored-by: Christian Edward Gruber <[email protected]>
  • Loading branch information
restingbull and cgruber authored Feb 27, 2020
1 parent ffcd2b2 commit f5b824e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 14 deletions.
24 changes: 10 additions & 14 deletions kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def _build_resourcejar_action(ctx):
return resources_jar_output

# MAIN ACTIONS #########################################################################################################
def _declare_output_directory(ctx, aspect, dir_name):
return ctx.actions.declare_directory("_kotlinc/%s_%s/%s_%s" % (ctx.label.name, aspect, ctx.label.name, dir_name))
def _output_dir_path(ctx, aspect, dir_name):
return "_kotlinc/%s_%s/%s_%s" % (ctx.label.name, aspect, ctx.label.name, dir_name)

def _partition_srcs(srcs):
"""Partition sources for the jvm aspect."""
Expand Down Expand Up @@ -173,17 +173,17 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar):
else:
fail("only one friend is possible")

classes_directory = _declare_output_directory(ctx, "jvm", "classes")
generated_classes_directory = _declare_output_directory(ctx, "jvm", "generated_classes")
sourcegen_directory = _declare_output_directory(ctx, "jvm", "sourcegenfiles")
temp_directory = _declare_output_directory(ctx, "jvm", "temp")
classes_directory = _output_dir_path(ctx, "jvm", "classes")
generated_classes_directory = _output_dir_path(ctx, "jvm", "generated_classes")
sourcegen_directory = _output_dir_path(ctx, "jvm", "sourcegenfiles")
temp_directory = _output_dir_path(ctx, "jvm", "temp")

args = _utils.init_args(ctx, rule_kind, module_name)

args.add("--classdir", classes_directory.path)
args.add("--sourcegendir", sourcegen_directory.path)
args.add("--tempdir", temp_directory.path)
args.add("--kotlin_generated_classdir", generated_classes_directory.path)
args.add("--classdir", classes_directory)
args.add("--sourcegendir", sourcegen_directory)
args.add("--tempdir", temp_directory)
args.add("--kotlin_generated_classdir", generated_classes_directory)

args.add("--output", output_jar)
args.add("--kotlin_output_jdeps", ctx.outputs.jdeps)
Expand Down Expand Up @@ -222,10 +222,6 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar):
output_jar,
ctx.outputs.jdeps,
ctx.outputs.srcjar,
sourcegen_directory,
classes_directory,
temp_directory,
generated_classes_directory,
],
executable = toolchain.kotlinbuilder.files_to_run.executable,
execution_requirements = {"supports-workers": "1"},
Expand Down
57 changes: 57 additions & 0 deletions kotlin/internal/repositories/nomaven_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This file contains the Kotlin compiler repository definitions. It should not be loaded directly by client workspaces.
"""

load(
"//kotlin/internal:defs.bzl",
_KT_COMPILER_REPO = "KT_COMPILER_REPO",
)
load(
"@bazel_tools//tools/build_defs/repo:http.bzl",
_http_archive = "http_archive",
_http_file = "http_file",
)

BAZEL_JAVA_LAUNCHER_VERSION = "0.28.1"

KOTLIN_CURRENT_COMPILER_RELEASE = {
"urls": [
"https://github.com/JetBrains/kotlin/releases/download/v1.3.50/kotlin-compiler-1.3.50.zip",
],
"sha256": "69424091a6b7f52d93eed8bba2ace921b02b113dbb71388d704f8180a6bdc6ec",
}

def kotlin_repositories(compiler_release = KOTLIN_CURRENT_COMPILER_RELEASE):
"""Call this in the WORKSPACE file to setup the Kotlin rules.
Args:
compiler_release: (internal) dict containing "urls" and "sha256" for the Kotlin compiler.
"""
_http_archive(
name = _KT_COMPILER_REPO,
urls = compiler_release["urls"],
sha256 = compiler_release["sha256"],
build_file = "@io_bazel_rules_kotlin//kotlin/internal/repositories:BUILD.com_github_jetbrains_kotlin",
strip_prefix = "kotlinc",
)

_http_file(
name = "kt_java_stub_template",
urls = [("https://raw.githubusercontent.com/bazelbuild/bazel/" +
BAZEL_JAVA_LAUNCHER_VERSION +
"/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" +
"java_stub_template.txt")],
sha256 = "e6531a6539ec1e38fec5e20523ff4bfc883e1cc0209eb658fe82eb918eb49657",
)

0 comments on commit f5b824e

Please sign in to comment.