Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ianoc committed Mar 17, 2020
0 parents commit 01fd799
Show file tree
Hide file tree
Showing 19 changed files with 954 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Release
on:
push:
branches:
- master
env:
PROTOBUF_SHA: d0bfd5221182da1a7cc280f3337b5e41a89539cf
GRPC_JAVA_SHA: fd7d2e5eb4dd020bb892278c78f7b3ef901232c1
jobs:
java-grpc-plugin-binaries:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
include:
- os: macos-latest
artifact: protoc_grpc_java_plugin-macos
- os: ubuntu-latest
artifact: protoc_grpc_java_plugin-linux
env:
BAZEL_BIN_LOC: "${{ github.workspace }}/.bazel-cache/bazel-bin"
steps:
- uses: actions/checkout@v2
- name: Bazel output cache
id: cache-bazel
uses: actions/cache@v1
with:
path: "${{ github.workspace }}/.bazel-cache"
key: ${{ runner.os }}-bazel-out-${{ github.run_id}}
restore-keys: |
${{ runner.os }}-bazel-out-
- name: Configure bazel config for actions
run: |
echo "build --disk_cache ${{ github.workspace }}/.bazel-cache/disk-cache" >> user.bazelrc
echo "build --repository_cache ${{ github.workspace }}/.bazel-cache/repo-cache" >> user.bazelrc
- name: Build protoc_grpc_java_plugin
run: ./ci_scripts/build_grpc_java_plugin.sh protoc_grpc_java_plugin
- name: Prepare outputs from platform run
run: ./ci_scripts/prepare_output.sh protoc_grpc_java_plugin ${{ matrix.artifact }} staging-directory
- uses: actions/upload-artifact@master
with:
name: ${{ matrix.artifact }}
path: staging-directory
make_release:
name: Make release
needs: java-grpc-plugin-binaries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download linux protoc_grpc_java_plugin
uses: actions/download-artifact@v1
with:
name: protoc_grpc_java_plugin-linux
path: downloads
- name: Download macos protoc_grpc_java_plugin
uses: actions/download-artifact@v1
with:
name: protoc_grpc_java_plugin-macos
path: downloads
- name: show downloads
run : ls -R downloads
- name: Build ci_scripts/make_java_grpc_zip.sh
run: ./ci_scripts/make_java_grpc_zip.sh
- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "v0.1-${{ github.run_number }}"
prerelease: false
title: "Auto generated release"
files: |
downloads/protoc_grpc_java_plugin-macos
downloads/protoc_grpc_java_plugin-linux
grpc-java.zip
grpc-java.zip.sha256
id: "automatic_releases"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.class
*.log
bazel-*
32 changes: 32 additions & 0 deletions 3rdparty/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@rules_java//java:defs.bzl", "java_binary")

java_library(
name = "example",
srcs = glob(["*.java"], exclude=["*Main.java"]),
visibility = ["//src/main/java/com/example/cmdline:__pkg__"],
plugins = [
"//3rdparty:dagger_component_plugin",
],
deps = [
"@third_party_jvm//3rdparty/jvm/com/google/guava:guava",
"@third_party_jvm//3rdparty/jvm/com/google/dagger:dagger_compiler",
"@third_party_jvm//3rdparty/jvm/com/google/dagger:dagger",
"@third_party_jvm//3rdparty/jvm/com/google/dagger:dagger_spi",
"@third_party_jvm//3rdparty/jvm/com/google/code/findbugs:jsr305",
"@third_party_jvm//3rdparty/jvm/javax/annotation:jsr250_api",
"@third_party_jvm//3rdparty/jvm/javax/inject:javax_inject",
],
)


java_binary(
name = "ProjectRunnerMain",
srcs = ["ProjectRunnerMain.java"],
main_class = "com.example.ProjectRunnerMain",
deps = [
":example",
"@third_party_jvm//3rdparty/jvm/com/google/guava:guava",
"@third_party_jvm//3rdparty/jvm/com/google/code/findbugs:jsr305",
"@third_party_jvm//3rdparty/jvm/javax/annotation:jsr250_api",
],
)
129 changes: 129 additions & 0 deletions 3rdparty/target_file.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Do not edit. bazel-deps autogenerates this file from.
_JAVA_LIBRARY_TEMPLATE = """
java_library(
name = "{name}",
exports = [
{exports}
],
runtime_deps = [
{runtime_deps}
],
visibility = [
"{visibility}"
]
)\n"""

_SCALA_IMPORT_TEMPLATE = """
scala_import(
name = "{name}",
exports = [
{exports}
],
jars = [
{jars}
],
runtime_deps = [
{runtime_deps}
],
visibility = [
"{visibility}"
]
)
"""

_SCALA_LIBRARY_TEMPLATE = """
scala_library(
name = "{name}",
exports = [
{exports}
],
runtime_deps = [
{runtime_deps}
],
visibility = [
"{visibility}"
]
)
"""


def _build_external_workspace_from_opts_impl(ctx):
build_header = ctx.attr.build_header
separator = ctx.attr.separator
target_configs = ctx.attr.target_configs

result_dict = {}
for key, cfg in target_configs.items():
build_file_to_target_name = key.split(":")
build_file = build_file_to_target_name[0]
target_name = build_file_to_target_name[1]
if build_file not in result_dict:
result_dict[build_file] = []
result_dict[build_file].append(cfg)

for key, file_entries in result_dict.items():
build_file_contents = build_header + '\n\n'
for build_target in file_entries:
entry_map = {}
for entry in build_target:
elements = entry.split(separator)
build_entry_key = elements[0]
if elements[1] == "L":
entry_map[build_entry_key] = [e for e in elements[2::] if len(e) > 0]
elif elements[1] == "B":
entry_map[build_entry_key] = (elements[2] == "true" or elements[2] == "True")
else:
entry_map[build_entry_key] = elements[2]

