Exemplo n.º 1
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)).ToArray(),
                    dir,
                    new[] { GeneratedFileType.TYPES, GeneratedFileType.SERVICES },
                    new[] { GeneratedFileType.TYPES }
                    )
                                   .Select(Path.GetFileName)
                                   .ToList();

                return(FlowErrorCode.Success);
            }


            List <string> 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);
            }
        }