From cc930432c2823c3d82e0b8dd2ae4f446c82f4fce Mon Sep 17 00:00:00 2001 From: temporal Date: Mon, 21 Jul 2008 20:28:30 +0000 Subject: [PATCH] misc. stuff: - Improved readmes. - Fixed incorrect definition of kint32min. - Fixed absolute output paths on Windows. - Added info to Java POM that will be required when we upload the package to a Maven repo. --- README.txt | 26 ++++++- java/README.txt | 32 ++++++++- java/pom.xml | 22 +++++- python/README.txt | 12 ++++ .../compiler/command_line_interface.cc | 33 ++++++--- .../command_line_interface_unittest.cc | 71 ++++++++++++++++++- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/stubs/common_unittest.cc | 11 +++ vsprojects/readme.txt | 7 +- 9 files changed, 195 insertions(+), 21 deletions(-) diff --git a/README.txt b/README.txt index 75a429af45..717803672e 100644 --- a/README.txt +++ b/README.txt @@ -10,8 +10,8 @@ incompatible way in the future. It's unlikely that any big changes will be made, but we can make no promises. Expect a non-beta release sometime in August 2008. -C++ Installation -================ +C++ Installation - Unix +======================= To build and install the C++ Protocol Buffer runtime and the Protocol Buffer compiler (protoc) execute the following: @@ -27,7 +27,19 @@ Proceed at your own risk. "make install" may require superuser privileges. -For advanced usage information on configure and make, see INSTALL. +For advanced usage information on configure and make, see INSTALL.txt. + +** Hint on insall location ** + + By default, the package will be installed to /usr/local. However, + on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH. + You can add it, but it may be easier to just install to /usr + instead. To do this, invoke configure as follows: + + ./configure --prefix=/usr + + If you already built the package with a different prefix, make sure + to run "make clean" before building again. ** Note for Solaris users ** @@ -39,6 +51,14 @@ For advanced usage information on configure and make, see INSTALL. See src/solaris/libstdc++.la for more info on this bug. +C++ Installation - Windows +========================== + +If you are using Micosoft Visual C++, see vsprojects/readme.txt. + +If you are using Cygwin or MinGW, follow the Unix installation +instructions, above. + Java and Python Installation ============================ diff --git a/java/README.txt b/java/README.txt index 3bb69236d4..050bbfe7d0 100644 --- a/java/README.txt +++ b/java/README.txt @@ -3,8 +3,11 @@ Copyright 2008 Google Inc. This directory contains the Java Protocol Buffers runtime library. -Installation -============ +Installation - With Maven +========================= + +The Protocol Buffers build is managed using Maven. If you would +rather build without Maven, see the next section. 1) Install Apache Maven if you don't have it: @@ -37,6 +40,31 @@ Installation The .jar will be placed in the "target" directory. +Installation - Without Maven +============================ + +If you would rather not install Maven to build the library, you may +follow these instructions instead. Note that these instructions skip +running unit tests. + +1) Build the C++ code, or obtain a binary distribution of protoc. If + you install a binary distribution, make sure that it is the same + version as this package. If in doubt, run: + + $ protoc --version + + If you built the C++ code without installing, the compiler binary + should be located in ../src. + +2) Invoke protoc to build DescriptorProtos.java: + + $ protoc --java_out=src/main/java -I../src \ + ../src/google/protobuf/descriptor.proto + +3) Compile the code in src/main/java using whatever means you prefer. + +4) Install the classes wherever you prefer. + Usage ===== diff --git a/java/pom.xml b/java/pom.xml index 76b3235c05..1bb26b2ed5 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -14,10 +14,27 @@ com.google.protobuf protobuf-java 2.0.1-SNAPSHOT - Protocol Buffer Java API jar + Protocol Buffer Java API + + Protocol Buffers are a way of encoding structured data in an efficient yet + extensible format. + 2008 http://code.google.com/p/protobuf + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + http://code.google.com/p/protobuf/source/browse + + scm:svn:http://protobuf.googlecode.com/svn/trunk/ + + junit @@ -89,7 +106,8 @@ - + diff --git a/python/README.txt b/python/README.txt index 44bbee0b6b..4f68d506fd 100644 --- a/python/README.txt +++ b/python/README.txt @@ -3,6 +3,18 @@ Copyright 2008 Google Inc. This directory contains the Python Protocol Buffers runtime library. +Normally, this directory comes as part of the protobuf package, available +from: + + http://code.google.com/p/protobuf + +The complete package includes the C++ source code, which includes the +Protocol Compiler (protoc). If you downloaded this package from PyPI +or some other Python-specific source, you may have received only the +Python part of the code. In this case, you will need to obtain the +Protocol Compiler from some other source before you can use this +package. + Installation ============ diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 68e88a8e52..6c2c9e8f68 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -29,6 +29,7 @@ #endif #include #include +#include #include #include @@ -67,6 +68,20 @@ static const char* kPathSeparator = ";"; #else static const char* kPathSeparator = ":"; #endif + +// Returns true if the text looks like a Windows-style absolute path, starting +// with a drive letter. Example: "C:\foo". +static bool IsWindowsAbsolutePath(const string& text) { +#if defined(_WIN32) || defined(__CYGWIN__) + return text.size() >= 3 && text[1] == ':' && + isalpha(text[0]) && + (text[2] == '/' || text[2] == '\\') && + text.find_last_of(':') == 1; +#else + return false; +#endif +} + } // namespace // A MultiFileErrorCollector that prints errors to stderr. @@ -502,18 +517,14 @@ bool CommandLineInterface::InterpretArgument(const string& name, directive.generator = iter->second.generator; // Split value at ':' to separate the generator parameter from the - // filename. - vector parts; - SplitStringUsing(value, ":", &parts); - - if (parts.size() == 1) { - directive.output_location = parts[0]; - } else if (parts.size() == 2) { - directive.parameter = parts[0]; - directive.output_location = parts[1]; + // filename. However, avoid doing this if the colon is part of a valid + // Windows-style absolute path. + string::size_type colon_pos = value.find_first_of(':'); + if (colon_pos == string::npos || IsWindowsAbsolutePath(value)) { + directive.output_location = value; } else { - cerr << "Invalid value for flag " << name << "." << endl; - return false; + directive.parameter = value.substr(0, colon_pos); + directive.output_location = value.substr(colon_pos + 1); } output_directives_.push_back(directive); diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 1b1458de59..09644466df 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -51,6 +51,7 @@ class CommandLineInterfaceTest : public testing::Test { // Methods to set up the test (called before Run()). class MockCodeGenerator; + class NullCodeGenerator; // Registers a MockCodeGenerator with the given name. MockCodeGenerator* RegisterGenerator(const string& generator_name, @@ -63,6 +64,10 @@ class CommandLineInterfaceTest : public testing::Test { const string& filename, const string& help_text); + // Registers a CodeGenerator which will not actually generate anything, + // but records the parameter passed to the generator. + NullCodeGenerator* RegisterNullGenerator(const string& flag_name); + // Create a temp file within temp_directory_ with the given name. // The containing directory is also created if necessary. void CreateTempFile(const string& name, const string& contents); @@ -122,7 +127,7 @@ class CommandLineInterfaceTest : public testing::Test { string error_text_; // Pointers which need to be deleted later. - vector mock_generators_to_delete_; + vector mock_generators_to_delete_; }; // A mock CodeGenerator which outputs information about the context in which @@ -159,6 +164,25 @@ class CommandLineInterfaceTest::MockCodeGenerator : public CodeGenerator { bool expect_write_error_; }; +class CommandLineInterfaceTest::NullCodeGenerator : public CodeGenerator { + public: + NullCodeGenerator() : called_(false) {} + ~NullCodeGenerator() {} + + mutable bool called_; + mutable string parameter_; + + // implements CodeGenerator ---------------------------------------- + bool Generate(const FileDescriptor* file, + const string& parameter, + OutputDirectory* output_directory, + string* error) const { + called_ = true; + parameter_ = parameter; + return true; + } +}; + // =================================================================== void CommandLineInterfaceTest::SetUp() { @@ -239,6 +263,15 @@ CommandLineInterfaceTest::RegisterErrorGenerator( return generator; } +CommandLineInterfaceTest::NullCodeGenerator* +CommandLineInterfaceTest::RegisterNullGenerator( + const string& flag_name) { + NullCodeGenerator* generator = new NullCodeGenerator; + mock_generators_to_delete_.push_back(generator); + cli_.RegisterGenerator(flag_name, generator, ""); + return generator; +} + void CommandLineInterfaceTest::CreateTempFile( const string& name, const string& contents) { @@ -424,6 +457,42 @@ TEST_F(CommandLineInterfaceTest, GeneratorParameters) { "foo.proto", "Foo", "output.test"); } +#if defined(_WIN32) || defined(__CYGWIN__) + +TEST_F(CommandLineInterfaceTest, WindowsOutputPath) { + // Test that the output path can be a Windows-style path. + + NullCodeGenerator* generator = RegisterNullGenerator("--test_out"); + + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n"); + + Run("protocol_compiler --test_out=C:\\ " + "--proto_path=$tmpdir foo.proto"); + + ExpectNoErrors(); + EXPECT_TRUE(generator->called_); + EXPECT_EQ("", generator->parameter_); +} + +TEST_F(CommandLineInterfaceTest, WindowsOutputPathAndParameter) { + // Test that we can have a windows-style output path and a parameter. + + NullCodeGenerator* generator = RegisterNullGenerator("--test_out"); + + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n"); + + Run("protocol_compiler --test_out=bar:C:\\ " + "--proto_path=$tmpdir foo.proto"); + + ExpectNoErrors(); + EXPECT_TRUE(generator->called_); + EXPECT_EQ("bar", generator->parameter_); +} + +#endif // defined(_WIN32) || defined(__CYGWIN__) + TEST_F(CommandLineInterfaceTest, PathLookup) { // Test that specifying multiple directories in the proto search path works. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 03b176a31d..f0d55b534f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -147,7 +147,7 @@ typedef uint64_t uint64; #endif static const int32 kint32max = 0x7FFFFFFF; -static const int32 kint32min = -kint32min - 1; +static const int32 kint32min = -kint32max - 1; static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF); static const int64 kint64min = -kint64max - 1; static const uint32 kuint32max = 0xFFFFFFFFu; diff --git a/src/google/protobuf/stubs/common_unittest.cc b/src/google/protobuf/stubs/common_unittest.cc index f12422be06..c339c5fd18 100644 --- a/src/google/protobuf/stubs/common_unittest.cc +++ b/src/google/protobuf/stubs/common_unittest.cc @@ -50,6 +50,17 @@ TEST(VersionTest, VersionMatchesConfig) { #endif // PACKAGE_VERSION +TEST(CommonTest, IntMinMaxConstants) { + // kint32min was declared incorrectly in the first release of protobufs. + // Ugh. + EXPECT_LT(kint32min, kint32max); + EXPECT_EQ(static_cast(kint32min), static_cast(kint32max) + 1); + EXPECT_LT(kint64min, kint64max); + EXPECT_EQ(static_cast(kint64min), static_cast(kint64max) + 1); + EXPECT_EQ(0, kuint32max + 1); + EXPECT_EQ(0, kuint64max + 1); +} + vector captured_messages_; void CaptureLog(LogLevel level, const char* filename, int line, diff --git a/vsprojects/readme.txt b/vsprojects/readme.txt index 7f7278e087..b79f6006d7 100644 --- a/vsprojects/readme.txt +++ b/vsprojects/readme.txt @@ -7,7 +7,7 @@ Compiling and Installing ======================== 1) Open protobuf.sln in Microsoft Visual Studio. -2) Choose "Debug" or "Release" configuration as desired. +2) Choose "Debug" or "Release" configuration as desired.* 3) From the Build menu, choose "Build Solution". Wait for compiling to finish. 4) From a command shell, run tests.exe and check that all tests pass. 5) Run extract_includes.bat to copy all the public headers into a separate @@ -19,6 +19,11 @@ Compiling and Installing 8) Copy libprotobuf.{lib,dll} and libprotoc.{lib,dll} wherever you put libraries. +* To avoid conflicts between the MSVC debug and release runtime libraries, when + compiling a debug build of your application, you must link against a debug + build of libprotobuf.dll. Similarly, release builds must link against + release DLLs. + DLLs and Distribution =====================