Skip to content

Commit

Permalink
Add reformatter, fix google#73
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkprime committed Mar 1, 2016
1 parent a888289 commit 17c59ac
Show file tree
Hide file tree
Showing 136 changed files with 5,627 additions and 2,027 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ Makefile text
# These tests are explicitly given specific line endings
test_suite/unix_line_endings.jsonnet text eol=lf
test_suite/dos_line_endings.jsonnet text eol=crlf

8 changes: 6 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ genrule(
cc_library(
name = "jsonnet-common",
srcs = [
"core/desugaring.cpp",
"core/desugarer.cpp",
"core/formatter.cpp",
"core/lexer.cpp",
"core/parser.cpp",
"core/static_analysis.cpp",
"core/string_utils.cpp",
"core/vm.cpp",
"core/std.jsonnet.h",
],
hdrs = [
"core/ast.h",
"core/desugaring.h",
"core/desugarer.h",
"core/formatter.h",
"core/lexer.h",
"core/parser.h",
"core/state.h",
"core/static_analysis.h",
"core/static_error.h",
"core/string_utils.h",
"core/unicode.h",
"core/vm.h",
"include/libjsonnet.h",
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ SHARED_LDFLAGS ?= -shared
################################################################################

LIB_SRC = \
core/desugaring.cpp \
core/desugarer.cpp \
core/formatter.cpp \
core/lexer.cpp \
core/libjsonnet.cpp \
core/parser.cpp \
core/static_analysis.cpp \
core/string_utils.cpp \
core/vm.cpp
LIB_OBJ = $(LIB_SRC:.cpp=.o)

Expand All @@ -60,12 +62,14 @@ ALL = \
$(LIB_OBJ)
ALL_HEADERS = \
core/ast.h \
core/desugaring.h \
core/desugarer.h \
core/formatter.h \
core/lexer.h \
core/parser.h \
core/state.h \
core/static_analysis.h \
core/static_error.h \
core/string_utils.h \
core/vm.h \
core/std.jsonnet.h \
include/libjsonnet.h
Expand All @@ -82,7 +86,7 @@ test: jsonnet libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
cd examples ; ./check.sh
cd examples/terraform ; ./check.sh
cd test_suite ; ./run_tests.sh
cd test_suite ; ./run_unparse_tests.sh
cd test_suite ; ./run_fmt_tests.sh

MAKEDEPEND_SRCS = \
cmd/jsonnet.cpp \
Expand All @@ -92,7 +96,7 @@ MAKEDEPEND_SRCS = \
depend:
makedepend -f- $(LIB_SRC) $(MAKEDEPEND_SRCS) > Makefile.depend

core/desugaring.cpp: core/std.jsonnet.h
core/desugarer.cpp: core/std.jsonnet.h

# Object files
%.o: %.cpp
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench.01.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ local sum(x) =
if x == 0 then
0
else
x + sum(x-1);
x + sum(x - 1);
sum(300)
2 changes: 1 addition & 1 deletion benchmarks/bench.02.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
local Fib = {
n: 1,
local outer = self,
r: if self.n <= 1 then 1 else (Fib { n: outer.n - 1}).r + (Fib { n: outer.n - 2}).r
r: if self.n <= 1 then 1 else (Fib { n: outer.n - 1 }).r + (Fib { n: outer.n - 2 }).r,
};

(Fib { n: 25 }).r
50 changes: 25 additions & 25 deletions case_studies/fractal/service.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local credentials = import "credentials.jsonnet";
seed_provider: [
{
class_name: "org.apache.cassandra.locator.SimpleSeedProvider",
parameters: [ { seeds: std.join(", ", cassandraNodes) } ],
parameters: [{ seeds: std.join(", ", cassandraNodes) }],
},
],
},
Expand Down Expand Up @@ -100,17 +100,17 @@ local credentials = import "credentials.jsonnet";

// For debugging:
local network_debug = ["traceroute", "lsof", "iptraf", "tcpdump", "host", "dnsutils"],
aptPackages +: ["vim", "git", "psmisc", "screen", "strace" ] + network_debug,
aptPackages+: ["vim", "git", "psmisc", "screen", "strace"] + network_debug,
},

// Frontend image.
"appserv.packer.json": packer.GcpDebianNginxUwsgiFlaskImage + ImageMixin {
name: "appserv-v20150430-2145",
module: "main", // Entrypoint in the Python code.
pipPackages +: ["httplib2", "cassandra-driver", "blist"],
uwsgiConf +: { lazy: "true" }, // cassandra-driver does not survive fork()
module: "main", // Entrypoint in the Python code.
pipPackages+: ["httplib2", "cassandra-driver", "blist"],
uwsgiConf+: { lazy: "true" }, // cassandra-driver does not survive fork()
// Copy website content and code.
provisioners +: [
provisioners+: [
packer.File {
source: "appserv",
destination: "/tmp/",
Expand All @@ -134,12 +134,12 @@ local credentials = import "credentials.jsonnet";
name: "tilegen-v20150430-2145",
module: "mandelbrot_service",

aptPackages +: ["g++", "libpng-dev"],
aptPackages+: ["g++", "libpng-dev"],

port: tilegenPort,

// Copy the flask handlers and also build the C++ executable.
provisioners +: [
provisioners+: [
packer.File {
source: "tilegen",
destination: "/tmp/",
Expand Down Expand Up @@ -168,7 +168,7 @@ local credentials = import "credentials.jsonnet";
account_file: "service_account_key.json",
project: credentials.project,
region: "us-central1",
}
},
},

// The deployed resources.
Expand Down Expand Up @@ -213,12 +213,12 @@ local credentials = import "credentials.jsonnet";
appserv: {
name: "appserv",
health_checks: ["${google_compute_http_health_check.appserv.name}"],
instances: [ "%s/appserv%d" % [zone(k), k] for k in [1, 2, 3] ],
instances: ["%s/appserv%d" % [zone(k), k] for k in [1, 2, 3]],
},
tilegen: {
name: "tilegen",
health_checks: ["${google_compute_http_health_check.tilegen.name}"],
instances: [ "%s/tilegen%d" % [zone(k), k] for k in [1, 2, 3, 4, 5] ],
instances: ["%s/tilegen%d" % [zone(k), k] for k in [1, 2, 3, 4, 5]],
},
},

Expand All @@ -234,12 +234,12 @@ local credentials = import "credentials.jsonnet";
name: "tilegen",
target: "${google_compute_target_pool.tilegen.self_link}",
port_range: tilegenPort,
}
},
},

// Open ports for the various services, to instances (identified by tags)
google_compute_firewall: {
local NetworkMixin = { network: "${google_compute_network.fractal.name}", },
local NetworkMixin = { network: "${google_compute_network.fractal.name}" },
ssh: terraform.GcpFirewallSsh + NetworkMixin { name: "ssh" },
appserv: terraform.GcpFirewallHttp + NetworkMixin { name: "appserv" },
tilegen: terraform.GcpFirewallHttp + NetworkMixin { name: "tilegen", port: tilegenPort },
Expand All @@ -249,17 +249,17 @@ local credentials = import "credentials.jsonnet";

// All our instances share this configuration.
local FractalInstance(zone_hash) = terraform.GcpInstance {
network_interface: [super.network_interface[0] + {network: "${google_compute_network.fractal.name}"} ],
tags +: ["fractal"],
network_interface: [super.network_interface[0] { network: "${google_compute_network.fractal.name}" }],
tags+: ["fractal"],
zone: zone(zone_hash),
scopes +: ["devstorage.full_control"]
scopes+: ["devstorage.full_control"],
},

// The various kinds of Cassandra instances all share this basic configuration.
local CassandraInstance(zone_hash) = FractalInstance(zone_hash) {
image: "cassandra-v20150430-2145",
machine_type: "n1-standard-1",
tags +: ["fractal-db", "cassandra-server"],
tags+: ["fractal-db", "cassandra-server"],
user:: cassandraUser,
userPass:: credentials.cassandraUserPass,
rootPass:: credentials.cassandraRootPass,
Expand All @@ -279,8 +279,8 @@ local credentials = import "credentials.jsonnet";
database_user: cassandraUser,
database_pass: credentials.cassandraUserPass,
},
tags +: ["fractal-appserv", "http-server"],
startup_script +: [self.addFile(self.conf, "/var/www/conf.json")],
tags+: ["fractal-appserv", "http-server"],
startup_script+: [self.addFile(self.conf, "/var/www/conf.json")],
}
for k in [1, 2, 3]

Expand Down Expand Up @@ -326,8 +326,8 @@ local credentials = import "credentials.jsonnet";
["tilegen" + k]: FractalInstance(k) {
name: "tilegen" + k,
image: "tilegen-v20150430-2145",
tags +: ["fractal-tilegen", "http-server"],
startup_script +: [self.addFile(ApplicationConf, "/var/www/conf.json")],
tags+: ["fractal-tilegen", "http-server"],
startup_script+: [self.addFile(ApplicationConf, "/var/www/conf.json")],
}
for k in [1, 2, 3, 4]
},
Expand All @@ -337,7 +337,7 @@ local credentials = import "credentials.jsonnet";
name: "fractaldemo-com",
dns_name: credentials.dnsPrefix + "fractaldemo.com.",
description: "Fractal Demo DNS Zone",
}
},
},