exports_str = ""
for e in entry_map.get("exports", []):
exports_str += "\"" + e + "\",\n"

jars_str = ""
for e in entry_map.get("jars", []):
jars_str += "\"" + e + "\",\n"

runtime_deps_str = ""
for e in entry_map.get("runtimeDeps", []):
runtime_deps_str += "\"" + e + "\",\n"

name = entry_map["name"].split(":")[1]
if entry_map["lang"] == "java":
build_file_contents += _JAVA_LIBRARY_TEMPLATE.format(name = name, exports=exports_str, runtime_deps=runtime_deps_str, visibility=entry_map["visibility"])
elif entry_map["lang"].startswith("scala") and entry_map["kind"] == "import":
build_file_contents += _SCALA_IMPORT_TEMPLATE.format(name = name, exports=exports_str, jars=jars_str, runtime_deps=runtime_deps_str, visibility=entry_map["visibility"])
elif entry_map["lang"].startswith("scala") and entry_map["kind"] == "library":
build_file_contents += _SCALA_LIBRARY_TEMPLATE.format(name = name, exports=exports_str, runtime_deps=runtime_deps_str, visibility=entry_map["visibility"])
else:
print(entry_map)

ctx.file(ctx.path(key + "/BUILD"), build_file_contents, False)
return None

build_external_workspace_from_opts = repository_rule(
attrs = {
"target_configs": attr.string_list_dict(mandatory = True),
"separator": attr.string(mandatory = True),
"build_header": attr.string(mandatory = True),
},
implementation = _build_external_workspace_from_opts_impl
)




def build_header():
return """"""

def list_target_data_separator():
return "|||"

def list_target_data():
return {
"3rdparty/jvm/javax/inject:javax_inject": ["lang||||||java","name||||||//3rdparty/jvm/javax/inject:javax_inject","visibility||||||//visibility:public","kind||||||library","deps|||L|||","jars|||L|||","sources|||L|||","exports|||L|||//external:jar/javax/inject/javax_inject","runtimeDeps|||L|||","processorClasses|||L|||","generatesApi|||B|||false","licenses|||L|||","generateNeverlink|||B|||false"]
}


def build_external_workspace(name):
return build_external_workspace_from_opts(name = name, target_configs = list_target_data(), separator = list_target_data_separator(), build_header = build_header())

76 changes: 76 additions & 0 deletions 3rdparty/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Do not edit. bazel-deps autogenerates this file from dependencies.yaml.
def _jar_artifact_impl(ctx):
jar_name = "%s.jar" % ctx.name
ctx.download(
output=ctx.path("jar/%s" % jar_name),
url=ctx.attr.urls,
sha256=ctx.attr.sha256,
executable=False
)
src_name="%s-sources.jar" % ctx.name
srcjar_attr=""
has_sources = len(ctx.attr.src_urls) != 0
if has_sources:
ctx.download(
output=ctx.path("jar/%s" % src_name),
url=ctx.attr.src_urls,
sha256=ctx.attr.src_sha256,
executable=False
)
srcjar_attr ='\n srcjar = ":%s",' % src_name

build_file_contents = """
package(default_visibility = ['//visibility:public'])
java_import(
name = 'jar',
tags = ['maven_coordinates={artifact}'],
jars = ['{jar_name}'],{srcjar_attr}
)
filegroup(
name = 'file',
srcs = [
'{jar_name}',
'{src_name}'
],
visibility = ['//visibility:public']
)\n""".format(artifact = ctx.attr.artifact, jar_name = jar_name, src_name = src_name, srcjar_attr = srcjar_attr)
ctx.file(ctx.path("jar/BUILD"), build_file_contents, False)
return None

jar_artifact = repository_rule(
attrs = {
"artifact": attr.string(mandatory = True),
"sha256": attr.string(mandatory = True),
"urls": attr.string_list(mandatory = True),
"src_sha256": attr.string(mandatory = False, default=""),
"src_urls": attr.string_list(mandatory = False, default=[]),
},
implementation = _jar_artifact_impl
)

def jar_artifact_callback(hash):
src_urls = []
src_sha256 = ""
source=hash.get("source", None)
if source != None:
src_urls = [source["url"]]
src_sha256 = source["sha256"]
jar_artifact(
artifact = hash["artifact"],
name = hash["name"],
urls = [hash["url"]],
sha256 = hash["sha256"],
src_urls = src_urls,
src_sha256 = src_sha256
)
native.bind(name = hash["bind"], actual = hash["actual"])


def list_dependencies():
return [
{"artifact": "javax.inject:javax.inject:1", "lang": "java", "sha1": "6975da39a7040257bd51d21a231b76c915872d38", "sha256": "91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff", "repository": "https://repo.maven.apache.org/maven2/", "url": "https://repo.maven.apache.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar", "source": {"sha1": "a00123f261762a7c5e0ec916a2c7c8298d29c400", "sha256": "c4b87ee2911c139c3daf498a781967f1eb2e75bc1a8529a2e7b328a15d0e433e", "repository": "https://repo.maven.apache.org/maven2/", "url": "https://repo.maven.apache.org/maven2/javax/inject/javax.inject/1/javax.inject-1-sources.jar"} , "name": "javax_inject_javax_inject", "actual": "@javax_inject_javax_inject//jar", "bind": "jar/javax/inject/javax_inject"},
]

def maven_dependencies(callback = jar_artifact_callback):
for hash in list_dependencies():
callback(hash)
Loading

0 comments on commit 01fd799

Please sign in to comment.