1 #region Copyright notice and license 2 3 // Copyright 2018 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #endregion 18 19 using Microsoft.Build.Framework; 20 using Microsoft.Build.Utilities; 21 22 namespace Grpc.Tools 23 { 24 /// <summary> 25 /// A helper task to resolve actual OS type and bitness. 26 /// </summary> 27 public class ProtoToolsPlatform : Task 28 { 29 /// <summary> 30 /// Return one of 'linux', 'macosx' or 'windows'. 31 /// If the OS is unknown, the property is not set. 32 /// </summary> 33 [Output] 34 public string Os { get; set; } 35 36 /// <summary> 37 /// Return one of 'x64' or 'x86'. 38 /// If the CPU is unknown, the property is not set. 39 /// </summary> 40 [Output] 41 public string Cpu { get; set; } 42 43 Execute()44 public override bool Execute() 45 { 46 switch (Platform.Os) 47 { 48 case Platform.OsKind.Linux: Os = "linux"; break; 49 case Platform.OsKind.MacOsX: Os = "macosx"; break; 50 case Platform.OsKind.Windows: Os = "windows"; break; 51 default: Os = ""; break; 52 } 53 54 switch (Platform.Cpu) 55 { 56 case Platform.CpuKind.X86: Cpu = "x86"; break; 57 case Platform.CpuKind.X64: Cpu = "x64"; break; 58 default: Cpu = ""; break; 59 } 60 return true; 61 } 62 }; 63 } 64