Skip to content

Commit

Permalink
Move maven repo back to kotlin_repos
Browse files Browse the repository at this point in the history
Make examples use the release repository
Make git ignore profiling artifacts

Issue: #269 (comment)
  • Loading branch information
Corbin McNeely-Smith committed Feb 6, 2020
1 parent 7103070 commit abb9183
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
**/.ijwb
**/.aswb
**/.vscode
**/trace.profile.gz
trace.profile.gz
7 changes: 3 additions & 4 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ test_suite(
# Release target.
release_archive(
name = "rules_kotlin_release",
dist_files = {
"BUILD": "",
"WORKSPACE": """workspace(name = "io_bazel_rules_kotlin")""",
src_map = {
"BUILD.release.bazel.bazel" : "BUILD.bazel",
"WORKSPACE.release.bazel" : "WORKSPACE",
},
extension = "tgz",
deps = [
"//kotlin:pkg",
"//src/main/kotlin:pkg",
Expand Down
13 changes: 13 additions & 0 deletions BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 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.
14 changes: 14 additions & 0 deletions WORKSPACE.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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.
workspace(name = "io_bazel_rules_kotlin")
7 changes: 2 additions & 5 deletions kotlin/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ release_archive(
name = "pkg",
visibility = ["//visibility:public"],
srcs = glob(["*.bzl"]),
dist_files = {
"BUILD": """
load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains")
kt_configure_toolchains()
""",
src_map = {
"BUILD.release.bazel.bazel" : "BUILD.bazel",
},
deps = [
"//kotlin/internal/js:pkg",
Expand Down
16 changes: 16 additions & 0 deletions kotlin/internal/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 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.

load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains")
kt_configure_toolchains()
11 changes: 3 additions & 8 deletions kotlin/internal/js/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ release_archive(
"*.bzl",
"*.py",
]),
dist_files = {
"BUILD": """
py_binary(
name = "importer",
srcs = ["importer.py"],
visibility = ["//visibility:public"],
)""",
},
src_map = {
"BUILD.release.bazel" : "BUILD.bazel"
}
)
19 changes: 19 additions & 0 deletions kotlin/internal/js/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

py_binary(
name = "importer",
srcs = ["importer.py"],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion kotlin/internal/repositories/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ release_archive(
"BUILD",
"BUILD.com_github_jetbrains_kotlin",
],
renames = {
src_map = {
"nomaven_repositories.bzl" : "repositories.bzl",
}
)
77 changes: 15 additions & 62 deletions kotlin/internal/utils/packager.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@

load("@rules_pkg//:pkg.bzl", "pkg_tar")

def release_archive(name, dist_files = {}, srcs = None, renames = {}, **kwargs):
def release_archive(name, srcs = None, src_map = {}, package_dir = None, extension="tgz", deps=None):
"""
Creates an tar of the srcs, dist_files, and renamed label artifacts.
Creates an tar of the srcs, and renamed label artifacts.
Usage:
//:BUILD
load("//kotlin/internal/utils:packager.bzl", "release_archive")
release_archive(
name = "release_archive",
dist_files = {
"BUILD": "",
"WORKSPACE": "workspace(name = "io_bazel_rules_kotlin")",
src_map = {
"BUILD.release.bazel.bazel": "BUILD.bazel",
"WORKSPACE.release.bazel": "WORKSPACE",
},
extension = "tgz",
deps = [
"//dep:pkg"
],
Expand All @@ -46,34 +45,25 @@ def release_archive(name, dist_files = {}, srcs = None, renames = {}, **kwargs):
Args:
name: target identifier, points to a pkg_tar target.
package_dir: directory to place the srcs, renames, and dist_files under. Defaults to the current directory.
package_dir: directory to place the srcs, src_map, and dist_files under. Defaults to the current directory.
dist_files: dict of <filename string>:<contents string> for files to be generated in the distribution artifact.
renames: dict of <label>:<name string> for labels to be renamed and included in the distribution.
src_map: dict of <label>:<name string> for labels to be renamed and included in the distribution.
srcs: files to include in the distribution.
ext: Extension of the archive. Controls the type of tar file generated.
deps: release_archives to be included.
"""

if "package_dir" not in kwargs:
if package_dir == None:
pkg_name = native.package_name()
local_pkg_index = pkg_name.rfind("/")
if local_pkg_index > -1:
pkg_name = pkg_name[local_pkg_index:]
kwargs["package_dir"] = pkg_name
package_dir = pkg_name

# release_archives are always public.
kwargs["visibility"] = ["//visibility:public"]
if srcs == None:
srcs = []
for path, content in dist_files.items():
gen_name = name + "_" + path
_gen_file(
name = gen_name,
contents = content,
path = path,
)
srcs += [gen_name]

for source, target in renames.items():
for source, target in src_map.items():
rename_name = name + "_" + target
_rename(
name = rename_name,
Expand All @@ -84,49 +74,12 @@ def release_archive(name, dist_files = {}, srcs = None, renames = {}, **kwargs):

pkg_tar(
name = name,
srcs = srcs,
**kwargs
srcs = srcs if srcs == None else [],
extension = extension,
visibility = ["//visibility:public"],
deps = deps if deps == None else [],
)

_file_header = """
# Copyright 2020 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.
"""

def _gen_file_impl(ctx):
"""
Creates a file in a directory based on the rule name.
Useful for creating source files that may overlap existing sources in a given directory.
** This is not windows safe. **
Args:
path: a valid, raltive path string. Unvalidated.
contents: string to write to the path.
"""
out = ctx.actions.declare_file(ctx.label.name + "/" + ctx.attr.path)
ctx.actions.write(out, _file_header + ctx.attr.contents)
return [DefaultInfo(files = depset([out]))]

_gen_file = rule(
implementation = _gen_file_impl,
attrs = {
"contents": attr.string(mandatory = True),
"path": attr.string(mandatory = True),
},
)

def _rename_impl(ctx):
out_file = ctx.actions.declare_file(ctx.label.name + "/" + ctx.attr.target)
in_file = ctx.file.source
Expand Down
30 changes: 3 additions & 27 deletions src/main/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,10 @@ release_archive(
srcs = [
":compiler_lib.jar",
],
# Generate the release build file, relying on precompiled jars.
dist_files = {
"BUILD": """
java_import(
name = "import_builder",
jars = ["kotlin_deploy.jar"],
)
java_import(
name = "compiler_lib",
jars = ["compiler_lib.jar"],
)
java_binary(
name = "builder",
main_class = "io.bazel.kotlin.builder.KotlinBuilderMain",
visibility = ["//visibility:public"],
runtime_deps = [":import_builder"],
data = [
":compiler_lib",
"@com_github_jetbrains_kotlin//:lib/kotlin-compiler.jar",
],
)
""",
},
package_dir = "src/main/kotlin", # explicitly set the package directory, as there are no parent release_archives.
renames = {
src_map = {
# must rename, otherwise it creates a cyclical dependency in the release.
":builder_deploy.jar": "kotlin_deploy.jar",
":builder_deploy.jar": "kotlin_linc.jar",
"BUILD.release.bazel" :"BUILD.bazel",
},
)
34 changes: 34 additions & 0 deletions src/main/kotlin/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

java_import(
name = "import_builder",
jars = ["kotlin_linc.jar"],
)

java_import(
name = "compiler_lib",
jars = ["compiler_lib.jar"],
)

java_binary(
name = "builder",
main_class = "io.bazel.kotlin.builder.KotlinBuilderMain",
visibility = ["//visibility:public"],
runtime_deps = [":import_builder"],
data = [
":compiler_lib",
"@com_github_jetbrains_kotlin//:lib/kotlin-compiler.jar",
],
)
13 changes: 2 additions & 11 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,8 @@ release_archive(
name = "pkg",
visibility = ["//visibility:public"],
srcs = ["empty.jar"],
dist_files = {
"BUILD" : """
exports_files(["empty.jar"])
java_import(
name = "android_sdk",
jars = ["@bazel_tools//tools/android:android_jar"],
neverlink = 1,
visibility = ["//visibility:public"],
)
"""
src_map = {
"BUILD.release.bazel" : "BUILD.bazel",
},
)

22 changes: 22 additions & 0 deletions third_party/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.

exports_files(["empty.jar"])

java_import(
name = "android_sdk",
jars = ["@bazel_tools//tools/android:android_jar"],
neverlink = 1,
visibility = ["//visibility:public"],
)

0 comments on commit abb9183

Please sign in to comment.