Skip to content

Commit

Permalink
Fix gencopy path for external protos
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Jul 21, 2024
1 parent f0507a6 commit b521f07
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
17 changes: 11 additions & 6 deletions cmd/gencopy/gencopy.bash.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ CONFIG_SHORT_PATH=@@CONFIG_SHORT_PATH@@

# env
# set -x
# echo "PWD: $PWD"
# find .
# find ..

# Get the directory of the current script (part of the runfiles tree)
script_dir=$(dirname "$0")

# find_runfile prints the location of a runfile in the source workspace,
# either by reading the symbolic link or reading the runfiles manifest.
Expand Down Expand Up @@ -45,18 +50,18 @@ fi
# Note that we don't change directories first; if we did, Generator wouldn't be
# able to find runfiles, and some extensions rely on that. Generator can use
# BUILD_WORKSPACE_DIRECTORY to interpret relative paths on the command line.
GENCOPY_short_path=$(find_runfile "$GENCOPY_SHORT_PATH")
if [ -z "$GENCOPY_short_path" ]; then
GENCOPY_path=$(find_runfile "$GENCOPY_SHORT_PATH")
if [ -z "$GENCOPY_path" ]; then
echo "error: could not locate gencopy binary" >&2
exit 1
fi

CONFIG_short_path=$(find_runfile "$CONFIG_SHORT_PATH")
if [ -z "$CONFIG_short_path" ]; then
CONFIG_path=$(find_runfile "$CONFIG_SHORT_PATH")
if [ -z "$CONFIG_path" ]; then
echo "error: could not locate gencopy configuration file" >&2
exit 1
fi

"$GENCOPY_short_path" \
-config="$CONFIG_short_path" \
"$GENCOPY_path" \
-config="$CONFIG_path" \
-workspace_root_directory="${BUILD_WORKSPACE_DIRECTORY:-""}"
2 changes: 1 addition & 1 deletion cmd/gencopy/gencopy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def gencopy_config(ctx):
)

def gencopy_action(ctx, config, runfiles):
"""gencopy_action declared a bazel action that runs the gencopy.bash script.
"""gencopy_action declares a bazel action that runs the gencopy.bash script.
Args:
ctx: the context object.
Expand Down
2 changes: 0 additions & 2 deletions cmd/gencopy/gencopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"path/filepath"
"strconv"
"strings"

"github.com/google/go-cmp/cmp"
)
Expand Down Expand Up @@ -174,7 +173,6 @@ func makePkgSrcDstPairs(cfg *Config, pkg *PackageConfig) []*SrcDst {

func makePkgSrcDstPair(cfg *Config, pkg *PackageConfig, src, dst string) *SrcDst {
if pkg.TargetWorkspaceRoot != "" {
src = filepath.Join("external", strings.TrimPrefix(src, ".."))
dst = filepath.Join(pkg.TargetWorkspaceRoot, dst)
}
dst = filepath.Join(cfg.WorkspaceRootDirectory, dst)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gencopy/gencopy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestMakePkgSrcDstPair(t *testing.T) {
pkg: PackageConfig{TargetWorkspaceRoot: "external/foo"},
src: "../foo/file.txt",
dst: "file.txt",
want: SrcDst{Src: "external/foo/file.txt", Dst: "/home/external/foo/file.txt"},
want: SrcDst{Src: "../foo/file.txt", Dst: "/home/external/foo/file.txt"},
},
} {
t.Run(name, func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/protoc/proto_compiled_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (s *protoCompiledSources) LoadInfo() rule.LoadInfo {

// ProvideRule implements part of the LanguageRule interface.
func (s *protoCompiledSources) ProvideRule(cfg *LanguageRuleConfig, config *ProtocConfiguration) RuleProvider {
if len(config.Outputs) == 0 {
return nil
}
return &protoCompileRule{
kind: "proto_compiled_sources",
nameSuffix: "compiled_sources",
Expand Down
1 change: 1 addition & 0 deletions rules/private/proto_repository_tools_srcs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ PROTO_REPOSITORY_TOOLS_SRCS = [
"@build_stack_rules_proto//plugin/grpc/grpc-web:BUILD.bazel",
"@build_stack_rules_proto//plugin/grpc-ecosystem/grpc-gateway:BUILD.bazel",
"@build_stack_rules_proto//plugin/scalapb/scalapb:BUILD.bazel",
"@build_stack_rules_proto//plugin/scalapb/zio-grpc:BUILD.bazel",
"@build_stack_rules_proto//plugin/stackb/grpc_js:BUILD.bazel",
"@build_stack_rules_proto//plugin/stephenh/ts-proto:BUILD.bazel",
"@build_stack_rules_proto//rules:BUILD.bazel",
Expand Down

0 comments on commit b521f07

Please sign in to comment.