Skip to content

Commit

Permalink
Add Jsonnet rules to Bazel.
Browse files Browse the repository at this point in the history
RELNOTES: Add Jsonnet rules to Bazel

--
MOS_MIGRATED_REVID=102895524
  • Loading branch information
davidzchen authored and kchodorow committed Sep 14, 2015
1 parent 2ad1c81 commit 361d2e2
Show file tree
Hide file tree
Showing 13 changed files with 797 additions and 7 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,10 @@ new_http_archive(
sha256 = "aa76bb83c38b3f7495516eb08977fc9700c664d7a945ba3ac3c0004a6a8509f2",
build_file = "tools/build_defs/d/dmd.BUILD",
)

new_git_repository(
name = "jsonnet",
remote = "https://github.com/google/jsonnet.git",
tag = "v0.8.0",
build_file = "tools/build_defs/jsonnet/jsonnet.BUILD",
)
41 changes: 41 additions & 0 deletions examples/jsonnet/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])

load("/tools/build_defs/jsonnet/jsonnet", "jsonnet_library", "jsonnet_to_json")

jsonnet_library(
name = "workflow",
srcs = ["workflow.jsonnet"],
)

jsonnet_to_json(
name = "wordcount",
src = "wordcount.jsonnet",
outs = ["wordcount.json"],
deps = [":workflow"],
)

jsonnet_to_json(
name = "intersection",
src = "intersection.jsonnet",
outs = ["intersection.json"],
deps = [":workflow"],
)

jsonnet_library(
name = "shell-workflows-lib",
srcs = [
"intersection.jsonnet",
"wordcount.jsonnet",
],
deps = [":workflow"],
)

jsonnet_to_json(
name = "shell-workflows",
src = "shell-workflows.jsonnet",
outs = [
"intersection-workflow.json",
"wordcount-workflow.json",
],
deps = [":shell-workflows-lib"],
)
60 changes: 60 additions & 0 deletions examples/jsonnet/intersection.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2015 Google Inc. 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.

local workflow = import "examples/jsonnet/workflow.jsonnet";

// Workflow that performs an intersection of two files using shell commands.
{
intersection: workflow.Workflow {
jobs: {
local input_file1 = "/tmp/list1",
local input_file2 = "/tmp/list2",
local sorted_file1 = "/tmp/list1_sorted",
local sorted_file2 = "/tmp/list2_sorted",
local intersection = "/tmp/intersection",

SortJob:: workflow.ShJob {
input_file:: "",
output_file:: "",
command: "sort %s > %s" % [self.input_file, self.output_file],
inputs: [self.input_file],
outputs: [self.output_file],
},

sort_file1: self.SortJob {
input_file:: input_file1,
output_file:: sorted_file1,
},

sort_file2: self.SortJob {
input_file:: input_file2,
output_file:: sorted_file2,
},

intersect: workflow.ShJob {
deps: [
":sort_file1",
":sort_file2",
],
command: "comm -12 %s %s > %s" %
[sorted_file1, sorted_file2, intersection],
inputs: [
sorted_file1,
sorted_file2,
],
outputs: [intersection],
},
}
}
}
21 changes: 21 additions & 0 deletions examples/jsonnet/shell-workflows.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 Google Inc. 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.

local wordcount = import "examples/jsonnet/wordcount.jsonnet";
local intersection = import "examples/jsonnet/intersection.jsonnet";

{
"wordcount-workflow.json": wordcount,
"intersection-workflow.json": intersection,
}
59 changes: 59 additions & 0 deletions examples/jsonnet/wordcount.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2015 Google Inc. 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.

local workflow = import "examples/jsonnet/workflow.jsonnet";

// Workflow that performs a wordcount using shell commands.
{
wordcount: workflow.Workflow {
retries: 12,
schedule: workflow.Schedule {
start_date: "2015-11-15",
start_time: "17:30",
repeat_frequency: 1,
repeat_type: "week",
},
jobs: {
local input_file = "/tmp/passage_test",
local tokens_file = "/tmp/tokens",
local sorted_tokens_file = "/tmp/sorted_tokens",
local counts_file = "/tmp/counts",

// Reads the input file and produces an output file with one word per
// line.
tokenize: workflow.ShJob {
command: "tr ' ' '\n' < %s > %s" % [input_file, tokens_file],
inputs: [input_file],
outputs: [tokens_file],
},

// Takes the tokens file and produces a file with the tokens sorted.
sort: workflow.ShJob {
deps: [":tokenize"],
command: "sort %s > %s" % [tokens_file, sorted_tokens_file],
inputs: [tokens_file],
outputs: [sorted_tokens_file],
},

// Takes the file containing sorted tokens and produces a file containing
// the counts for each word.
count: workflow.ShJob {
deps: [":sort"],
command: "uniq -c %s > %s" % [sorted_tokens_file, counts_file],
inputs: [sorted_tokens_file],
outputs: [counts_file],
},
}
}
}
46 changes: 46 additions & 0 deletions examples/jsonnet/workflow.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2015 Google Inc. 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.

// Configuration for a hypothetical workflow scheduling system.
{
// Configuration for a workflow.
Workflow:: {
schedule: {},
retries: 5,
jobs: {},
},

// Scheduling configuration for a workflow.
Schedule:: {
start_date: "",
start_time: "",
repeat_frequency: 0,
repeat_type: "",
},

// Base configuration for a Job in a workflow.
Job:: {
type: "base",
deps: [],
inputs: [],
outputs: [],
},

// Configuration for a job that runs a shell command.
ShJob:: self.Job {
type: "sh",
command: "",
vars: {},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,30 @@ ${LEFT_PANEL}

<h4>Rules implemented as Skylark extensions</h4>

<p>
The Bazel team provides a set of supported build rules written using the
<a href="/docs/skylark/index.html">Skylark</a> rules framework. These rules
should be explicitly <a href="#load">load</a>ed. They allow you to build the
following:
</p>

<ul>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_rules/closure">
Closure libraries</a>
Closure libraries</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_defs/docker">
Docker images</a>
Docker images</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_defs/groovy">
Groovy projects</a>
Groovy projects</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_rules/appengine">
Java App Engine applications</a>
Java App Engine applications</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_defs/d">
D projects</a>
D projects</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_rules/rust">
Rust projects</a>
Rust projects</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_defs/jsonnet">
Jsonnet files</a></li>
<li> <a href="https://github.com/bazelbuild/bazel/tree/master/tools/build_defs/scala">
Scala projects</a> - experimental
Scala projects</a> - experimental</li>
</ul>

<h2 id="common-definitions">Common definitions</h2>
Expand Down
1 change: 1 addition & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ filegroup(
name = "package-srcs",
srcs = glob(["**"]) + [
"//tools/build_defs/d:srcs",
"//tools/build_defs/jsonnet:srcs",
"//tools/build_defs/docker:srcs",
"//tools/build_rules/appengine:srcs",
"//tools/build_rules/closure:srcs",
Expand Down
16 changes: 16 additions & 0 deletions tools/build_defs/jsonnet/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
)

filegroup(
name = "jsonnet",
srcs = ["@jsonnet//:jsonnet"],
)

filegroup(
name = "std",
srcs = ["@jsonnet//:std"],
)
Loading

0 comments on commit 361d2e2

Please sign in to comment.