Skip to content

Commit e77ea61

Browse files
committed
Commit generated code to avoid development sluggishness
Instead of running build.rs on every save, this should make development nicer
1 parent 89977d5 commit e77ea61

16 files changed

+11028
-531
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ prost = "0.12.1"
5151
[build-dependencies]
5252
prost-build = "0.12.1"
5353

54+
[features]
55+
generate = []

build.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ extern crate prost_build;
33
use std::io::Result;
44

55
fn main() -> Result<()> {
6+
if cfg!(feature = "generate") {
7+
generate_protobuf_code()?
8+
}
9+
Ok(())
10+
}
11+
12+
fn generate_protobuf_code() -> Result<()> {
613
let mut prost_build = prost_build::Config::new();
714

815
prost_build.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]");
916
prost_build.type_attribute(".", "#[serde(rename_all = \"camelCase\")]");
1017

11-
prost_build.include_file("_includes.rs");
18+
prost_build.out_dir("src/protobuf_gen");
19+
20+
prost_build.include_file("protobufs.rs");
1221

1322
prost_build.compile_protos(
1423
&[

reproto.sh

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77
rm -rf "$SCRIPT_DIR/src/protobuf"
88
mkdir -p "$SCRIPT_DIR/src/protobuf"
99

10-
OPENSHIFT_API_DIR="${OPENSHIFT_API_DIR:-"$SCRIPT_DIR/../api"}"
10+
OPENSHIFT_API_DIR=${OPENSHIFT_API_DIR:-"$SCRIPT_DIR/../api"}
1111

12-
pushd OPENSHIFT_API_DIR >/dev/null
13-
find k8s.io -name 'generated.proto' -exec cp --parents {} ~/repos/recert/src/protobuf ';'
12+
pushd "${OPENSHIFT_API_DIR}/vendor" >/dev/null
13+
find k8s.io -name 'generated.proto' -exec cp --parents {} "$SCRIPT_DIR"/src/protobuf ';'
14+
popd
1415

16+
pushd "${OPENSHIFT_API_DIR}" >/dev/null
1517
for dir in */; do
1618
if ! [[ "$dir" == "vendor/" || "$dir" == "tests/" || "$dir" == "tools/" ]]; then
17-
find "$dir" -name 'generated.proto' -exec cp --parents {} ~/repos/recert/src/protobuf ';'
19+
find "$dir" -name 'generated.proto' -exec cp --parents {} "$SCRIPT_DIR"/src/protobuf ';'
1820
fi
1921
done
20-
2122
popd >/dev/null
23+
24+
pushd "$SCRIPT_DIR"
25+
cargo build --release --features generate
26+
popd
27+
28+
29+

src/etcd_encoding.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
use self::k8s_etcd_protobuf::k8s::io::apimachinery::pkg::runtime::TypeMeta;
2-
use anyhow::{bail, Context, Result};
3-
use k8s_etcd_protobuf::github::com::openshift::api::route::v1::Route;
4-
use k8s_etcd_protobuf::k8s::io::{
5-
api::{
6-
admissionregistration::v1::{MutatingWebhookConfiguration, ValidatingWebhookConfiguration},
7-
apps::v1::{DaemonSet, Deployment},
8-
core::v1::{ConfigMap, Secret},
1+
use super::protobuf_gen::{
2+
github::com::openshift::api::route::v1::Route,
3+
k8s::io::{
4+
api::{
5+
admissionregistration::v1::{MutatingWebhookConfiguration, ValidatingWebhookConfiguration},
6+
apps::v1::{DaemonSet, Deployment},
7+
core::v1::{ConfigMap, Secret},
8+
},
9+
apimachinery::pkg::runtime::{TypeMeta, Unknown},
910
},
10-
apimachinery::pkg::runtime::Unknown,
1111
};
12+
use anyhow::{bail, Context, Result};
1213
use prost::Message;
1314
use serde_json::Value;
1415

15-
mod k8s_etcd_protobuf {
16-
#![allow(clippy::all)]
17-
include!(concat!(env!("OUT_DIR"), "/_includes.rs"));
18-
}
19-
2016
macro_rules! k8s_type {
2117
($name:ident, $type:ident) => {
2218
#[derive(serde::Serialize, serde::Deserialize)]

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod file_utils;
1818
mod json_tools;
1919
mod k8s_etcd;
2020
mod ocp_postprocess;
21+
mod protobuf_gen;
2122
mod rsa_key_pool;
2223
mod rules;
2324
mod runtime;

0 commit comments

Comments
 (0)