local instances = self.google_compute_instance,
Expand Down Expand Up @@ -374,14 +374,14 @@ local credentials = import "credentials.jsonnet";
ttl: 300,
rrdatas: ["${google_compute_address.appserv.address}"],
},
}
},

},

output: {
"frontend": { value: "${google_compute_address.appserv.address}" },
frontend: { value: "${google_compute_address.appserv.address}" },
},

} // terraform.tf
}, // terraform.tf

}
48 changes: 24 additions & 24 deletions case_studies/kubernetes/example.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local Kube = import "libkube.jsonnet";
{

# The port that this service should serve on.
redis_port:: 6379,
redis_port:: 6379,
# Change this to your project ID.
project_id:: "cooltool-1009",

Expand All @@ -38,8 +38,8 @@ local Kube = import "libkube.jsonnet";
template: {
metadata: {
labels: {
name: "twitter-stream"
}
name: "twitter-stream",
},
},
spec: {
containers: [
Expand All @@ -55,11 +55,11 @@ local Kube = import "libkube.jsonnet";
ACCESSTOKENSEC: $.twitter_access_token_sec,
TWSTREAMMODE: "sample",
}),
}
]
}
}
}
},
],
},
},
},
},
"redis-master-service.new.yaml": Kube.v1.Service("redis-master") {
metadata+: {
Expand All @@ -72,12 +72,12 @@ local Kube = import "libkube.jsonnet";
# You don't need to specify the targetPort if it is the same as the port,
# though here we include it anyway, to show the syntax.
targetPort: $.redis_port,
}
},
],
selector: {
name: "redis-master",
}
}
},
},
},
"redis-master.new.yaml": Kube.v1.ReplicationController("redis-master") {
spec: {
Expand All @@ -86,7 +86,7 @@ local Kube = import "libkube.jsonnet";
metadata: {
labels: {
name: "redis-master",
}
},
},
spec: {
containers: [
Expand All @@ -103,11 +103,11 @@ local Kube = import "libkube.jsonnet";
name: "collectd",
image: "gcr.io/%s/collectd-redis:latest" % $.project_id,
ports: [],
}
]
}
}
}
},
],
},
},
},
},
"bigquery-controller.new.yaml": Kube.v1.ReplicationController("bigquery-controller") {
spec: {
Expand All @@ -116,7 +116,7 @@ local Kube = import "libkube.jsonnet";
metadata: {
labels: {
name: "bigquery-controller",
}
},
},
spec: {
containers: [
Expand All @@ -131,10 +131,10 @@ local Kube = import "libkube.jsonnet";
BQ_DATASET: $.bq_dataset,
BQ_TABLE: $.bq_table,
}),
}
]
}
}
}
}
},
],
},
},
},
},
}
4 changes: 2 additions & 2 deletions case_studies/kubernetes/libkube.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@

Service(name): ApiVersion + Metadata(name) {
kind: "Service",
}
},
},

pair_list_ex(tab, kfield, vfield)::
[{[kfield]: k, [vfield]: tab[k]} for k in std.objectFields(tab)],
[{ [kfield]: k, [vfield]: tab[k] } for k in std.objectFields(tab)],

pair_list(tab)::
self.pair_list_ex(tab, "name", "value"),
Expand Down
Loading

0 comments on commit 17c59ac

Please sign in to comment.