@@ -24,6 +24,10 @@ namespace Google.Api.Generator.Tests
2424{
2525 internal static class Invoker
2626 {
27+ const string ProtocFileStr = "ProtocFile" ;
28+ const string RuntimeStr = "Runtime" ;
29+ const string PluginFileStr = "PluginFile" ;
30+
2731 public class WithPath : IDisposable
2832 {
2933 public WithPath ( Action action , string path ) => ( _action , Path ) = ( action , path ) ;
@@ -38,11 +42,13 @@ static Invoker()
3842 RootDir = PathUtils . GetRepoRoot ( ) ;
3943 GeneratorDir = Path . Combine ( RootDir , "Google.Api.Generator" ) ;
4044 GeneratorTestsDir = Path . Combine ( RootDir , "Google.Api.Generator.Tests" ) ;
41- var isWindows = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
42- ProtocFile = Path . Combine ( RootDir , "tools" , isWindows ? "protoc.exe" : "protoc" ) ;
43- Runtime = isWindows ? "win-x64" : "linux-x64" ;
44- PluginFile = Path . Combine ( GeneratorDir , "bin" , "Debug" , "net6.0" , Runtime , "publish" ,
45- isWindows ? "Google.Api.Generator.exe" : "Google.Api.Generator" ) ;
45+
46+ // Fetch OS dependent executable paths and other configs
47+ var OSConfigs = GetOSSpecificConfigs ( RootDir ) ;
48+ ProtocFile = OSConfigs [ "ProtocFile" ] ;
49+ Runtime = OSConfigs [ "Runtime" ] ;
50+ PluginFile = OSConfigs [ "PluginFile" ] ;
51+
4652 CommonProtosDir = Path . Combine ( RootDir , "googleapis" ) ;
4753 ProtobufDir = Path . Combine ( RootDir , "tools" , "protos" ) ;
4854 var now = DateTime . UtcNow ;
@@ -92,7 +98,7 @@ private static void Execute(string executable, string args, string workingDirect
9298 process . OutputDataReceived += handler ;
9399 process . BeginErrorReadLine ( ) ;
94100 process . BeginOutputReadLine ( ) ;
95- var exited = process . WaitForExit ( ( int ) timeout . TotalMilliseconds ) ;
101+ var exited = process . WaitForExit ( ( int ) timeout . TotalMilliseconds ) ;
96102
97103 // Avoid any extra data being added to our output while we're processing assertions.
98104 process . ErrorDataReceived -= handler ;
@@ -128,5 +134,35 @@ public static WithPath TempDir()
128134 Directory . CreateDirectory ( dirPath ) ;
129135 return new WithPath ( ( ) => Directory . Delete ( dirPath , recursive : true ) , dirPath ) ;
130136 }
137+
138+ private static Dictionary < string , string > GetOSSpecificConfigs ( string rootDir )
139+ {
140+ Dictionary < string , string > configs = new Dictionary < string , string > ( ) ;
141+
142+
143+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
144+ {
145+ // Linux configs
146+ configs [ ProtocFileStr ] = Path . Combine ( RootDir , "tools" , "protoc" ) ;
147+ configs [ RuntimeStr ] = "linux-x64" ;
148+ configs [ PluginFileStr ] = Path . Combine ( GeneratorDir , "bin" , "Debug" , "net6.0" , configs [ RuntimeStr ] , "publish" , "Google.Api.Generator" ) ;
149+ }
150+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
151+ {
152+ // MacOS configs
153+ configs [ ProtocFileStr ] = Path . Combine ( RootDir , "tools" , "protoc_macosx_x64" ) ;
154+ configs [ RuntimeStr ] = "osx-x64" ;
155+ configs [ PluginFileStr ] = Path . Combine ( GeneratorDir , "bin" , "Debug" , "net6.0" , configs [ RuntimeStr ] , "publish" , "Google.Api.Generator" ) ;
156+ }
157+ else
158+ {
159+ // Default to Windows configs
160+ configs [ ProtocFileStr ] = Path . Combine ( RootDir , "tools" , "protoc.exe" ) ;
161+ configs [ RuntimeStr ] = "win-x64" ;
162+ configs [ PluginFileStr ] = Path . Combine ( GeneratorDir , "bin" , "Debug" , "net6.0" , configs [ RuntimeStr ] , "publish" , "Google.Api.Generator.exe" ) ;
163+ }
164+
165+ return configs ;
166+ }
131167 }
132168}
0 commit comments