Skip to content

Commit

Permalink
feat(cxx_common): use a more compact serialization and in-memory form…
Browse files Browse the repository at this point in the history
…at for selection (#5652)
  • Loading branch information
shahms committed May 23, 2023
1 parent b7e9f65 commit 2b14f98
Show file tree
Hide file tree
Showing 8 changed files with 1,080 additions and 114 deletions.
8 changes: 4 additions & 4 deletions external.bzl
Expand Up @@ -197,11 +197,11 @@ def _cc_dependencies():
maybe(
http_archive,
name = "com_google_googletest",
sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2",
strip_prefix = "googletest-release-1.12.1",
sha256 = "ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363",
strip_prefix = "googletest-1.13.0",
urls = [
"https://mirror.bazel.build/github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz",
"https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz",
"https://mirror.bazel.build/github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz",
"https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz",
],
)

Expand Down
9 changes: 9 additions & 0 deletions kythe/cxx/extractor/BUILD
Expand Up @@ -332,6 +332,9 @@ cc_test(
cc_library(
name = "bazel_artifact",
hdrs = ["bazel_artifact.h"],
deps = [
"@com_google_absl//absl/strings:str_format",
],
)

cc_library(
Expand All @@ -345,10 +348,13 @@ cc_library(
":bazel_artifact",
"//kythe/cxx/common:regex",
"//kythe/proto:bazel_artifact_selector_cc_proto",
"//kythe/proto:bazel_artifact_selector_v2_cc_proto",
"@build_event_stream_proto//:build_event_stream_cc_proto",
"@com_github_google_glog//:glog",
"@com_google_absl//absl/base",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/container:inlined_vector",
"@com_google_absl//absl/container:node_hash_map",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/status",
Expand All @@ -373,6 +379,9 @@ cc_test(
"//third_party:gtest_main",
"@build_event_stream_proto//:build_event_stream_cc_proto",
"@com_github_google_glog//:glog",
"@com_github_inazarenko_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
Expand Down
32 changes: 32 additions & 0 deletions kythe/cxx/extractor/bazel_artifact.h
Expand Up @@ -17,10 +17,15 @@
#ifndef KYTHE_CXX_EXTRACTOR_BAZEL_ARTIFACT_H_
#define KYTHE_CXX_EXTRACTOR_BAZEL_ARTIFACT_H_

#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"

namespace kythe {

/// \brief A pair of local path and canonical URI for a given Bazel output file.
Expand All @@ -43,6 +48,17 @@ struct BazelArtifactFile {
friend H AbslHashValue(H h, const BazelArtifactFile& file) {
return H::combine(std::move(h), file.local_path, file.uri);
}

template <typename Sink>
friend void AbslStringify(Sink& sink, const BazelArtifactFile& file) {
absl::Format(&sink, "BazelArtifactFile{.local_path = %v, .uri = %v}",
absl::FormatStreamed(std::quoted(file.local_path)),
absl::FormatStreamed(std::quoted(file.uri)));
}
friend std::ostream& operator<<(std::ostream& out,
const BazelArtifactFile& file) {
return (out << absl::StreamFormat("%v", file));
}
};

/// \brief A list of extracted compilation units and the target which owns them.
Expand All @@ -58,6 +74,22 @@ struct BazelArtifact {
bool operator!=(const BazelArtifact& other) const {
return !(*this == other);
}

template <typename H>
friend H AbslHashValue(H h, const BazelArtifact& artifact) {
return H::combine(std::move(h), artifact.label, artifact.files);
}

template <typename Sink>
friend void AbslStringify(Sink& sink, const BazelArtifact& artifact) {
absl::Format(&sink, "BazelArtifact{.label = %v, .files = { %s }}",
absl::FormatStreamed(std::quoted(artifact.label)),
absl::StrJoin(artifact.files, ", "));
}
friend std::ostream& operator<<(std::ostream& out,
const BazelArtifact& artifact) {
return (out << absl::StreamFormat("%v", artifact));
}
};

} // namespace kythe
Expand Down

0 comments on commit 2b14f98

Please sign in to comment.