Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
c58ce5dc
Commit
c58ce5dc
authored
Nov 03, 2010
by
Jon Skeet
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'csharptest/master'
parents
f18a5b09
e8e1dab0
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1399 additions
and
56 deletions
+1399
-56
.gitignore
.gitignore
+3
-0
ProtocolBuffers.build
ProtocolBuffers.build
+5
-5
csharp_options.proto
protos/google/protobuf/csharp_options.proto
+17
-0
ProtoGen.Test.csproj
src/ProtoGen.Test/ProtoGen.Test.csproj
+18
-0
TempFile.cs
src/ProtoGen.Test/TempFile.cs
+48
-0
TestPreprocessing.cs
src/ProtoGen.Test/TestPreprocessing.cs
+600
-0
DescriptorUtil.cs
src/ProtoGen/DescriptorUtil.cs
+15
-1
Generator.cs
src/ProtoGen/Generator.cs
+59
-11
GeneratorOptions.cs
src/ProtoGen/GeneratorOptions.cs
+185
-5
Program.cs
src/ProtoGen/Program.cs
+6
-3
ProgramPreprocess.cs
src/ProtoGen/ProgramPreprocess.cs
+150
-0
ProtoGen.csproj
src/ProtoGen/ProtoGen.csproj
+2
-0
ServiceGenerator.cs
src/ProtoGen/ServiceGenerator.cs
+1
-1
UmbrellaClassGenerator.cs
src/ProtoGen/UmbrellaClassGenerator.cs
+15
-2
ProtocolBuffers.sln
src/ProtocolBuffers.sln
+8
-0
CSharpOptions.cs
src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
+178
-8
FileDescriptor.cs
src/ProtocolBuffers/Descriptors/FileDescriptor.cs
+46
-16
todo.txt
todo.txt
+43
-4
No files found.
.gitignore
View file @
c58ce5dc
...
@@ -29,3 +29,5 @@ mono/TestResult.xml
...
@@ -29,3 +29,5 @@ mono/TestResult.xml
mono/.libs
mono/.libs
mono/*.exe
mono/*.exe
mono/*.dll
mono/*.dll
src/ProtocolBuffers/objCF
\ No newline at end of file
ProtocolBuffers.build
View file @
c58ce5dc
...
@@ -266,10 +266,10 @@
...
@@ -266,10 +266,10 @@
<property
name=
"Configuration"
value=
"Release"
/>
<property
name=
"Configuration"
value=
"Release"
/>
<property
name=
"Platform"
value=
"Any CPU"
/>
<property
name=
"Platform"
value=
"Any CPU"
/>
</msbuild>
</msbuild>
<msbuild
project=
"${src}/ProtocolBuffers.sln"
>
<
!--
msbuild project="${src}/ProtocolBuffers.sln">
<property name="Configuration" value="Silverlight2" />
<property name="Configuration" value="Silverlight2" />
<property name="Platform" value="Any CPU" />
<property name="Platform" value="Any CPU" />
</msbuild>
</msbuild
--
>
<!-- Note the deliberate lack of space in the platform name -->
<!-- Note the deliberate lack of space in the platform name -->
<msbuild
project=
"${src}/ProtocolBuffers/ProtocolBuffersCF.csproj"
>
<msbuild
project=
"${src}/ProtocolBuffers/ProtocolBuffersCF.csproj"
>
<property
name=
"Configuration"
value=
"Release"
/>
<property
name=
"Configuration"
value=
"Release"
/>
...
@@ -291,7 +291,7 @@
...
@@ -291,7 +291,7 @@
<mkdir
dir=
"${output-dir}/Protoc"
/>
<mkdir
dir=
"${output-dir}/Protoc"
/>
<mkdir
dir=
"${output-dir}/Debug"
/>
<mkdir
dir=
"${output-dir}/Debug"
/>
<mkdir
dir=
"${output-dir}/Release"
/>
<mkdir
dir=
"${output-dir}/Release"
/>
<
mkdir
dir=
"${output-dir}/Silverlight2"
/
>
<
!--mkdir dir="${output-dir}/Silverlight2" /--
>
<mkdir
dir=
"${output-dir}/CompactFramework35"
/>
<mkdir
dir=
"${output-dir}/CompactFramework35"
/>
<copy
todir=
"${output-dir}/Protoc"
>
<copy
todir=
"${output-dir}/Protoc"
>
<fileset
basedir=
"${project::get-base-directory()}/lib"
>
<fileset
basedir=
"${project::get-base-directory()}/lib"
>
...
@@ -321,12 +321,12 @@
...
@@ -321,12 +321,12 @@
<exclude
name=
"**/*vshost*"
/>
<exclude
name=
"**/*vshost*"
/>
</fileset>
</fileset>
</copy>
</copy>
<copy
todir=
"${output-dir}/Silverlight2"
<
!--
copy todir="${output-dir}/Silverlight2"
flatten="true">
flatten="true">
<fileset basedir="${src}">
<fileset basedir="${src}">
<include name="ProtocolBuffers/bin/Silverlight2/Google.ProtocolBuffers.dll" />
<include name="ProtocolBuffers/bin/Silverlight2/Google.ProtocolBuffers.dll" />
</fileset>
</fileset>
</copy>
</copy
--
>
<copy
todir=
"${output-dir}/CompactFramework35"
<copy
todir=
"${output-dir}/CompactFramework35"
flatten=
"true"
>
flatten=
"true"
>
<fileset
basedir=
"${src}"
>
<fileset
basedir=
"${src}"
>
...
...
protos/google/protobuf/csharp_options.proto
View file @
c58ce5dc
...
@@ -38,6 +38,23 @@ message CSharpFileOptions {
...
@@ -38,6 +38,23 @@ message CSharpFileOptions {
// Generate attributes indicating non-CLS-compliance
// Generate attributes indicating non-CLS-compliance
optional
bool
cls_compliance
=
8
[
default
=
true
];
optional
bool
cls_compliance
=
8
[
default
=
true
];
// ROK - 2010-09-03 additions to csoptions ...
// The extension that should be appended to the umbrella_classname when creating files.
optional
string
file_extension
=
221
[
default
=
".cs"
];
// A nested namespace for the umbrella class. Helpful for name collisions caused by
// umbrella_classname conflicting with an existing type. This will be automatically
// set to 'Proto' if a collision is detected with types being generated. This value
// is ignored when nest_classes == true
optional
string
umbrella_namespace
=
222
;
// The output path for the source file(s) generated
optional
string
output_directory
=
223
[
default
=
"."
];
// Will ignore the type generations and remove dependencies for the descriptor proto
// files that declare their package to be "google.protobuf"
optional
bool
ignore_google_protobuf
=
224
[
default
=
false
];
}
}
extend
FileOptions
{
extend
FileOptions
{
...
...
src/ProtoGen.Test/ProtoGen.Test.csproj
View file @
c58ce5dc
...
@@ -50,10 +50,14 @@
...
@@ -50,10 +50,14 @@
<HintPath>
..\..\lib\Rhino.Mocks.dll
</HintPath>
<HintPath>
..\..\lib\Rhino.Mocks.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"DependencyResolutionTest.cs"
/>
<Compile
Include=
"DependencyResolutionTest.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"TempFile.cs"
/>
<Compile
Include=
"TestPreprocessing.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\ProtocolBuffers\ProtocolBuffers.csproj"
>
<ProjectReference
Include=
"..\ProtocolBuffers\ProtocolBuffers.csproj"
>
...
@@ -68,6 +72,20 @@
...
@@ -68,6 +72,20 @@
<ItemGroup>
<ItemGroup>
<None
Include=
"Properties\Google.ProtocolBuffers.ProtoGen.Test.snk"
/>
<None
Include=
"Properties\Google.ProtocolBuffers.ProtoGen.Test.snk"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<None
Include=
"..\..\lib\protoc.exe"
>
<Link>
protoc.exe
</Link>
<CopyToOutputDirectory>
Always
</CopyToOutputDirectory>
</None>
<None
Include=
"..\..\protos\google\protobuf\csharp_options.proto"
>
<Link>
google\protobuf\csharp_options.proto
</Link>
<CopyToOutputDirectory>
Always
</CopyToOutputDirectory>
</None>
<None
Include=
"..\..\protos\google\protobuf\descriptor.proto"
>
<Link>
google\protobuf\descriptor.proto
</Link>
<CopyToOutputDirectory>
Always
</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
src/ProtoGen.Test/TempFile.cs
0 → 100644
View file @
c58ce5dc
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Text
;
namespace
Google.ProtocolBuffers.ProtoGen
{
class
ProtoFile
:
TempFile
{
public
ProtoFile
(
string
filename
,
string
contents
)
{
_tempFile
=
filename
;
File
.
WriteAllText
(
_tempFile
,
contents
);
}
}
class
TempFile
:
IDisposable
{
protected
string
_tempFile
;
public
static
TempFile
Attach
(
string
path
)
{
TempFile
f
=
new
TempFile
();
f
.
_tempFile
=
path
;
return
f
;
}
protected
TempFile
()
{
}
public
TempFile
(
string
contents
)
{
File
.
WriteAllText
(
_tempFile
=
Path
.
GetTempFileName
(),
contents
,
Encoding
.
ASCII
);
}
public
string
TempPath
{
get
{
return
_tempFile
;
}
}
public
void
ChangeExtension
(
string
ext
)
{
string
newFile
=
Path
.
ChangeExtension
(
_tempFile
,
ext
);
File
.
Move
(
_tempFile
,
newFile
);
_tempFile
=
newFile
;
}
public
void
Dispose
()
{
if
(
File
.
Exists
(
_tempFile
))
File
.
Delete
(
_tempFile
);
}
}
}
src/ProtoGen.Test/TestPreprocessing.cs
0 → 100644
View file @
c58ce5dc
#
region
Copyright
notice
and
license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Reflection
;
using
NUnit.Framework
;
namespace
Google.ProtocolBuffers.ProtoGen
{
[
TestFixture
]
[
Category
(
"Preprocessor"
)]
public
partial
class
TestPreprocessing
{
private
static
readonly
string
TEMP
=
Path
.
Combine
(
Path
.
GetTempPath
(),
"proto-gen-test"
);
private
const
string
DEFAULT_PROTO
=
@"
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
}"
;
#
region
TestFixture
SetUp
/
TearDown
private
string
OriginalWorkingDirectory
=
Environment
.
CurrentDirectory
;
[
TestFixtureSetUp
]
public
virtual
void
Setup
()
{
Teardown
();
Directory
.
CreateDirectory
(
TEMP
);
Environment
.
CurrentDirectory
=
TEMP
;
}
[
TestFixtureTearDown
]
public
virtual
void
Teardown
()
{
Environment
.
CurrentDirectory
=
OriginalWorkingDirectory
;
if
(
Directory
.
Exists
(
TEMP
))
Directory
.
Delete
(
TEMP
,
true
);
}
#
endregion
#
region
Helper
Methods
RunProtoGen
/
RunCsc
void
RunProtoGen
(
int
expect
,
params
string
[]
args
)
{
TextWriter
tout
=
Console
.
Out
,
terr
=
Console
.
Error
;
StringWriter
temp
=
new
StringWriter
();
Console
.
SetOut
(
temp
);
Console
.
SetError
(
temp
);
try
{
Assert
.
AreEqual
(
expect
,
ProgramPreprocess
.
Run
(
args
),
"ProtoGen Failed: {0}"
,
temp
);
}
finally
{
Console
.
SetOut
(
tout
);
Console
.
SetError
(
terr
);
}
}
private
Assembly
RunCsc
(
int
expect
,
params
string
[]
sources
)
{
using
(
TempFile
tempDll
=
new
TempFile
(
String
.
Empty
))
{
tempDll
.
ChangeExtension
(
".dll"
);
List
<
string
>
args
=
new
List
<
string
>();
args
.
Add
(
"/nologo"
);
args
.
Add
(
"/target:library"
);
args
.
Add
(
"/debug-"
);
args
.
Add
(
String
.
Format
(
@"""/out:{0}"""
,
tempDll
.
TempPath
));
args
.
Add
(
"/r:System.dll"
);
args
.
Add
(
String
.
Format
(
@"""/r:{0}"""
,
typeof
(
Google
.
ProtocolBuffers
.
DescriptorProtos
.
DescriptorProto
).
Assembly
.
Location
));
args
.
AddRange
(
sources
);
string
exe
=
Path
.
Combine
(
System
.
Runtime
.
InteropServices
.
RuntimeEnvironment
.
GetRuntimeDirectory
(),
"csc.exe"
);
ProcessStartInfo
psi
=
new
ProcessStartInfo
(
exe
);
psi
.
CreateNoWindow
=
true
;
psi
.
UseShellExecute
=
false
;
psi
.
RedirectStandardOutput
=
true
;
psi
.
RedirectStandardError
=
true
;
psi
.
Arguments
=
string
.
Join
(
" "
,
args
.
ToArray
());
Process
p
=
Process
.
Start
(
psi
);
p
.
WaitForExit
();
string
errorText
=
p
.
StandardOutput
.
ReadToEnd
()
+
p
.
StandardError
.
ReadToEnd
();
Assert
.
AreEqual
(
expect
,
p
.
ExitCode
,
"CSC.exe Failed: {0}"
,
errorText
);
Assembly
asm
=
null
;
if
(
p
.
ExitCode
==
0
)
{
byte
[]
allbytes
=
File
.
ReadAllBytes
(
tempDll
.
TempPath
);
asm
=
Assembly
.
Load
(
allbytes
);
foreach
(
Type
t
in
asm
.
GetTypes
())
Debug
.
WriteLine
(
t
.
FullName
,
asm
.
FullName
);
}
return
asm
;
}
}
#
endregion
// *******************************************************************
// The following tests excercise options for protogen.exe
// *******************************************************************
[
Test
]
public
void
TestProtoFile
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithConflictingType
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
package nunit.simple;
// Test a very simple message.
message "
+
test
+
@" {
optional string name = 1;
} "
))
{
RunProtoGen
(
0
,
proto
.
TempPath
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple.Proto."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithNamespace
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"-namespace:MyNewNamespace"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"MyNewNamespace.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"MyNewNamespace."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithUmbrellaClassName
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
"MyUmbrellaClassname.cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"/umbrella_classname=MyUmbrellaClassname"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple.MyUmbrellaClassname"
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithNestedClass
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"-nest_classes:true"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple."
+
test
+
"+MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithExpandedNsDirectories
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
@"nunit\simple\"
+
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"-expand_namespace_directories:true"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileDisablingClsComplianceFlags
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional uint32 name = 1;
} "
))
{
//CS3021: Warning as Error: xx does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
RunProtoGen
(
0
,
proto
.
TempPath
);
RunCsc
(
1
,
source
.
TempPath
,
"/warnaserror+"
);
//Now we know it fails, make it pass by turning off cls_compliance generation
RunProtoGen
(
0
,
proto
.
TempPath
,
"-cls_compliance:false"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
,
"/warnaserror+"
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithNewExtension
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".Generated.cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"-file_extension:.Generated.cs"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithUmbrellaNamespace
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"-umbrella_namespace:MyUmbrella.Namespace"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple.MyUmbrella.Namespace."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithIgnoredUmbrellaNamespaceDueToNesting
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"-nest_classes:true"
,
"-umbrella_namespace:MyUmbrella.Namespace"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple."
+
test
+
"+MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithExplicitEmptyUmbrellaNamespace
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
package nunit.simple;
// Test a very simple message.
message "
+
test
+
@" {
optional string name = 1;
} "
))
{
//Forces the umbrella class to not use a namespace even if a collision with a type is detected.
RunProtoGen
(
0
,
proto
.
TempPath
,
"-umbrella_namespace:"
);
//error CS0441: 'nunit.simple.TestProtoFileWithExplicitEmptyUmbrellaNamespace': a class cannot be both static and sealed
RunCsc
(
1
,
source
.
TempPath
);
}
}
[
Test
]
public
void
TestProtoFileWithNewOutputFolder
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
@"generated-code\"
+
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
RunProtoGen
(
1
,
proto
.
TempPath
,
"-output_directory:generated-code"
);
Directory
.
CreateDirectory
(
"generated-code"
);
RunProtoGen
(
0
,
proto
.
TempPath
,
"-output_directory:generated-code"
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileAndIgnoreGoogleProtobuf
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
import ""google/protobuf/csharp_options.proto"";
option (google.protobuf.csharp_file_options).namespace = ""MyNewNamespace"";
"
+
DEFAULT_PROTO
))
{
string
google
=
Path
.
Combine
(
TEMP
,
"google\\protobuf"
);
Directory
.
CreateDirectory
(
google
);
foreach
(
string
file
in
Directory
.
GetFiles
(
Path
.
Combine
(
OriginalWorkingDirectory
,
"google\\protobuf"
)))
File
.
Copy
(
file
,
Path
.
Combine
(
google
,
Path
.
GetFileName
(
file
)));
Assert
.
AreEqual
(
0
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
RunProtoGen
(
0
,
proto
.
TempPath
,
"-ignore_google_protobuf:true"
);
Assert
.
AreEqual
(
1
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"MyNewNamespace.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"MyNewNamespace."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithoutIgnoreGoogleProtobuf
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
import ""google/protobuf/csharp_options.proto"";
option (google.protobuf.csharp_file_options).namespace = ""MyNewNamespace"";
"
+
DEFAULT_PROTO
))
{
string
google
=
Path
.
Combine
(
TEMP
,
"google\\protobuf"
);
Directory
.
CreateDirectory
(
google
);
foreach
(
string
file
in
Directory
.
GetFiles
(
Path
.
Combine
(
OriginalWorkingDirectory
,
"google\\protobuf"
)))
File
.
Copy
(
file
,
Path
.
Combine
(
google
,
Path
.
GetFileName
(
file
)));
Assert
.
AreEqual
(
0
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
//Without the option this fails due to being unable to resolve google/protobuf descriptors
RunProtoGen
(
1
,
proto
.
TempPath
,
"-ignore_google_protobuf:false"
);
}
}
// *******************************************************************
// The following tests excercise options for protoc.exe
// *******************************************************************
[
Test
]
public
void
TestProtoFileWithIncludeImports
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
import ""google/protobuf/csharp_options.proto"";
option (google.protobuf.csharp_file_options).namespace = ""MyNewNamespace"";
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
} "
))
{
string
google
=
Path
.
Combine
(
TEMP
,
"google\\protobuf"
);
Directory
.
CreateDirectory
(
google
);
foreach
(
string
file
in
Directory
.
GetFiles
(
Path
.
Combine
(
OriginalWorkingDirectory
,
"google\\protobuf"
)))
File
.
Copy
(
file
,
Path
.
Combine
(
google
,
Path
.
GetFileName
(
file
)));
Assert
.
AreEqual
(
0
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
//if you specify the protoc option --include_imports this should build three source files
RunProtoGen
(
0
,
proto
.
TempPath
,
"--include_imports"
);
Assert
.
AreEqual
(
3
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
//you can (and should) simply omit the inclusion of the extra source files in your project
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"MyNewNamespace.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"MyNewNamespace."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileWithIncludeImportsAndIgnoreGoogleProtobuf
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
import ""google/protobuf/csharp_options.proto"";
option (google.protobuf.csharp_file_options).namespace = ""MyNewNamespace"";
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
} "
))
{
string
google
=
Path
.
Combine
(
TEMP
,
"google\\protobuf"
);
Directory
.
CreateDirectory
(
google
);
foreach
(
string
file
in
Directory
.
GetFiles
(
Path
.
Combine
(
OriginalWorkingDirectory
,
"google\\protobuf"
)))
File
.
Copy
(
file
,
Path
.
Combine
(
google
,
Path
.
GetFileName
(
file
)));
Assert
.
AreEqual
(
0
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
//Even with --include_imports, if you provide -ignore_google_protobuf:true you only get the one source file
RunProtoGen
(
0
,
proto
.
TempPath
,
"-ignore_google_protobuf:true"
,
"--include_imports"
);
Assert
.
AreEqual
(
1
,
Directory
.
GetFiles
(
TEMP
,
"*.cs"
).
Length
);
//you can (and should) simply omit the inclusion of the extra source files in your project
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"MyNewNamespace.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"MyNewNamespace."
+
test
,
true
,
true
);
}
}
[
Test
]
public
void
TestProtoFileKeepingTheProtoBuffer
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
protobuf
=
TempFile
.
Attach
(
test
+
".pb"
))
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
} "
))
{
RunProtoGen
(
0
,
proto
.
TempPath
,
"--descriptor_set_out="
+
protobuf
.
TempPath
);
Assert
.
IsTrue
(
File
.
Exists
(
protobuf
.
TempPath
),
"Missing: "
+
protobuf
.
TempPath
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
//Seems the --proto_path or -I option is non-functional for me. Maybe others have luck?
[
Test
,
Ignore
(
"http://code.google.com/p/protobuf/issues/detail?id=40"
)]
public
void
TestProtoFileInDifferentDirectory
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
DEFAULT_PROTO
))
{
Environment
.
CurrentDirectory
=
OriginalWorkingDirectory
;
RunProtoGen
(
0
,
proto
.
TempPath
,
"--proto_path="
+
TEMP
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple."
+
test
,
true
,
true
);
}
}
// *******************************************************************
// Handling of mutliple input files
// *******************************************************************
[
Test
]
public
void
TestMultipleProtoFiles
()
{
Setup
();
using
(
TempFile
source1
=
TempFile
.
Attach
(
"MyMessage.cs"
))
using
(
ProtoFile
proto1
=
new
ProtoFile
(
"MyMessage.proto"
,
@"
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
}"
))
using
(
TempFile
source2
=
TempFile
.
Attach
(
"MyMessageList.cs"
))
using
(
ProtoFile
proto2
=
new
ProtoFile
(
"MyMessageList.proto"
,
@"
package nunit.simple;
import ""MyMessage.proto"";
// Test a very simple message.
message MyMessageList {
repeated MyMessage messages = 1;
}"
))
{
RunProtoGen
(
0
,
proto1
.
TempPath
,
proto2
.
TempPath
);
Assembly
a
=
RunCsc
(
0
,
source1
.
TempPath
,
source2
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t1
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t1
),
"Expect an IMessage"
);
//assert that the message type is in the expected namespace
Type
t2
=
a
.
GetType
(
"nunit.simple.MyMessageList"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t2
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple.Proto.MyMessage"
,
true
,
true
);
a
.
GetType
(
"nunit.simple.Proto.MyMessageList"
,
true
,
true
);
}
}
[
Test
]
public
void
TestOneProtoFileWithBufferFile
()
{
Setup
();
using
(
TempFile
source1
=
TempFile
.
Attach
(
"MyMessage.cs"
))
using
(
TempFile
protobuf
=
TempFile
.
Attach
(
"MyMessage.pb"
))
using
(
ProtoFile
proto1
=
new
ProtoFile
(
"MyMessage.proto"
,
@"
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
}"
))
using
(
TempFile
source2
=
TempFile
.
Attach
(
"MyMessageList.cs"
))
using
(
ProtoFile
proto2
=
new
ProtoFile
(
"MyMessageList.proto"
,
@"
package nunit.simple;
import ""MyMessage.proto"";
// Test a very simple message.
message MyMessageList {
repeated MyMessage messages = 1;
}"
))
{
//build the proto buffer for MyMessage
RunProtoGen
(
0
,
proto1
.
TempPath
,
"--descriptor_set_out="
+
protobuf
.
TempPath
);
//build the MyMessageList proto-buffer and generate code by including MyMessage.pb
RunProtoGen
(
0
,
proto2
.
TempPath
,
protobuf
.
TempPath
);
Assembly
a
=
RunCsc
(
0
,
source1
.
TempPath
,
source2
.
TempPath
);
//assert that the message type is in the expected namespace
Type
t1
=
a
.
GetType
(
"nunit.simple.MyMessage"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t1
),
"Expect an IMessage"
);
//assert that the message type is in the expected namespace
Type
t2
=
a
.
GetType
(
"nunit.simple.MyMessageList"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IMessage
).
IsAssignableFrom
(
t2
),
"Expect an IMessage"
);
//assert that we can find the static descriptor type
a
.
GetType
(
"nunit.simple.Proto.MyMessage"
,
true
,
true
);
a
.
GetType
(
"nunit.simple.Proto.MyMessageList"
,
true
,
true
);
}
}
}
}
src/ProtoGen/DescriptorUtil.cs
View file @
c58ce5dc
...
@@ -46,10 +46,24 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -46,10 +46,24 @@ namespace Google.ProtocolBuffers.ProtoGen {
CSharpFileOptions
options
=
descriptor
.
File
.
CSharpOptions
;
CSharpFileOptions
options
=
descriptor
.
File
.
CSharpOptions
;
string
result
=
options
.
Namespace
;
string
result
=
options
.
Namespace
;
if
(
result
!=
""
)
result
+=
'.'
;
if
(
result
!=
""
)
result
+=
'.'
;
result
+=
options
.
UmbrellaClassname
;
result
+=
QualifiedUmbrellaClassName
(
options
)
;
return
"global::"
+
result
;
return
"global::"
+
result
;
}
}
/// <summary>
/// ROK 2010-09-03
/// Evaluates the options and returns the qualified name of the umbrella class
/// relative to the descriptor type's namespace. Basically contacts the
/// UmbrellaNamespace + UmbrellaClassname fields.
/// </summary>
internal
static
string
QualifiedUmbrellaClassName
(
CSharpFileOptions
options
)
{
string
fullName
=
options
.
UmbrellaClassname
;
if
(!
options
.
NestClasses
&&
options
.
UmbrellaNamespace
!=
""
)
fullName
=
String
.
Format
(
"{0}.{1}"
,
options
.
UmbrellaNamespace
,
options
.
UmbrellaClassname
);
return
fullName
;
}
internal
static
string
GetMappedTypeName
(
MappedType
type
)
{
internal
static
string
GetMappedTypeName
(
MappedType
type
)
{
switch
(
type
)
{
switch
(
type
)
{
case
MappedType
.
Int32
:
return
"int"
;
case
MappedType
.
Int32
:
return
"int"
;
...
...
src/ProtoGen/Generator.cs
View file @
c58ce5dc
...
@@ -60,19 +60,30 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -60,19 +60,30 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
Generate
()
{
public
void
Generate
()
{
List
<
FileDescriptorSet
>
descriptorProtos
=
new
List
<
FileDescriptorSet
>();
foreach
(
string
inputFile
in
options
.
InputFiles
)
{
foreach
(
string
inputFile
in
options
.
InputFiles
)
{
FileDescriptorSet
descriptorProtos
;
ExtensionRegistry
extensionRegistry
=
ExtensionRegistry
.
CreateInstance
();
ExtensionRegistry
extensionRegistry
=
ExtensionRegistry
.
CreateInstance
();
extensionRegistry
.
Add
(
CSharpOptions
.
CSharpFileOptions
);
extensionRegistry
.
Add
(
CSharpOptions
.
CSharpFileOptions
);
extensionRegistry
.
Add
(
CSharpOptions
.
CSharpFieldOptions
);
extensionRegistry
.
Add
(
CSharpOptions
.
CSharpFieldOptions
);
using
(
Stream
inputStream
=
File
.
OpenRead
(
inputFile
))
{
using
(
Stream
inputStream
=
File
.
OpenRead
(
inputFile
))
{
descriptorProtos
=
FileDescriptorSet
.
ParseFrom
(
inputStream
,
extensionRegistry
);
descriptorProtos
.
Add
(
FileDescriptorSet
.
ParseFrom
(
inputStream
,
extensionRegistry
)
);
}
}
IList
<
FileDescriptor
>
descriptors
=
ConvertDescriptors
(
descriptorProtos
);
}
IList
<
FileDescriptor
>
descriptors
=
ConvertDescriptors
(
options
.
FileOptions
,
descriptorProtos
.
ToArray
());
//ROK Combine with Options...
foreach
(
FileDescriptor
descriptor
in
descriptors
)
descriptor
.
ConfigureWithDefaultOptions
(
options
.
FileOptions
);
foreach
(
FileDescriptor
descriptor
in
descriptors
)
{
foreach
(
FileDescriptor
descriptor
in
descriptors
)
{
//ROK 2010-09-03 Ignore google protobuf package
if
(
descriptor
.
CSharpOptions
.
IgnoreGoogleProtobuf
&&
descriptor
.
Package
==
"google.protobuf"
)
continue
;
Generate
(
descriptor
);
Generate
(
descriptor
);
}
}
}
}
}
...
@@ -90,8 +101,14 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -90,8 +101,14 @@ namespace Google.ProtocolBuffers.ProtoGen {
private
string
GetOutputFile
(
FileDescriptor
descriptor
)
{
private
string
GetOutputFile
(
FileDescriptor
descriptor
)
{
CSharpFileOptions
fileOptions
=
descriptor
.
CSharpOptions
;
CSharpFileOptions
fileOptions
=
descriptor
.
CSharpOptions
;
string
filename
=
descriptor
.
CSharpOptions
.
UmbrellaClassname
+
".cs"
;
string
outputDirectory
=
options
.
OutputDirectory
;
//ROK 2010-09-03 - added the ability to sepcify the extension used within the options
//string filename = descriptor.CSharpOptions.UmbrellaClassname + ".cs";
string
filename
=
descriptor
.
CSharpOptions
.
UmbrellaClassname
+
descriptor
.
CSharpOptions
.
FileExtension
;
//ROK 2010-09-03 - output directory can be specific to a descriptor file
//string outputDirectory = options.OutputDirectory;
string
outputDirectory
=
descriptor
.
CSharpOptions
.
OutputDirectory
;
if
(
fileOptions
.
ExpandNamespaceDirectories
)
{
if
(
fileOptions
.
ExpandNamespaceDirectories
)
{
string
package
=
fileOptions
.
Namespace
;
string
package
=
fileOptions
.
Namespace
;
if
(!
string
.
IsNullOrEmpty
(
package
))
{
if
(!
string
.
IsNullOrEmpty
(
package
))
{
...
@@ -99,22 +116,31 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -99,22 +116,31 @@ namespace Google.ProtocolBuffers.ProtoGen {
foreach
(
string
bit
in
bits
)
{
foreach
(
string
bit
in
bits
)
{
outputDirectory
=
Path
.
Combine
(
outputDirectory
,
bit
);
outputDirectory
=
Path
.
Combine
(
outputDirectory
,
bit
);
}
}
Directory
.
CreateDirectory
(
outputDirectory
);
}
}
}
}
//ROK 2010-09-03 - Always force output directory exists since they can specify this in .proto options
Directory
.
CreateDirectory
(
outputDirectory
);
return
Path
.
Combine
(
outputDirectory
,
filename
);
return
Path
.
Combine
(
outputDirectory
,
filename
);
}
}
// ROK 2010-09-03 - used by unit tests, we will continue to allow them to function as-is.
internal
static
IList
<
FileDescriptor
>
ConvertDescriptors
(
FileDescriptorSet
descriptorProtos
)
{
return
ConvertDescriptors
(
CSharpFileOptions
.
DefaultInstance
,
descriptorProtos
);
}
/// <summary>
/// <summary>
/// Resolves any dependencies and converts FileDescriptorProtos into FileDescriptors.
/// Resolves any dependencies and converts FileDescriptorProtos into FileDescriptors.
/// The list returned is in the same order as the protos are listed in the descriptor set.
/// The list returned is in the same order as the protos are listed in the descriptor set.
/// Note: this method is internal rather than private to allow testing.
/// Note: this method is internal rather than private to allow testing.
/// </summary>
/// </summary>
/// <exception cref="DependencyResolutionException">Not all dependencies could be resolved.</exception>
/// <exception cref="DependencyResolutionException">Not all dependencies could be resolved.</exception>
internal
static
IList
<
FileDescriptor
>
ConvertDescriptors
(
FileDescriptorSet
descriptorProtos
)
{
private
static
IList
<
FileDescriptor
>
ConvertDescriptors
(
CSharpFileOptions
options
,
params
FileDescriptorSet
[]
descriptorProtos
)
{
// Simple strategy: Keep going through the list of protos to convert, only doing ones where
// Simple strategy: Keep going through the list of protos to convert, only doing ones where
// we've already converted all the dependencies, until we get to a stalemate
// we've already converted all the dependencies, until we get to a stalemate
IList
<
FileDescriptorProto
>
fileList
=
descriptorProtos
.
FileList
;
List
<
FileDescriptorProto
>
fileList
=
new
List
<
FileDescriptorProto
>();
foreach
(
FileDescriptorSet
set
in
descriptorProtos
)
fileList
.
AddRange
(
set
.
FileList
);
FileDescriptor
[]
converted
=
new
FileDescriptor
[
fileList
.
Count
];
FileDescriptor
[]
converted
=
new
FileDescriptor
[
fileList
.
Count
];
Dictionary
<
string
,
FileDescriptor
>
convertedMap
=
new
Dictionary
<
string
,
FileDescriptor
>();
Dictionary
<
string
,
FileDescriptor
>
convertedMap
=
new
Dictionary
<
string
,
FileDescriptor
>();
...
@@ -131,10 +157,32 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -131,10 +157,32 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
FileDescriptorProto
candidate
=
fileList
[
i
];
FileDescriptorProto
candidate
=
fileList
[
i
];
FileDescriptor
[]
dependencies
=
new
FileDescriptor
[
candidate
.
DependencyList
.
Count
];
FileDescriptor
[]
dependencies
=
new
FileDescriptor
[
candidate
.
DependencyList
.
Count
];
CSharpFileOptions
.
Builder
builder
=
options
.
ToBuilder
();
if
(
candidate
.
Options
.
HasExtension
(
DescriptorProtos
.
CSharpOptions
.
CSharpFileOptions
))
{
builder
.
MergeFrom
(
candidate
.
Options
.
GetExtension
(
DescriptorProtos
.
CSharpOptions
.
CSharpFileOptions
));
}
CSharpFileOptions
localOptions
=
builder
.
Build
();
bool
foundAllDependencies
=
true
;
bool
foundAllDependencies
=
true
;
for
(
int
j
=
0
;
j
<
dependencies
.
Length
;
j
++)
{
for
(
int
j
=
0
;
j
<
dependencies
.
Length
;
j
++)
{
if
(!
convertedMap
.
TryGetValue
(
candidate
.
DependencyList
[
j
],
out
dependencies
[
j
]))
{
if
(!
convertedMap
.
TryGetValue
(
candidate
.
DependencyList
[
j
],
out
dependencies
[
j
]))
{
foundAllDependencies
=
false
;
// ROK 2010-09-03 - we can auto-magically resolve these since we already have their description
// This way if the file is only referencing options it does not need to be built with the
// --include_imports definition.
if
(
localOptions
.
IgnoreGoogleProtobuf
&&
(
candidate
.
DependencyList
[
j
]
==
"google/protobuf/csharp_options.proto"
))
{
dependencies
[
j
]
=
CSharpOptions
.
Descriptor
;
continue
;
}
if
(
localOptions
.
IgnoreGoogleProtobuf
&&
(
candidate
.
DependencyList
[
j
]
==
"google/protobuf/descriptor.proto"
))
{
dependencies
[
j
]
=
DescriptorProtoFile
.
Descriptor
;
continue
;
}
foundAllDependencies
=
false
;
break
;
break
;
}
}
}
}
...
...
src/ProtoGen/GeneratorOptions.cs
View file @
c58ce5dc
...
@@ -32,8 +32,12 @@
...
@@ -32,8 +32,12 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Text.RegularExpressions
;
using
Google.ProtocolBuffers.DescriptorProtos
;
using
Google.ProtocolBuffers.Descriptors
;
namespace
Google.ProtocolBuffers.ProtoGen
{
namespace
Google.ProtocolBuffers.ProtoGen
{
...
@@ -44,8 +48,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -44,8 +48,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
/// the generator.
/// the generator.
/// </summary>
/// </summary>
public
sealed
class
GeneratorOptions
{
public
sealed
class
GeneratorOptions
{
//ROK, see below - public string OutputDirectory { get; set; }
public
string
OutputDirectory
{
get
;
set
;
}
public
IList
<
string
>
InputFiles
{
get
;
set
;
}
public
IList
<
string
>
InputFiles
{
get
;
set
;
}
/// <summary>
/// <summary>
...
@@ -58,12 +61,15 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -58,12 +61,15 @@ namespace Google.ProtocolBuffers.ProtoGen {
public
bool
TryValidate
(
out
IList
<
string
>
reasons
)
{
public
bool
TryValidate
(
out
IList
<
string
>
reasons
)
{
List
<
string
>
tmpReasons
=
new
List
<
string
>();
List
<
string
>
tmpReasons
=
new
List
<
string
>();
//ROK 2010-09-03 see population of options below
ParseArguments
(
tmpReasons
);
// Output directory validation
// Output directory validation
if
(
string
.
IsNullOrEmpty
(
OutputDirectory
))
{
if
(
string
.
IsNullOrEmpty
(
FileOptions
.
OutputDirectory
))
{
tmpReasons
.
Add
(
"No output directory specified"
);
tmpReasons
.
Add
(
"No output directory specified"
);
}
else
{
}
else
{
if
(!
Directory
.
Exists
(
OutputDirectory
))
{
if
(!
Directory
.
Exists
(
FileOptions
.
OutputDirectory
))
{
tmpReasons
.
Add
(
"Specified output directory ("
+
OutputDirectory
+
" doesn't exist."
);
tmpReasons
.
Add
(
"Specified output directory ("
+
FileOptions
.
OutputDirectory
+
" doesn't exist."
);
}
}
}
}
...
@@ -99,5 +105,179 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -99,5 +105,179 @@ namespace Google.ProtocolBuffers.ProtoGen {
throw
new
InvalidOptionsException
(
reasons
);
throw
new
InvalidOptionsException
(
reasons
);
}
}
}
}
// ROK - added to provide defaults for any of the options
//Raw arguments
public
IList
<
string
>
Arguments
{
get
;
set
;
}
[
Obsolete
(
"Please use GeneratorOptions.FileOptions.OutputDirectory instead"
)]
public
string
OutputDirectory
{
get
{
return
FileOptions
.
OutputDirectory
;
}
set
{
CSharpFileOptions
.
Builder
bld
=
FileOptions
.
ToBuilder
();
bld
.
OutputDirectory
=
value
;
FileOptions
=
bld
.
Build
();
}
}
private
static
readonly
Regex
ArgMatch
=
new
Regex
(
@"^[-/](?<name>[\w_]+?)[:=](?<value>.*)$"
);
CSharpFileOptions
_fileOptions
;
public
CSharpFileOptions
FileOptions
{
get
{
return
_fileOptions
??
(
_fileOptions
=
CSharpFileOptions
.
DefaultInstance
);
}
set
{
_fileOptions
=
value
;
}
}
private
void
ParseArguments
(
IList
<
string
>
tmpReasons
)
{
bool
doHelp
=
Arguments
.
Count
==
0
;
//ROK Parse the raw arguments
InputFiles
=
new
List
<
string
>();
CSharpFileOptions
.
Builder
builder
=
FileOptions
.
ToBuilder
();
Dictionary
<
string
,
FieldDescriptor
>
fields
=
new
Dictionary
<
string
,
FieldDescriptor
>(
StringComparer
.
OrdinalIgnoreCase
);
foreach
(
FieldDescriptor
fld
in
builder
.
DescriptorForType
.
Fields
)
fields
.
Add
(
fld
.
Name
,
fld
);
foreach
(
string
argument
in
Arguments
)
{
if
(
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
"-help"
,
argument
)
||
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
"/help"
,
argument
)
||
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
"-?"
,
argument
)
||
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
"/?"
,
argument
))
{
doHelp
=
true
;
break
;
}
Match
m
=
ArgMatch
.
Match
(
argument
);
if
(
m
.
Success
)
{
FieldDescriptor
fld
;
string
name
=
m
.
Groups
[
"name"
].
Value
;
string
value
=
m
.
Groups
[
"value"
].
Value
;
if
(
fields
.
TryGetValue
(
name
,
out
fld
))
{
object
obj
;
if
(
TryCoerceType
(
value
,
fld
,
out
obj
,
tmpReasons
))
builder
[
fld
]
=
obj
;
}
else
if
(!
File
.
Exists
(
argument
))
{
doHelp
=
true
;
tmpReasons
.
Add
(
"Unknown argument '"
+
name
+
"'."
);
}
else
InputFiles
.
Add
(
argument
);
}
else
InputFiles
.
Add
(
argument
);
}
if
(
doHelp
||
InputFiles
.
Count
==
0
)
{
tmpReasons
.
Add
(
"Arguments:"
);
foreach
(
KeyValuePair
<
string
,
FieldDescriptor
>
field
in
fields
)
{
tmpReasons
.
Add
(
String
.
Format
(
"-{0}=[{1}]"
,
field
.
Key
,
field
.
Value
.
FieldType
));
}
tmpReasons
.
Add
(
"followed by one or more file paths."
);
}
else
FileOptions
=
builder
.
Build
();
}
private
static
bool
TryCoerceType
(
string
text
,
FieldDescriptor
field
,
out
object
value
,
IList
<
string
>
tmpReasons
)
{
value
=
null
;
switch
(
field
.
FieldType
)
{
case
FieldType
.
Int32
:
case
FieldType
.
SInt32
:
case
FieldType
.
SFixed32
:
value
=
Int32
.
Parse
(
text
);
break
;
case
FieldType
.
Int64
:
case
FieldType
.
SInt64
:
case
FieldType
.
SFixed64
:
value
=
Int64
.
Parse
(
text
);
break
;
case
FieldType
.
UInt32
:
case
FieldType
.
Fixed32
:
value
=
UInt32
.
Parse
(
text
);
break
;
case
FieldType
.
UInt64
:
case
FieldType
.
Fixed64
:
value
=
UInt64
.
Parse
(
text
);
break
;
case
FieldType
.
Float
:
value
=
float
.
Parse
(
text
);
break
;
case
FieldType
.
Double
:
value
=
Double
.
Parse
(
text
);
break
;
case
FieldType
.
Bool
:
value
=
Boolean
.
Parse
(
text
);
break
;
case
FieldType
.
String
:
value
=
text
;
break
;
case
FieldType
.
Enum
:
{
EnumDescriptor
enumType
=
field
.
EnumType
;
int
number
;
if
(
int
.
TryParse
(
text
,
out
number
))
{
value
=
enumType
.
FindValueByNumber
(
number
);
if
(
value
==
null
)
{
tmpReasons
.
Add
(
"Enum type \""
+
enumType
.
FullName
+
"\" has no value with number "
+
number
+
"."
);
return
false
;
}
}
else
{
value
=
enumType
.
FindValueByName
(
text
);
if
(
value
==
null
)
{
tmpReasons
.
Add
(
"Enum type \""
+
enumType
.
FullName
+
"\" has no value named \""
+
text
+
"\"."
);
return
false
;
}
}
break
;
}
case
FieldType
.
Bytes
:
case
FieldType
.
Message
:
case
FieldType
.
Group
:
tmpReasons
.
Add
(
"Unhandled field type "
+
field
.
FieldType
.
ToString
()
+
"."
);
return
false
;
}
return
true
;
}
}
}
}
}
src/ProtoGen/Program.cs
View file @
c58ce5dc
...
@@ -41,7 +41,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -41,7 +41,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
/// Entry point for the Protocol Buffers generator.
/// Entry point for the Protocol Buffers generator.
/// </summary>
/// </summary>
class
Program
{
class
Program
{
static
int
Main
(
string
[]
args
)
{
internal
static
int
Main
(
string
[]
args
)
{
try
{
try
{
// Hack to make sure everything's initialized
// Hack to make sure everything's initialized
DescriptorProtoFile
.
Descriptor
.
ToString
();
DescriptorProtoFile
.
Descriptor
.
ToString
();
...
@@ -71,8 +71,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -71,8 +71,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
//string baseDir = "c:\\Users\\Jon\\Documents\\Visual Studio 2008\\Projects\\ProtocolBuffers";
//string baseDir = "c:\\Users\\Jon\\Documents\\Visual Studio 2008\\Projects\\ProtocolBuffers";
//options.OutputDirectory = baseDir + "\\tmp";
//options.OutputDirectory = baseDir + "\\tmp";
//options.InputFiles = new[] { baseDir + "\\protos\\nwind-solo.protobin" };
//options.InputFiles = new[] { baseDir + "\\protos\\nwind-solo.protobin" };
options
.
OutputDirectory
=
"."
;
options
.
InputFiles
=
args
;
//ROK 2010-09-03 - fixes to allow parsing these options...
//options.OutputDirectory = ".";
//options.InputFiles = args;
options
.
Arguments
=
args
;
return
options
;
return
options
;
}
}
}
}
...
...
src/ProtoGen/ProgramPreprocess.cs
0 → 100644
View file @
c58ce5dc
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
namespace
Google.ProtocolBuffers.ProtoGen
{
/// <summary>
/// Preprocesses any input files with an extension of '.proto' by running protoc.exe. If arguments
/// are supplied with '--' prefix they are provided to protoc.exe, otherwise they are assumed to
/// be used for ProtoGen.exe which is run on the resulting output proto buffer. If the option
/// --descriptor_set_out= is specified the proto buffer file is kept, otherwise it will be removed
/// after code generation.
/// </summary>
internal
class
ProgramPreprocess
{
static
int
Main
(
string
[]
args
)
{
try
{
return
Environment
.
ExitCode
=
Run
(
args
);
}
catch
(
Exception
ex
)
{
Console
.
Error
.
WriteLine
(
ex
);
return
Environment
.
ExitCode
=
2
;
}
}
internal
static
int
Run
(
params
string
[]
args
)
{
bool
deleteFile
=
false
;
string
tempFile
=
null
;
int
result
=
1
;
bool
doHelp
=
args
.
Length
==
0
;
try
{
List
<
string
>
protocArgs
=
new
List
<
string
>();
List
<
string
>
protoGenArgs
=
new
List
<
string
>();
foreach
(
string
arg
in
args
)
{
doHelp
|=
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
arg
,
"/?"
);
doHelp
|=
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
arg
,
"/help"
);
doHelp
|=
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
arg
,
"-?"
);
doHelp
|=
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
arg
,
"-help"
);
if
(
arg
.
StartsWith
(
"--descriptor_set_out="
))
{
tempFile
=
arg
.
Substring
(
"--descriptor_set_out="
.
Length
);
protoGenArgs
.
Add
(
tempFile
);
}
}
if
(
doHelp
)
{
Console
.
WriteLine
();
Console
.
WriteLine
(
"PROTOC.exe: Use any of the following options that begin with '--':"
);
Console
.
WriteLine
();
try
{
RunProtoc
(
"--help"
);
}
catch
(
Exception
ex
)
{
Console
.
Error
.
WriteLine
(
ex
.
Message
);
}
Console
.
WriteLine
();
Console
.
WriteLine
();
Console
.
WriteLine
(
"PRTOGEN.exe: The following options are used to specify defaults for code generation."
);
Console
.
WriteLine
();
Program
.
Main
(
new
string
[
0
]);
return
0
;
}
foreach
(
string
arg
in
args
)
{
if
(
arg
.
StartsWith
(
"--"
))
protocArgs
.
Add
(
arg
);
else
if
(
File
.
Exists
(
arg
)
&&
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
".proto"
,
Path
.
GetExtension
(
arg
)))
{
if
(
tempFile
==
null
)
{
deleteFile
=
true
;
tempFile
=
Path
.
GetTempFileName
();
protocArgs
.
Add
(
String
.
Format
(
"--descriptor_set_out={0}"
,
tempFile
));
protoGenArgs
.
Add
(
tempFile
);
}
protocArgs
.
Add
(
arg
);
}
else
protoGenArgs
.
Add
(
arg
);
}
if
(
tempFile
!=
null
)
{
result
=
RunProtoc
(
protocArgs
.
ToArray
());
if
(
result
!=
0
)
return
result
;
}
result
=
Program
.
Main
(
protoGenArgs
.
ToArray
());
}
finally
{
if
(
deleteFile
&&
tempFile
!=
null
&&
File
.
Exists
(
tempFile
))
File
.
Delete
(
tempFile
);
}
return
result
;
}
private
static
int
RunProtoc
(
params
string
[]
args
)
{
const
string
protoc
=
"protoc.exe"
;
string
exePath
=
protoc
;
//why oh why is this not in System.IO.Path or Environment...
List
<
string
>
searchPath
=
new
List
<
string
>();
searchPath
.
Add
(
Environment
.
CurrentDirectory
);
searchPath
.
Add
(
AppDomain
.
CurrentDomain
.
BaseDirectory
);
searchPath
.
AddRange
((
Environment
.
GetEnvironmentVariable
(
"PATH"
)
??
String
.
Empty
).
Split
(
Path
.
PathSeparator
));
foreach
(
string
path
in
searchPath
)
if
(
File
.
Exists
(
exePath
=
Path
.
Combine
(
path
,
protoc
)))
break
;
if
(!
File
.
Exists
(
exePath
))
throw
new
FileNotFoundException
(
"Unable to locate "
+
protoc
+
" make sure it is in the PATH, cwd, or exe dir."
);
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
++)
if
(
args
[
i
].
IndexOf
(
' '
)
>
0
&&
args
[
i
][
0
]
!=
'"'
)
args
[
i
]
=
'"'
+
args
[
i
]
+
'"'
;
ProcessStartInfo
psi
=
new
ProcessStartInfo
(
exePath
);
psi
.
Arguments
=
String
.
Join
(
" "
,
args
);
psi
.
RedirectStandardError
=
true
;
psi
.
RedirectStandardInput
=
false
;
psi
.
RedirectStandardOutput
=
true
;
psi
.
ErrorDialog
=
false
;
psi
.
CreateNoWindow
=
true
;
psi
.
UseShellExecute
=
false
;
psi
.
WorkingDirectory
=
Environment
.
CurrentDirectory
;
Process
process
=
Process
.
Start
(
psi
);
if
(
process
==
null
)
return
1
;
process
.
WaitForExit
();
string
tmp
=
process
.
StandardOutput
.
ReadToEnd
();
if
(
tmp
.
Trim
().
Length
>
0
)
Console
.
Out
.
WriteLine
(
tmp
);
tmp
=
process
.
StandardError
.
ReadToEnd
();
if
(
tmp
.
Trim
().
Length
>
0
)
Console
.
Error
.
WriteLine
(
tmp
);
return
process
.
ExitCode
;
}
}
}
src/ProtoGen/ProtoGen.csproj
View file @
c58ce5dc
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
</TargetFrameworkSubset>
</TargetFrameworkSubset>
<SignAssembly>
true
</SignAssembly>
<SignAssembly>
true
</SignAssembly>
<AssemblyOriginatorKeyFile>
Properties\Google.ProtocolBuffers.ProtoGen.snk
</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>
Properties\Google.ProtocolBuffers.ProtoGen.snk
</AssemblyOriginatorKeyFile>
<StartupObject>
Google.ProtocolBuffers.ProtoGen.ProgramPreprocess
</StartupObject>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugSymbols>
true
</DebugSymbols>
...
@@ -58,6 +59,7 @@
...
@@ -58,6 +59,7 @@
<Compile
Include=
"MessageFieldGenerator.cs"
/>
<Compile
Include=
"MessageFieldGenerator.cs"
/>
<Compile
Include=
"MessageGenerator.cs"
/>
<Compile
Include=
"MessageGenerator.cs"
/>
<Compile
Include=
"PrimitiveFieldGenerator.cs"
/>
<Compile
Include=
"PrimitiveFieldGenerator.cs"
/>
<Compile
Include=
"ProgramPreprocess.cs"
/>
<Compile
Include=
"RepeatedEnumFieldGenerator.cs"
/>
<Compile
Include=
"RepeatedEnumFieldGenerator.cs"
/>
<Compile
Include=
"RepeatedMessageFieldGenerator.cs"
/>
<Compile
Include=
"RepeatedMessageFieldGenerator.cs"
/>
<Compile
Include=
"RepeatedPrimitiveFieldGenerator.cs"
/>
<Compile
Include=
"RepeatedPrimitiveFieldGenerator.cs"
/>
...
...
src/ProtoGen/ServiceGenerator.cs
View file @
c58ce5dc
...
@@ -61,7 +61,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -61,7 +61,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer
.
WriteLine
();
writer
.
WriteLine
();
writer
.
WriteLine
(
"{0} static pbd::ServiceDescriptor Descriptor {{"
,
ClassAccessLevel
);
writer
.
WriteLine
(
"{0} static pbd::ServiceDescriptor Descriptor {{"
,
ClassAccessLevel
);
writer
.
WriteLine
(
" get {{ return {0}.Descriptor.Services[{1}]; }}"
,
writer
.
WriteLine
(
" get {{ return {0}.Descriptor.Services[{1}]; }}"
,
Descriptor
.
File
.
CSharpOptions
.
UmbrellaClassname
,
Descriptor
.
Index
);
Descriptor
Util
.
QualifiedUmbrellaClassName
(
Descriptor
.
File
.
CSharpOptions
)
,
Descriptor
.
Index
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"{0} pbd::ServiceDescriptor DescriptorForType {{"
,
ClassAccessLevel
);
writer
.
WriteLine
(
"{0} pbd::ServiceDescriptor DescriptorForType {{"
,
ClassAccessLevel
);
writer
.
WriteLine
(
" get { return Descriptor; }"
);
writer
.
WriteLine
(
" get { return Descriptor; }"
);
...
...
src/ProtoGen/UmbrellaClassGenerator.cs
View file @
c58ce5dc
...
@@ -92,7 +92,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -92,7 +92,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
if
(!
Descriptor
.
CSharpOptions
.
NestClasses
)
{
if
(!
Descriptor
.
CSharpOptions
.
NestClasses
)
{
writer
.
Outdent
();
writer
.
Outdent
();
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
//ROK 2010-09-03 - close the namespace around the umbrella class if defined
if
(!
Descriptor
.
CSharpOptions
.
NestClasses
&&
Descriptor
.
CSharpOptions
.
UmbrellaNamespace
!=
""
)
{
writer
.
Outdent
();
writer
.
WriteLine
(
"}"
);
}
}
WriteChildren
(
writer
,
"Enums"
,
Descriptor
.
EnumTypes
);
WriteChildren
(
writer
,
"Enums"
,
Descriptor
.
EnumTypes
);
WriteChildren
(
writer
,
"Messages"
,
Descriptor
.
MessageTypes
);
WriteChildren
(
writer
,
"Messages"
,
Descriptor
.
MessageTypes
);
WriteChildren
(
writer
,
"Services"
,
Descriptor
.
Services
);
WriteChildren
(
writer
,
"Services"
,
Descriptor
.
Services
);
...
@@ -115,7 +121,14 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -115,7 +121,14 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer
.
WriteLine
(
"namespace {0} {{"
,
Descriptor
.
CSharpOptions
.
Namespace
);
writer
.
WriteLine
(
"namespace {0} {{"
,
Descriptor
.
CSharpOptions
.
Namespace
);
writer
.
Indent
();
writer
.
Indent
();
writer
.
WriteLine
();
writer
.
WriteLine
();
}
}
//ROK 2010-09-03 - add the namespace around the umbrella class if defined
if
(!
Descriptor
.
CSharpOptions
.
NestClasses
&&
Descriptor
.
CSharpOptions
.
UmbrellaNamespace
!=
""
)
{
writer
.
WriteLine
(
"namespace {0} {{"
,
Descriptor
.
CSharpOptions
.
UmbrellaNamespace
);
writer
.
Indent
();
writer
.
WriteLine
();
}
if
(
Descriptor
.
CSharpOptions
.
CodeContracts
)
{
if
(
Descriptor
.
CSharpOptions
.
CodeContracts
)
{
writer
.
WriteLine
(
"[global::System.Diagnostics.Contracts.ContractVerificationAttribute(false)]"
);
writer
.
WriteLine
(
"[global::System.Diagnostics.Contracts.ContractVerificationAttribute(false)]"
);
}
}
...
...
src/ProtocolBuffers.sln
View file @
c58ce5dc
...
@@ -17,6 +17,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoBench", "ProtoBench\Pr
...
@@ -17,6 +17,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoBench", "ProtoBench\Pr
EndProject
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoDump", "ProtoDump\ProtoDump.csproj", "{D7282E99-2DC3-405B-946F-177DB2FD2AE2}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoDump", "ProtoDump\ProtoDump.csproj", "{D7282E99-2DC3-405B-946F-177DB2FD2AE2}"
EndProject
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C-5FC2-4671-9216-781CB8187EC7}"
ProjectSection(SolutionItems) = preProject
..\protos\tutorial\addressbook.proto = ..\protos\tutorial\addressbook.proto
..\protos\google\protobuf\csharp_options.proto = ..\protos\google\protobuf\csharp_options.proto
..\protos\google\protobuf\descriptor.proto = ..\protos\google\protobuf\descriptor.proto
..\todo.txt = ..\todo.txt
EndProjectSection
EndProject
Global
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Any CPU = Debug|Any CPU
...
...
src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
View file @
c58ce5dc
...
@@ -37,23 +37,26 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -37,23 +37,26 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
byte
[]
descriptorData
=
global
::
System
.
Convert
.
FromBase64String
(
byte
[]
descriptorData
=
global
::
System
.
Convert
.
FromBase64String
(
"CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb2ds"
+
"CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb2ds"
+
"ZS5wcm90b2J1ZhogZ29vZ2xlL3Byb3RvYnVmL2Rlc2NyaXB0b3IucHJvdG8i"
+
"ZS5wcm90b2J1ZhogZ29vZ2xlL3Byb3RvYnVmL2Rlc2NyaXB0b3IucHJvdG8i"
+
"6
gE
KEUNTaGFycEZpbGVPcHRpb25zEhEKCW5hbWVzcGFjZRgBIAEoCRIaChJ1"
+
"6
wI
KEUNTaGFycEZpbGVPcHRpb25zEhEKCW5hbWVzcGFjZRgBIAEoCRIaChJ1"
+
"bWJyZWxsYV9jbGFzc25hbWUYAiABKAkSHAoOcHVibGljX2NsYXNzZXMYAyAB"
+
"bWJyZWxsYV9jbGFzc25hbWUYAiABKAkSHAoOcHVibGljX2NsYXNzZXMYAyAB"
+
"KAg6BHRydWUSFgoObXVsdGlwbGVfZmlsZXMYBCABKAgSFAoMbmVzdF9jbGFz"
+
"KAg6BHRydWUSFgoObXVsdGlwbGVfZmlsZXMYBCABKAgSFAoMbmVzdF9jbGFz"
+
"c2VzGAUgASgIEhYKDmNvZGVfY29udHJhY3RzGAYgASgIEiQKHGV4cGFuZF9u"
+
"c2VzGAUgASgIEhYKDmNvZGVfY29udHJhY3RzGAYgASgIEiQKHGV4cGFuZF9u"
+
"YW1lc3BhY2VfZGlyZWN0b3JpZXMYByABKAgSHAoOY2xzX2NvbXBsaWFuY2UY"
+
"YW1lc3BhY2VfZGlyZWN0b3JpZXMYByABKAgSHAoOY2xzX2NvbXBsaWFuY2UY"
+
"CCABKAg6BHRydWUiKwoSQ1NoYXJwRmllbGRPcHRpb25zEhUKDXByb3BlcnR5"
+
"CCABKAg6BHRydWUSHAoOZmlsZV9leHRlbnNpb24Y3QEgASgJOgMuY3MSGwoS"
+
"X25hbWUYASABKAk6XgoTY3NoYXJwX2ZpbGVfb3B0aW9ucxIcLmdvb2dsZS5w"
+
"dW1icmVsbGFfbmFtZXNwYWNlGN4BIAEoCRIcChBvdXRwdXRfZGlyZWN0b3J5"
+
"cm90b2J1Zi5GaWxlT3B0aW9ucxjoByABKAsyIi5nb29nbGUucHJvdG9idWYu"
+
"GN8BIAEoCToBLhImChZpZ25vcmVfZ29vZ2xlX3Byb3RvYnVmGOABIAEoCDoF"
+
"Q1NoYXJwRmlsZU9wdGlvbnM6YQoUY3NoYXJwX2ZpZWxkX29wdGlvbnMSHS5n"
+
"ZmFsc2UiKwoSQ1NoYXJwRmllbGRPcHRpb25zEhUKDXByb3BlcnR5X25hbWUY"
+
"b29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zGOgHIAEoCzIjLmdvb2dsZS5w"
+
"ASABKAk6XgoTY3NoYXJwX2ZpbGVfb3B0aW9ucxIcLmdvb2dsZS5wcm90b2J1"
+
"cm90b2J1Zi5DU2hhcnBGaWVsZE9wdGlvbnM="
);
"Zi5GaWxlT3B0aW9ucxjoByABKAsyIi5nb29nbGUucHJvdG9idWYuQ1NoYXJw"
+
"RmlsZU9wdGlvbnM6YQoUY3NoYXJwX2ZpZWxkX29wdGlvbnMSHS5nb29nbGUu"
+
"cHJvdG9idWYuRmllbGRPcHRpb25zGOgHIAEoCzIjLmdvb2dsZS5wcm90b2J1"
+
"Zi5DU2hhcnBGaWVsZE9wdGlvbnM="
);
pbd
::
FileDescriptor
.
InternalDescriptorAssigner
assigner
=
delegate
(
pbd
::
FileDescriptor
root
)
{
pbd
::
FileDescriptor
.
InternalDescriptorAssigner
assigner
=
delegate
(
pbd
::
FileDescriptor
root
)
{
descriptor
=
root
;
descriptor
=
root
;
internal__static_google_protobuf_CSharpFileOptions__Descriptor
=
Descriptor
.
MessageTypes
[
0
];
internal__static_google_protobuf_CSharpFileOptions__Descriptor
=
Descriptor
.
MessageTypes
[
0
];
internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable
=
internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFileOptions__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFileOptions__Descriptor
,
new
string
[]
{
"Namespace"
,
"UmbrellaClassname"
,
"PublicClasses"
,
"MultipleFiles"
,
"NestClasses"
,
"CodeContracts"
,
"ExpandNamespaceDirectories"
,
"ClsCompliance"
,
});
new
string
[]
{
"Namespace"
,
"UmbrellaClassname"
,
"PublicClasses"
,
"MultipleFiles"
,
"NestClasses"
,
"CodeContracts"
,
"ExpandNamespaceDirectories"
,
"ClsCompliance"
,
"FileExtension"
,
"UmbrellaNamespace"
,
"OutputDirectory"
,
"IgnoreGoogleProtobuf"
,
});
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
=
Descriptor
.
MessageTypes
[
1
];
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
=
Descriptor
.
MessageTypes
[
1
];
internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable
=
internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
,
...
@@ -173,6 +176,46 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -173,6 +176,46 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
get
{
return
clsCompliance_
;
}
get
{
return
clsCompliance_
;
}
}
}
public
const
int
FileExtensionFieldNumber
=
221
;
private
bool
hasFileExtension
;
private
string
fileExtension_
=
".cs"
;
public
bool
HasFileExtension
{
get
{
return
hasFileExtension
;
}
}
public
string
FileExtension
{
get
{
return
fileExtension_
;
}
}
public
const
int
UmbrellaNamespaceFieldNumber
=
222
;
private
bool
hasUmbrellaNamespace
;
private
string
umbrellaNamespace_
=
""
;
public
bool
HasUmbrellaNamespace
{
get
{
return
hasUmbrellaNamespace
;
}
}
public
string
UmbrellaNamespace
{
get
{
return
umbrellaNamespace_
;
}
}
public
const
int
OutputDirectoryFieldNumber
=
223
;
private
bool
hasOutputDirectory
;
private
string
outputDirectory_
=
"."
;
public
bool
HasOutputDirectory
{
get
{
return
hasOutputDirectory
;
}
}
public
string
OutputDirectory
{
get
{
return
outputDirectory_
;
}
}
public
const
int
IgnoreGoogleProtobufFieldNumber
=
224
;
private
bool
hasIgnoreGoogleProtobuf
;
private
bool
ignoreGoogleProtobuf_
=
false
;
public
bool
HasIgnoreGoogleProtobuf
{
get
{
return
hasIgnoreGoogleProtobuf
;
}
}
public
bool
IgnoreGoogleProtobuf
{
get
{
return
ignoreGoogleProtobuf_
;
}
}
public
override
bool
IsInitialized
{
public
override
bool
IsInitialized
{
get
{
get
{
return
true
;
return
true
;
...
@@ -205,6 +248,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -205,6 +248,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
HasClsCompliance
)
{
if
(
HasClsCompliance
)
{
output
.
WriteBool
(
8
,
ClsCompliance
);
output
.
WriteBool
(
8
,
ClsCompliance
);
}
}
if
(
HasFileExtension
)
{
output
.
WriteString
(
221
,
FileExtension
);
}
if
(
HasUmbrellaNamespace
)
{
output
.
WriteString
(
222
,
UmbrellaNamespace
);
}
if
(
HasOutputDirectory
)
{
output
.
WriteString
(
223
,
OutputDirectory
);
}
if
(
HasIgnoreGoogleProtobuf
)
{
output
.
WriteBool
(
224
,
IgnoreGoogleProtobuf
);
}
UnknownFields
.
WriteTo
(
output
);
UnknownFields
.
WriteTo
(
output
);
}
}
...
@@ -239,6 +294,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -239,6 +294,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
HasClsCompliance
)
{
if
(
HasClsCompliance
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeBoolSize
(
8
,
ClsCompliance
);
size
+=
pb
::
CodedOutputStream
.
ComputeBoolSize
(
8
,
ClsCompliance
);
}
}
if
(
HasFileExtension
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
221
,
FileExtension
);
}
if
(
HasUmbrellaNamespace
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
222
,
UmbrellaNamespace
);
}
if
(
HasOutputDirectory
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
223
,
OutputDirectory
);
}
if
(
HasIgnoreGoogleProtobuf
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeBoolSize
(
224
,
IgnoreGoogleProtobuf
);
}
size
+=
UnknownFields
.
SerializedSize
;
size
+=
UnknownFields
.
SerializedSize
;
memoizedSerializedSize
=
size
;
memoizedSerializedSize
=
size
;
return
size
;
return
size
;
...
@@ -355,6 +422,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -355,6 +422,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
HasClsCompliance
)
{
if
(
other
.
HasClsCompliance
)
{
ClsCompliance
=
other
.
ClsCompliance
;
ClsCompliance
=
other
.
ClsCompliance
;
}
}
if
(
other
.
HasFileExtension
)
{
FileExtension
=
other
.
FileExtension
;
}
if
(
other
.
HasUmbrellaNamespace
)
{
UmbrellaNamespace
=
other
.
UmbrellaNamespace
;
}
if
(
other
.
HasOutputDirectory
)
{
OutputDirectory
=
other
.
OutputDirectory
;
}
if
(
other
.
HasIgnoreGoogleProtobuf
)
{
IgnoreGoogleProtobuf
=
other
.
IgnoreGoogleProtobuf
;
}
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -419,6 +498,22 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -419,6 +498,22 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
ClsCompliance
=
input
.
ReadBool
();
ClsCompliance
=
input
.
ReadBool
();
break
;
break
;
}
}
case
1770
:
{
FileExtension
=
input
.
ReadString
();
break
;
}
case
1778
:
{
UmbrellaNamespace
=
input
.
ReadString
();
break
;
}
case
1786
:
{
OutputDirectory
=
input
.
ReadString
();
break
;
}
case
1792
:
{
IgnoreGoogleProtobuf
=
input
.
ReadBool
();
break
;
}
}
}
}
}
}
}
...
@@ -569,6 +664,81 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -569,6 +664,81 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
result
.
clsCompliance_
=
true
;
result
.
clsCompliance_
=
true
;
return
this
;
return
this
;
}
}
public
bool
HasFileExtension
{
get
{
return
result
.
HasFileExtension
;
}
}
public
string
FileExtension
{
get
{
return
result
.
FileExtension
;
}
set
{
SetFileExtension
(
value
);
}
}
public
Builder
SetFileExtension
(
string
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
result
.
hasFileExtension
=
true
;
result
.
fileExtension_
=
value
;
return
this
;
}
public
Builder
ClearFileExtension
()
{
result
.
hasFileExtension
=
false
;
result
.
fileExtension_
=
".cs"
;
return
this
;
}
public
bool
HasUmbrellaNamespace
{
get
{
return
result
.
HasUmbrellaNamespace
;
}
}
public
string
UmbrellaNamespace
{
get
{
return
result
.
UmbrellaNamespace
;
}
set
{
SetUmbrellaNamespace
(
value
);
}
}
public
Builder
SetUmbrellaNamespace
(
string
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
result
.
hasUmbrellaNamespace
=
true
;
result
.
umbrellaNamespace_
=
value
;
return
this
;
}
public
Builder
ClearUmbrellaNamespace
()
{
result
.
hasUmbrellaNamespace
=
false
;
result
.
umbrellaNamespace_
=
""
;
return
this
;
}
public
bool
HasOutputDirectory
{
get
{
return
result
.
HasOutputDirectory
;
}
}
public
string
OutputDirectory
{
get
{
return
result
.
OutputDirectory
;
}
set
{
SetOutputDirectory
(
value
);
}
}
public
Builder
SetOutputDirectory
(
string
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
result
.
hasOutputDirectory
=
true
;
result
.
outputDirectory_
=
value
;
return
this
;
}
public
Builder
ClearOutputDirectory
()
{
result
.
hasOutputDirectory
=
false
;
result
.
outputDirectory_
=
"."
;
return
this
;
}
public
bool
HasIgnoreGoogleProtobuf
{
get
{
return
result
.
HasIgnoreGoogleProtobuf
;
}
}
public
bool
IgnoreGoogleProtobuf
{
get
{
return
result
.
IgnoreGoogleProtobuf
;
}
set
{
SetIgnoreGoogleProtobuf
(
value
);
}
}
public
Builder
SetIgnoreGoogleProtobuf
(
bool
value
)
{
result
.
hasIgnoreGoogleProtobuf
=
true
;
result
.
ignoreGoogleProtobuf_
=
value
;
return
this
;
}
public
Builder
ClearIgnoreGoogleProtobuf
()
{
result
.
hasIgnoreGoogleProtobuf
=
false
;
result
.
ignoreGoogleProtobuf_
=
false
;
return
this
;
}
}
}
static
CSharpFileOptions
()
{
static
CSharpFileOptions
()
{
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpOptions
.
Descriptor
,
null
);
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpOptions
.
Descriptor
,
null
);
...
...
src/ProtocolBuffers/Descriptors/FileDescriptor.cs
View file @
c58ce5dc
...
@@ -73,21 +73,36 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -73,21 +73,36 @@ namespace Google.ProtocolBuffers.Descriptors {
(
field
,
index
)
=>
new
FieldDescriptor
(
field
,
this
,
null
,
index
,
true
));
(
field
,
index
)
=>
new
FieldDescriptor
(
field
,
this
,
null
,
index
,
true
));
}
}
private
CSharpFileOptions
BuildOrFakeCSharpOptions
()
{
// TODO(jonskeet): Check if we could use FileDescriptorProto.Descriptor.Name - interesting bootstrap issues
/// <summary>
if
(
proto
.
Name
==
"google/protobuf/descriptor.proto"
)
{
/// ROK - Added to allow the GeneratorOptions to sepcify the default for any or all of these values
return
new
CSharpFileOptions
.
Builder
{
/// </summary>
Namespace
=
"Google.ProtocolBuffers.DescriptorProtos"
,
internal
void
ConfigureWithDefaultOptions
(
CSharpFileOptions
options
)
UmbrellaClassname
=
"DescriptorProtoFile"
,
NestClasses
=
false
,
MultipleFiles
=
false
,
PublicClasses
=
true
{
}.
Build
();
csharpFileOptions
=
BuildOrFakeWithDefaultOptions
(
options
);
}
}
if
(
proto
.
Name
==
"google/protobuf/csharp_options.proto"
)
{
private
CSharpFileOptions
BuildOrFakeWithDefaultOptions
(
CSharpFileOptions
defaultOptions
)
return
new
CSharpFileOptions
.
Builder
{
{
Namespace
=
"Google.ProtocolBuffers.DescriptorProtos"
,
// ROK 2010-09-03 - fix for being able to relocate these files to any directory structure
UmbrellaClassname
=
"CSharpOptions"
,
NestClasses
=
false
,
MultipleFiles
=
false
,
PublicClasses
=
true
if
(
proto
.
Package
==
"google.protobuf"
)
{
}.
Build
();
string
filename
=
System
.
IO
.
Path
.
GetFileName
(
proto
.
Name
);
}
// TODO(jonskeet): Check if we could use FileDescriptorProto.Descriptor.Name - interesting bootstrap issues)
CSharpFileOptions
.
Builder
builder
=
CSharpFileOptions
.
CreateBuilder
();
if
(
filename
==
"descriptor.proto"
)
{
return
new
CSharpFileOptions
.
Builder
{
Namespace
=
"Google.ProtocolBuffers.DescriptorProtos"
,
UmbrellaClassname
=
"DescriptorProtoFile"
,
NestClasses
=
false
,
MultipleFiles
=
false
,
PublicClasses
=
true
,
OutputDirectory
=
defaultOptions
.
OutputDirectory
,
IgnoreGoogleProtobuf
=
defaultOptions
.
IgnoreGoogleProtobuf
}.
Build
();
}
if
(
filename
==
"csharp_options.proto"
)
{
return
new
CSharpFileOptions
.
Builder
{
Namespace
=
"Google.ProtocolBuffers.DescriptorProtos"
,
UmbrellaClassname
=
"CSharpOptions"
,
NestClasses
=
false
,
MultipleFiles
=
false
,
PublicClasses
=
true
,
OutputDirectory
=
defaultOptions
.
OutputDirectory
,
IgnoreGoogleProtobuf
=
defaultOptions
.
IgnoreGoogleProtobuf
}.
Build
();
}
}
CSharpFileOptions
.
Builder
builder
=
defaultOptions
.
ToBuilder
();
if
(
proto
.
Options
.
HasExtension
(
DescriptorProtos
.
CSharpOptions
.
CSharpFileOptions
))
{
if
(
proto
.
Options
.
HasExtension
(
DescriptorProtos
.
CSharpOptions
.
CSharpFileOptions
))
{
builder
.
MergeFrom
(
proto
.
Options
.
GetExtension
(
DescriptorProtos
.
CSharpOptions
.
CSharpFileOptions
));
builder
.
MergeFrom
(
proto
.
Options
.
GetExtension
(
DescriptorProtos
.
CSharpOptions
.
CSharpFileOptions
));
}
}
...
@@ -99,6 +114,21 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -99,6 +114,21 @@ namespace Google.ProtocolBuffers.Descriptors {
string
baseName
=
Name
.
Substring
(
lastSlash
+
1
);
string
baseName
=
Name
.
Substring
(
lastSlash
+
1
);
builder
.
UmbrellaClassname
=
NameHelpers
.
UnderscoresToPascalCase
(
NameHelpers
.
StripProto
(
baseName
));
builder
.
UmbrellaClassname
=
NameHelpers
.
UnderscoresToPascalCase
(
NameHelpers
.
StripProto
(
baseName
));
}
}
// ROK 2010-09-03 - auto fix for name collision by placing umbrella class into a new namespace. This
// still won't fix the collisions with nesting enabled; however, you have to turn that on so whatever.
if
(!
builder
.
NestClasses
&&
!
builder
.
HasUmbrellaNamespace
)
{
bool
collision
=
false
;
foreach
(
IDescriptor
d
in
MessageTypes
)
collision
|=
d
.
Name
==
builder
.
UmbrellaClassname
;
foreach
(
IDescriptor
d
in
Services
)
collision
|=
d
.
Name
==
builder
.
UmbrellaClassname
;
foreach
(
IDescriptor
d
in
EnumTypes
)
collision
|=
d
.
Name
==
builder
.
UmbrellaClassname
;
if
(
collision
)
builder
.
UmbrellaNamespace
=
"Proto"
;
}
return
builder
.
Build
();
return
builder
.
Build
();
}
}
...
@@ -124,7 +154,7 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -124,7 +154,7 @@ namespace Google.ProtocolBuffers.Descriptors {
get
{
get
{
lock
(
optionsLock
)
{
lock
(
optionsLock
)
{
if
(
csharpFileOptions
==
null
)
{
if
(
csharpFileOptions
==
null
)
{
csharpFileOptions
=
BuildOrFake
CSharpOptions
(
);
csharpFileOptions
=
BuildOrFake
WithDefaultOptions
(
CSharpFileOptions
.
DefaultInstance
);
}
}
}
}
return
csharpFileOptions
;
return
csharpFileOptions
;
...
...
todo.txt
View file @
c58ce5dc
Work complete on csharptest/branch
New Options (in csharp_options.proto):
1 - Add a way to specify the output directory
Added an option to csharp_options.proto called "output_directory", defaults to "."
2 - Added an option "file_extension" to control the suffix for cs files generated, defaults to ".cs"
This enables using ".Generated.cs" to provide easy filtering and cleanup of generated code.
3 - Added the option for "umbrella_namespace" used when nest_classes=false and having name conflicts
4 - Optionally remove dependencies to csharp options
provided option "ignore_google_protobuf" to prevent generation of code for csharp_options.proto and descriptor.proto
option also relaxes the contraint of having either of these compiled into the proto buffer input
5 - Investigate command line parsing library
All proto options for csharp_options.proto can now be provided via the command-line by using the following format:
/option=value or -option:value
i.e. use /namespace=My.Name.Space
6 - Investigate calling protoc directly
ProgramPreprocess.cs - input files with an extension of '.proto' by running protoc.exe. If arguments
are supplied with '--' prefix they are provided to protoc.exe, otherwise they are assumed to
be used for ProtoGen.exe which is run on the resulting output proto buffer. If the option
--descriptor_set_out= is specified the proto buffer file is kept, otherwise it will be removed
after code generation.
7 - Unable to resolve dependencies correctly
Fixed an issue where two or more proto-buffers are provided to protogen.exe that depend on types
defined in one-another. The dependency walker of the generator was not taking into account all
inputs when evaluating the descriptor's existence.
8 - Added several (20) nunits to automate the command-line invocation of each option and ensured the
generated code compiles into a working assembly and contains some of the expected types. Not sure
how to disable this test for mono, I'm certain it will not work; however, I still believe it's worth
having. As a side-benefit from testing the command-line options, it verifies behavior of each
setting in csharp_options (save for multi-file).
Current task list (not in order)
Current task list (not in order)
-
Optionally remove dependencies to csharp options
?
Optionally remove dependencies to csharp options
- Remove multifile support
- Remove multifile support
- Docs
- Docs
- Clean up protogen code
- Clean up protogen code
-
Add flags to protogen
X
Add flags to protogen
- Avoid using reflection for messages which don't need it (is this
- Avoid using reflection for messages which don't need it (is this
possible?)
possible?)
- Bring service generation into line with Java
- Bring service generation into line with Java
...
@@ -14,7 +53,7 @@ Current task list (not in order)
...
@@ -14,7 +53,7 @@ Current task list (not in order)
- Reformat code
- Reformat code
- Change generated format
- Change generated format
- Add regions to copyright
- Add regions to copyright
-
Investigate command line parsing library
X
Investigate command line parsing library
-
Investigate calling protoc directly
X
Investigate calling protoc directly
- Build and publish binaries
- Build and publish binaries
- Work out why the Compact Framework 3.5 build fails under VS2010
- Work out why the Compact Framework 3.5 build fails under VS2010
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment