Exemple #1
0
        //public string[] ToCommonSpec(ServiceSpec spec, string dir)
        //{
        //    throw new NotImplementedException();

        //}

        //public ServiceSpec FromCommonSpec(string spec, ServiceSpecType targetType)
        //{
        //    var generator = IdlGenerator.GetInstance(targetType);
        //    Assembly asm = Assembly.LoadFrom(spec);
        //    generator.Generate(asm);
        //    ServiceSpec serviceSpec = new ServiceSpec();
        //    // FIXME
        //    serviceSpec.SType = targetType;
        //    serviceSpec.Directory = ".";
        //    serviceSpec.MainSpecFile = "";
        //    serviceSpec.ReferencedSpecFiles = null;
        //    return serviceSpec;
        //}


        public FlowErrorCode GenerateServiceClient(
            ServiceSpec spec,
            string dir,
            ClientLanguage lang,
            ClientPlatform platform,
            out LinkageInfo linkInfo
            )
        {
            if (!spec.IsRdsnRpc)
            {
                throw new NotImplementedException();
            }
            linkInfo = new LinkageInfo();
            var appName = Path.GetFileNameWithoutExtension(spec.MainSpecFile);

            if (
                SystemHelper.RunProcess("php.exe",
                                        Path.Combine(Environment.GetEnvironmentVariable("DSN_ROOT"), "bin/dsn.generate_code.php") + " " +
                                        Path.Combine(spec.Directory, spec.MainSpecFile) + " csharp " + dir + " binary layer3") != 0)
            {
                return(FlowErrorCode.ProcessStartFailed);
            }
            linkInfo.Sources.Add(Path.Combine(dir, "GProtoBinaryHelper.cs"));
            linkInfo.Sources.Add(Path.Combine(dir, appName + ".cs"));
            linkInfo.Sources.Add(Path.Combine(dir, appName + ".client.cs"));
            linkInfo.Sources.Add(Path.Combine(dir, appName + ".code.definition.cs"));
            linkInfo.DynamicLibraries.Add(Path.Combine(Environment.GetEnvironmentVariable("DSN_ROOT"), "lib", "Google.Protobuf.dll"));
            linkInfo.DynamicLibraries.Add(Path.Combine("System.IO.dll"));
            linkInfo.DynamicLibraries.Add(Path.Combine("System.runtime.dll"));
            return(FlowErrorCode.Success);
        }
Exemple #2
0
 public FlowErrorCode GenerateServiceSketch(
     ServiceSpec spec,
     string dir,
     ClientLanguage lang,
     ClientPlatform platform,
     out LinkageInfo linkInfo
     )
 {
     linkInfo = null;
     return(FlowErrorCode.Success);
 }
Exemple #3
0
        //public string[] ToCommonSpec(ServiceSpec spec, string dir)
        //{
        //    var translator = IdlTranslator.GetInstance(GetType());
        //    var inputDir = spec.Directory;
        //    var file = spec.MainSpecFile;
        //    var outDir = dir;
        //    var args = new List<string>
        //    {
        //        "-out " + outDir,
        //        "-r" // recursively generate all included files
        //    };
        //    if (!translator.ToCommonInterface(inputDir, file, outDir, args)) return null;
        //    const int threshhold = 30; // filter the .cs files by their LastWriteTimes
        //    var output = SystemHelper.GetFilesByLastWrite(outDir, "*_common.cs", SearchOption.TopDirectoryOnly, threshhold);
        //    return output.ToArray();
        //}

        private static FlowErrorCode GenerateRdsnClient(ServiceSpec spec, string dir, out LinkageInfo linkinfo)
        {
            linkinfo = new LinkageInfo();
            var appName = Path.GetFileNameWithoutExtension(spec.MainSpecFile);

            if (
                SystemHelper.RunProcess("php.exe",
                                        Path.Combine(Environment.GetEnvironmentVariable("DSN_ROOT"), "bin/dsn.generate_code.php") + " " +
                                        Path.Combine(spec.Directory, spec.MainSpecFile) + " csharp " + dir + " json layer3") != 0)
            {
                return(FlowErrorCode.ProcessStartFailed);
            }
            var thriftGenPath = Path.Combine(dir, "thrift");

            linkinfo.Sources.Add(Path.Combine(dir, "ThriftJsonHelper.cs"));
            linkinfo.Sources.Add(Path.Combine(dir, appName + ".client.cs"));
            linkinfo.Sources.Add(Path.Combine(dir, appName + ".code.definition.cs"));
            linkinfo.Sources.AddRange(Directory.GetFiles(thriftGenPath, "*.cs", SearchOption.AllDirectories));
            return(FlowErrorCode.Success);
        }
Exemple #4
0
        public FlowErrorCode GenerateServiceClient(
            ServiceSpec spec,
            string dir,
            ClientLanguage lang,
            ClientPlatform platform,
            out LinkageInfo linkInfo
            )
        {
            if (spec.IsRdsnRpc)
            {
                return(GenerateRdsnClient(spec, dir, out linkInfo));
            }

            var compiler = LanguageHelper.GetCompilerPath(GetType(), platform);

            linkInfo = new LinkageInfo();
            if (compiler == "")
            {
                return(FlowErrorCode.SpecCompilerNotFound);
            }


            var arguments    = new List <string>();
            var languageName = GetLanguageName(lang);

            arguments.Add(" ");
            arguments.Add("--" + languageName);
            arguments.Add("-r");
            arguments.Add("-out " + dir);
            arguments.Add(Path.Combine(spec.Directory, spec.MainSpecFile));
            if (SystemHelper.RunProcess(compiler, string.Join(" ", arguments)) != 0)
            {
                return(FlowErrorCode.ExceptionError);
            }
            // generally, thrift.exe will generate a folder in the name of the mainspec's namespace to the output dir,e.g. gen-csharp
            // all language libraries are availabe in the source code of thrift project, placed in the thrift\\lib\\{language} dir
            // in Tron project, we place thrift compiler at "external\\thrift\\bin", and place the libraries in at"external\\thrift\\lib\\{language}"
            switch (lang)
            {
            case ClientLanguage.Client_CSharp:
            {
                var sourceDir = Path.Combine(dir, "gen-" + languageName);
                linkInfo.IncludeDirectories.Add(sourceDir);
                linkInfo.LibraryPaths.Add(Path.Combine(Directory.GetParent(compiler).FullName, "lib\\csharp"));
                linkInfo.LibraryPaths.Add(dir);

                linkInfo.DynamicLibraries.AddRange(new List <string>
                    {
                        "Thrift.dll"
                    });
                var searchPattern = "*." + LanguageHelper.GetSourceExtension(lang);
                linkInfo.Sources.AddRange(SystemHelper.GetFilesByLastWrite(sourceDir, searchPattern, SearchOption.AllDirectories, 15).Select(Path.GetFileName));
                break;
            }

            case ClientLanguage.Client_CPlusPlus:
            {
                var sourceDir = Path.Combine(dir, "gen-" + languageName);
                linkInfo.IncludeDirectories.Add(sourceDir);
                linkInfo.LibraryPaths.Add(sourceDir);
                linkInfo.LibraryPaths.Add(Path.Combine(Directory.GetParent(compiler).FullName, "lib\\cpp"));
                var searchPattern = "*." + LanguageHelper.GetSourceExtension(lang);
                linkInfo.Sources.AddRange(SystemHelper.GetFilesByLastWrite(sourceDir, searchPattern, SearchOption.AllDirectories, 15));
                break;
            }

            case ClientLanguage.Client_Java:
            {
                var sourceDir = Path.Combine(dir, "gen-" + languageName);
                linkInfo.IncludeDirectories.Add(sourceDir);
                linkInfo.LibraryPaths.Add(sourceDir);
                linkInfo.LibraryPaths.Add(Path.Combine(Directory.GetParent(compiler).FullName, "lib\\java"));
                var searchPattern = "*." + LanguageHelper.GetSourceExtension(lang);
                linkInfo.Sources.AddRange(SystemHelper.GetFilesByLastWrite(sourceDir, searchPattern, SearchOption.AllDirectories, 15));
                break;
            }

            default:
                break;
            }

            return(FlowErrorCode.Success);
        }
