aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD7
-rw-r--r--compiler_config_setting.bzl21
-rw-r--r--csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs55
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs1
-rw-r--r--java/pom.xml2
-rwxr-xr-xpython/setup.py8
-rw-r--r--src/google/protobuf/compiler/subprocess.cc9
7 files changed, 75 insertions, 28 deletions
diff --git a/BUILD b/BUILD
index 25c41a42..58d7a82b 100644
--- a/BUILD
+++ b/BUILD
@@ -52,10 +52,9 @@ COPTS = select({
],
})
-config_setting(
- name = "msvc",
- values = { "compiler": "msvc-cl" },
-)
+load(":compiler_config_setting.bzl", "create_compiler_config_setting")
+
+create_compiler_config_setting(name = "msvc", value = "msvc-cl")
config_setting(
name = "android",
diff --git a/compiler_config_setting.bzl b/compiler_config_setting.bzl
new file mode 100644
index 00000000..5e52a652
--- /dev/null
+++ b/compiler_config_setting.bzl
@@ -0,0 +1,21 @@
+"""Creates config_setting that allows selecting based on 'compiler' value."""
+
+def create_compiler_config_setting(name, value):
+ # The "do_not_use_tools_cpp_compiler_present" attribute exists to
+ # distinguish between older versions of Bazel that do not support
+ # "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
+ # In the future, the only way to select on the compiler will be through
+ # flag_values{"@bazel_tools//tools/cpp:compiler"} and the else branch can
+ # be removed.
+ if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"):
+ native.config_setting(
+ name = name,
+ flag_values = {
+ "@bazel_tools//tools/cpp:compiler": value,
+ },
+ )
+ else:
+ native.config_setting(
+ name = name,
+ values = {"compiler": value},
+ )
diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
index 9abee951..586ab47a 100644
--- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
+++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
@@ -71,7 +71,6 @@ namespace Google.Protobuf.Reflection
private void TestFileDescriptor(FileDescriptor file, FileDescriptor importedFile, FileDescriptor importedPublicFile)
{
-
Assert.AreEqual("unittest_proto3.proto", file.Name);
Assert.AreEqual("protobuf_unittest3", file.Package);
@@ -214,29 +213,61 @@ namespace Google.Protobuf.Reflection
}
[Test]
- public void FieldDescriptor()
+ public void FieldDescriptor_GeneratedCode()
{
- MessageDescriptor messageType = TestAllTypes.Descriptor;
- FieldDescriptor primitiveField = messageType.FindDescriptor<FieldDescriptor>("single_int32");
- FieldDescriptor enumField = messageType.FindDescriptor<FieldDescriptor>("single_nested_enum");
- FieldDescriptor messageField = messageType.FindDescriptor<FieldDescriptor>("single_foreign_message");
+ TestFieldDescriptor(UnittestProto3Reflection.Descriptor, TestAllTypes.Descriptor, ForeignMessage.Descriptor, ImportMessage.Descriptor);
+ }
+
+ [Test]
+ public void FieldDescriptor_BuildFromByteStrings()
+ {
+ // The descriptors have to be supplied in an order such that all the
+ // dependencies come before the descriptors depending on them.
+ var descriptorData = new List<ByteString>
+ {
+ UnittestImportPublicProto3Reflection.Descriptor.Proto.ToByteString(),
+ UnittestImportProto3Reflection.Descriptor.Proto.ToByteString(),
+ UnittestProto3Reflection.Descriptor.Proto.ToByteString()
+ };
+ var converted = FileDescriptor.BuildFromByteStrings(descriptorData);
+ TestFieldDescriptor(
+ converted[2],
+ converted[2].FindTypeByName<MessageDescriptor>("TestAllTypes"),
+ converted[2].FindTypeByName<MessageDescriptor>("ForeignMessage"),
+ converted[1].FindTypeByName<MessageDescriptor>("ImportMessage"));
+ }
+
+ public void TestFieldDescriptor(
+ FileDescriptor unitTestProto3Descriptor,
+ MessageDescriptor testAllTypesDescriptor,
+ MessageDescriptor foreignMessageDescriptor,
+ MessageDescriptor importMessageDescriptor)
+ {
+ FieldDescriptor primitiveField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_int32");
+ FieldDescriptor enumField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_nested_enum");
+ FieldDescriptor foreignMessageField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_foreign_message");
+ FieldDescriptor importMessageField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_import_message");
Assert.AreEqual("single_int32", primitiveField.Name);
Assert.AreEqual("protobuf_unittest3.TestAllTypes.single_int32",
primitiveField.FullName);
Assert.AreEqual(1, primitiveField.FieldNumber);
- Assert.AreEqual(messageType, primitiveField.ContainingType);
- Assert.AreEqual(UnittestProto3Reflection.Descriptor, primitiveField.File);
+ Assert.AreEqual(testAllTypesDescriptor, primitiveField.ContainingType);
+ Assert.AreEqual(unitTestProto3Descriptor, primitiveField.File);
Assert.AreEqual(FieldType.Int32, primitiveField.FieldType);
Assert.IsNull(primitiveField.Proto.Options);
Assert.AreEqual("single_nested_enum", enumField.Name);
Assert.AreEqual(FieldType.Enum, enumField.FieldType);
- Assert.AreEqual(messageType.EnumTypes[0], enumField.EnumType);
+ Assert.AreEqual(testAllTypesDescriptor.EnumTypes[0], enumField.EnumType);
+
+ Assert.AreEqual("single_foreign_message", foreignMessageField.Name);
+ Assert.AreEqual(FieldType.Message, foreignMessageField.FieldType);
+ Assert.AreEqual(foreignMessageDescriptor, foreignMessageField.MessageType);
- Assert.AreEqual("single_foreign_message", messageField.Name);
- Assert.AreEqual(FieldType.Message, messageField.FieldType);
- Assert.AreEqual(ForeignMessage.Descriptor, messageField.MessageType);
+ Assert.AreEqual("single_import_message", importMessageField.Name);
+ Assert.AreEqual(FieldType.Message, importMessageField.FieldType);
+ Assert.AreEqual(importMessageDescriptor, importMessageField.MessageType);
}
[Test]
diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
index 799f7291..216e03cc 100644
--- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -344,6 +344,7 @@ namespace Google.Protobuf.Reflection
FileDescriptor descriptor = new FileDescriptor(
data, proto, dependencies, pool,
allowUnknownDependencies: false, generatedCodeInfo: null);
+ descriptor.CrossLink();
descriptors.Add(descriptor);
if (descriptorsByName.ContainsKey(descriptor.Name))
{
diff --git a/java/pom.xml b/java/pom.xml
index bc71fdc9..e8008f45 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -82,7 +82,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
- <version>19.0</version>
+ <version>20.0</version>
</dependency>
</dependencies>
</dependencyManagement>
diff --git a/python/setup.py b/python/setup.py
index 9a02a246..c2769d04 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -11,14 +11,8 @@ import platform
# namespace_packages option for the "google" package.
from setuptools import setup, Extension, find_packages
+from distutils.command.build_py import build_py as _build_py
from distutils.command.clean import clean as _clean
-
-if sys.version_info[0] == 3:
- # Python 3
- from distutils.command.build_py import build_py_2to3 as _build_py
-else:
- # Python 2
- from distutils.command.build_py import build_py as _build_py
from distutils.spawn import find_executable
# Find the Protocol Compiler.
diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc
index 2e5a89ac..5bd3d435 100644
--- a/src/google/protobuf/compiler/subprocess.cc
+++ b/src/google/protobuf/compiler/subprocess.cc
@@ -124,14 +124,15 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
<< Win32ErrorMessage(GetLastError());
}
- // CreateProcess() mutates its second parameter. WTF?
- char* name_copy = portable_strdup(program.c_str());
+ // Invoking cmd.exe allows for '.bat' files from the path as well as '.exe'.
+ // Using a malloc'ed string because CreateProcess() can mutate its second parameter. (WTF).
+ char *command_line = portable_strdup(("cmd.exe /c \"" + program + "\"").c_str());
// Create the process.
PROCESS_INFORMATION process_info;
if (CreateProcessA((search_mode == SEARCH_PATH) ? NULL : program.c_str(),
- (search_mode == SEARCH_PATH) ? name_copy : NULL,
+ (search_mode == SEARCH_PATH) ? command_line : NULL,
NULL, // process security attributes
NULL, // thread security attributes
TRUE, // inherit handles?
@@ -152,7 +153,7 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
CloseHandleOrDie(stdin_pipe_read);
CloseHandleOrDie(stdout_pipe_write);
- free(name_copy);
+ free(command_line);
}
bool Subprocess::Communicate(const Message& input, Message* output,