Skip to content

Commit

Permalink
Add protogen make target
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Nov 7, 2015
1 parent e59a821 commit 9929d75
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
3 changes: 3 additions & 0 deletions build/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test: integration-test
fmt:
gofmt -s -w .

protogen:
$(PROJDIR)/build/protogen $(PROJDIR)

help:
@echo ''
@echo ' Targets:'
Expand Down
42 changes: 42 additions & 0 deletions build/protogen
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

if ! hash protoc 2>&1 >/dev/null
then
echo "protoc command must be in PATH."
exit 1
fi

declare -r projdir="${1:-unknown_projdir}"
if [[ ! -d $projdir ]]
then
echo "First argument must be project directory." 2>&1
exit 1
fi

declare -r rpb_path="$projdir/rpb"
declare -r proto_path="$projdir/riak_pb/src"
if [[ ! -d $proto_path ]]
then
echo "Could not find $proto_path." 2>&1
exit 1
fi

for proto_file in $proto_path/*.proto
do
proto_file_basename="$(basename -s '.proto' $proto_file)"
rpb_path_tmp="$rpb_path/$proto_file_basename"

protoc --go_out="$rpb_path_tmp" --proto_path="$proto_path" "$proto_file"

rpb_file="$rpb_path_tmp/$proto_file_basename.pb.go"

sed -i 's/^import proto.*/import proto "github.com\/golang\/protobuf\/proto"/g' "$rpb_file"

if [[ $proto_file_basename == 'riak_search' || $proto_file_basename == 'riak_kv' ]]
then
sed -i 's/^import riak.*/import riak "github.com\/basho\/riak-go-client\/rpb\/riak"/g' "$rpb_file"
fi
done
6 changes: 3 additions & 3 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function Do-ProtoGen {
$proto_path = Join-Path -Path $script_path -ChildPath (Join-Path -Path 'riak_pb' -ChildPath 'src')
$proto_wild = Join-Path -Path $proto_path -ChildPath '*.proto'
Get-ChildItem $proto_wild | ForEach-Object {
$rpb_path_tmp = Join-Path -Path $rpb_path -ChildPath $_.BaseName
$proto_file_basename = $_.BaseName
$rpb_path_tmp = Join-Path -Path $rpb_path -ChildPath $proto_file_basename
If (!(Test-Path $rpb_path_tmp)) {
New-Item $rpb_path_tmp -Type Directory -Force
}
Expand All @@ -80,8 +81,7 @@ function Do-ProtoGen {
throw "protoc.exe failed: $LastExitCode"
}

$base_name = $_.BaseName
$rpb_file = Join-Path -Path $rpb_path_tmp -ChildPath "$base_name.pb.go"
$rpb_file = Join-Path -Path $rpb_path_tmp -ChildPath "$proto_file_basename.pb.go"
Write-Verbose "post-processing $rpb_file"

(Get-Content $rpb_file) |
Expand Down

0 comments on commit 9929d75

Please sign in to comment.