Exemple #5
0
        public FlowErrorCode GenerateServiceSketch(
            ServiceSpec spec,
            string dir,
            ClientLanguage lang,
            ClientPlatform platform,
            out LinkageInfo linkInfo
            )
        {
            var compiler = LanguageHelper.GetCompilerPath(GetType());

            linkInfo = new LinkageInfo();
            if (compiler == "")
            {
                return(FlowErrorCode.SpecCompilerNotFound);
            }

            if (platform != ClientPlatform.Windows)
            {
                Console.WriteLine("Bond compiler only supports windows platform!");
                return(FlowErrorCode.PlatformNotSupported);
            }


            // hack for C# for the time being
            if (lang == ClientLanguage.Client_CSharp)
            {
                linkInfo.IncludeDirectories.Add(dir);
                linkInfo.LibraryPaths.Add(Directory.GetParent(compiler).FullName);
                linkInfo.LibraryPaths.Add(dir);

                linkInfo.DynamicLibraries.AddRange(new List <string>()
                {
                    "Microsoft.Bond.dll",
                    "Microsoft.Bond.Rpc.dll",
                    "Microsoft.Bond.Interfaces.dll",
                    "Microsoft.Bond.TypeProvider.dll",
                });
                linkInfo.Sources = FromAllSpecToSources(
                    Path.Combine(spec.Directory, spec.MainSpecFile),
                    spec.ReferencedSpecFiles.Select(rs => Path.Combine(spec.Directory, rs)),
                    dir,
                    new[] { GeneratedFileType.TYPES, GeneratedFileType.SERVICES },
                    new[] { GeneratedFileType.TYPES }
                    )
                                   .Select(Path.GetFileName)
                                   .ToList();

                return(FlowErrorCode.Success);
            }


            var arguments = new List <string>
            {
                " ",
                "/" + GetLanguageName(lang),
                "/I:" + spec.Directory,
                "/O:" + dir,
                Path.Combine(spec.Directory, spec.MainSpecFile)
            };



            if (SystemHelper.RunProcess(compiler, string.Join(" ", arguments)) == 0)
            {
                switch (lang)
                {
                case ClientLanguage.Client_CSharp:
                {
                    linkInfo.IncludeDirectories.Add(dir);
                    linkInfo.LibraryPaths.Add(Directory.GetParent(compiler).FullName);
                    linkInfo.LibraryPaths.Add(dir);

                    linkInfo.DynamicLibraries.AddRange(new List <string>()
                        {
                            "Microsoft.Bond.dll",
                            "Microsoft.Bond.Rpc.dll",
                            "Microsoft.Bond.Interfaces.dll",
                            "Microsoft.Bond.TypeProvider.dll",
                        });
                    var specName      = Path.GetFileNameWithoutExtension(spec.MainSpecFile);
                    var searchPattern = specName + "_*." + LanguageHelper.GetSourceExtension(lang);
                    linkInfo.Sources.AddRange(SystemHelper.GetFilesByLastWrite(dir, searchPattern, SearchOption.AllDirectories, 15).Select(Path.GetFileName));
                    break;
                }

                case ClientLanguage.Client_CPlusPlus:
                {
                    var bondHeaders = Path.GetPathRoot(compiler);
                    linkInfo.IncludeDirectories.Add(dir);
                    linkInfo.IncludeDirectories.Add(bondHeaders);
                    var searchPattern = "*." + LanguageHelper.GetSourceExtension(lang);
                    linkInfo.Sources.AddRange(SystemHelper.GetFilesByLastWrite(dir, searchPattern, SearchOption.AllDirectories, 15));
                    break;
                }

                case ClientLanguage.Client_Java:
                {
                    // FIXME: when generate java code, bondc will generate a subdir
                    linkInfo.IncludeDirectories.Add(dir);
                    var searchPattern = "*." + LanguageHelper.GetSourceExtension(lang);
                    linkInfo.Sources.AddRange(SystemHelper.GetFilesByLastWrite(dir, searchPattern, SearchOption.AllDirectories, 15));
                    break;
                }

                default:
                    break;
                }

                return(FlowErrorCode.Success);
            }
            else
            {
                return(FlowErrorCode.ExceptionError);
            }
        }