Example #1
0
        private Options.ExplicitOptions GenerateOptions(AndroidPackageProject project, string projectPath, Project.Configuration conf)
        {
            Options.ExplicitOptions options = new Options.ExplicitOptions();

            options["OutputFile"] = FileGeneratorUtilities.RemoveLineTag;
            if (_Project.AppLibType != null)
            {
                Project.Configuration appLibConf = conf.ConfigurationDependencies.FirstOrDefault(confDep => (confDep.Project.GetType() == _Project.AppLibType));
                if (appLibConf != null)
                {
                    // The lib name to first load from an AndroidActivity must be a dynamic library.
                    if (appLibConf.Output != Project.Configuration.OutputType.Dll)
                    {
                        throw new Error("Cannot use configuration \"{0}\" as app lib for package configuration \"{1}\". Output type must be set to dynamic library.", appLibConf, conf);
                    }

                    options["OutputFile"] = appLibConf.TargetFileFullName;
                }
                else
                {
                    throw new Error("Missing dependency of type \"{0}\" in configuration \"{1}\" dependencies.", _Project.AppLibType.ToNiceTypeName(), conf);
                }
            }

            //Options.Vc.General.UseDebugLibraries.
            //    Disable                                 WarnAsError="false"
            //    Enable                                  WarnAsError="true"                              /WX
            SelectOption
            (
                Options.Option(Options.Vc.General.UseDebugLibraries.Disabled, () => { options["UseDebugLibraries"] = "false"; }),
                Options.Option(Options.Vc.General.UseDebugLibraries.Enabled, () => { options["UseDebugLibraries"] = "true"; })
            );

            SelectOption
            (
                Options.Option(Options.Android.General.AndroidAPILevel.Default, () => { options["AndroidAPILevel"] = FileGeneratorUtilities.RemoveLineTag; }),
                Options.Option(Options.Android.General.AndroidAPILevel.Android19, () => { options["AndroidAPILevel"] = "android-19"; }),
                Options.Option(Options.Android.General.AndroidAPILevel.Android21, () => { options["AndroidAPILevel"] = "android-21"; }),
                Options.Option(Options.Android.General.AndroidAPILevel.Android22, () => { options["AndroidAPILevel"] = "android-22"; }),
                Options.Option(Options.Android.General.AndroidAPILevel.Android23, () => { options["AndroidAPILevel"] = "android-23"; }),
                Options.Option(Options.Android.General.AndroidAPILevel.Android24, () => { options["AndroidAPILevel"] = "android-24"; })
            );

            //OutputDirectory
            //    The debugger need a rooted path to work properly.
            //    So we root the relative output directory to $(ProjectDir) to work around this limitation.
            //    Hopefully in a futur version of the cross platform tools will be able to remove this hack.
            string outputDirectoryRelative = Util.PathGetRelative(projectPath, conf.TargetPath);

            options["OutputDirectory"] = outputDirectoryRelative;

            //IntermediateDirectory
            string intermediateDirectoryRelative = Util.PathGetRelative(projectPath, conf.IntermediatePath);

            options["IntermediateDirectory"] = intermediateDirectoryRelative;

            return(options);
        }
Example #2
0
            public GenerationContext(Builder builder, string projectPath, Project project, IEnumerable <Project.Configuration> projectConfigurations)
            {
                Builder = builder;

                FileInfo fileInfo = new FileInfo(projectPath);

                ProjectPath           = fileInfo.FullName;
                ProjectDirectory      = Path.GetDirectoryName(ProjectPath);
                ProjectFileName       = Path.GetFileName(ProjectPath);
                Project               = project;
                AndroidPackageProject = (AndroidPackageProject)Project;

                ProjectDirectoryCapitalized = Util.GetCapitalizedPath(ProjectDirectory);
                ProjectSourceCapitalized    = Util.GetCapitalizedPath(Project.SourceRootPath);

                ProjectConfigurations        = VsUtil.SortConfigurations(projectConfigurations, Path.Combine(ProjectDirectoryCapitalized, ProjectFileName + ProjectExtension)).ToArray();
                DevelopmentEnvironmentsRange = new DevEnvRange(ProjectConfigurations);

                PresentPlatforms = ProjectConfigurations.Select(conf => conf.Platform).Distinct().ToDictionary(p => p, p => PlatformRegistry.Get <IPlatformVcxproj>(p));
            }
Example #3
0
        private void Generate(
            AndroidPackageProject project,
            List <Project.Configuration> unsortedConfigurations,
            string projectPath,
            string projectFile,
            List <string> generatedFiles,
            List <string> skipFiles)
        {
            // Need to sort by name and platform
            List <Project.Configuration> configurations = new List <Project.Configuration>();

            configurations.AddRange(unsortedConfigurations.OrderBy(conf => conf.Name + conf.Platform));

            // validate that 2 conf name in the same project don't have the same name
            Dictionary <string, Project.Configuration> configurationNameMapping = new Dictionary <string, Project.Configuration>();
            string projectName = null;

            foreach (Project.Configuration conf in configurations)
            {
                if (projectName == null)
                {
                    projectName = conf.ProjectName;
                }
                else if (projectName != conf.ProjectName)
                {
                    throw new Error("Project configurations in the same project files must be the same: {0} != {1} in {2}", projectName, conf.ProjectName, projectFile);
                }

                Project.Configuration otherConf;

                string projectUniqueName = conf.Name + Util.GetPlatformString(conf.Platform, conf.Project);
                if (configurationNameMapping.TryGetValue(projectUniqueName, out otherConf))
                {
                    var differBy = Util.MakeDifferenceString(conf, otherConf);
                    throw new Error(
                              "Project {0} ({5} in {6}) have 2 configurations with the same name: \"{1}\" for {2} and {3}"
                              + Environment.NewLine + "Nb: ps3 and win32 cannot have same conf name: {4}",
                              project.Name, conf.Name, otherConf.Target, conf.Target, differBy, projectFile, projectPath);
                }

                configurationNameMapping[projectUniqueName] = conf;

                // set generator information
                switch (conf.Platform)
                {
                case Platform.android:
                    conf.GeneratorSetGeneratedInformation("elf", "elf", "so", "pdb");
                    break;

                default:
                    break;
                }
            }

            Resolver resolver = new Resolver();

            _ProjectDirectoryCapitalized = Util.GetCapitalizedPath(projectPath);
            //_ProjectSourceCapitalized = Util.GetCapitalizedPath(project.SourceRootPath);
            _Project = project;
            _ProjectConfigurationList = configurations;

            MemoryStream memoryStream = new MemoryStream();
            StreamWriter writer       = new StreamWriter(memoryStream);

            // xml begin header
            DevEnvRange devEnvRange = new DevEnvRange(unsortedConfigurations);

            using (resolver.NewScopedParameter("toolsVersion", devEnvRange.MinDevEnv.GetVisualProjectToolsVersionString()))
            {
                Write(Template.Project.ProjectBegin, writer, resolver);
            }

            Write(Template.Project.ProjectBeginConfigurationDescription, writer, resolver);
            // xml header contain description of each target
            foreach (Project.Configuration conf in _ProjectConfigurationList)
            {
                using (resolver.NewScopedParameter("platformName", Util.GetPlatformString(conf.Platform, conf.Project)))
                    using (resolver.NewScopedParameter("conf", conf))
                    {
                        Write(Template.Project.ProjectConfigurationDescription, writer, resolver);
                    }
            }
            Write(Template.Project.ProjectEndConfigurationDescription, writer, resolver);

            // xml end header
            var firstConf = _ProjectConfigurationList.First();

            using (resolver.NewScopedParameter("projectName", projectName))
                using (resolver.NewScopedParameter("guid", firstConf.ProjectGuid))
                    using (resolver.NewScopedParameter("toolsVersion", devEnvRange.MinDevEnv.GetVisualProjectToolsVersionString()))
                    {
                        Write(Template.Project.ProjectDescription, writer, resolver);
                    }

            // generate all configuration options once...
            Dictionary <Project.Configuration, Options.ExplicitOptions> options = new Dictionary <Project.Configuration, Options.ExplicitOptions>();

            foreach (Project.Configuration conf in _ProjectConfigurationList)
            {
                _ProjectConfiguration = conf;
                Options.ExplicitOptions option = GenerateOptions(project, projectPath, conf);
                _ProjectConfiguration = null;
                options.Add(conf, option);
            }

            // configuration general
            foreach (Project.Configuration conf in _ProjectConfigurationList)
            {
                using (resolver.NewScopedParameter("platformName", Util.GetPlatformString(conf.Platform, conf.Project)))
                    using (resolver.NewScopedParameter("conf", conf))
                        using (resolver.NewScopedParameter("options", options[conf]))
                        {
                            Write(Template.Project.ProjectConfigurationsGeneral, writer, resolver);
                        }
            }

            // .props files
            Write(Template.Project.ProjectAfterConfigurationsGeneral, writer, resolver);
            Write(Template.Project.ProjectAfterImportedProps, writer, resolver);

            string androidPackageDirectory = project.AntBuildRootDirectory;

            // configuration ItemDefinitionGroup
            foreach (Project.Configuration conf in _ProjectConfigurationList)
            {
                using (resolver.NewScopedParameter("platformName", Util.GetPlatformString(conf.Platform, conf.Project)))
                    using (resolver.NewScopedParameter("conf", conf))
                        using (resolver.NewScopedParameter("options", options[conf]))
                            using (resolver.NewScopedParameter("androidPackageDirectory", androidPackageDirectory))
                            {
                                Write(Template.Project.ProjectConfigurationBeginItemDefinition, writer, resolver);
                                {
                                    Write(Template.Project.AntPackage, writer, resolver);
                                }
                                Write(Template.Project.ProjectConfigurationEndItemDefinition, writer, resolver);
                            }
            }

            GenerateFilesSection(project, writer, resolver, projectPath, projectFile, generatedFiles, skipFiles);

            GenerateProjectReferences(configurations, resolver, writer, options);

            // .targets
            Write(Template.Project.ProjectTargets, writer, resolver);

            Write(Template.Project.ProjectEnd, writer, resolver);

            // Write the project file
            writer.Flush();

            // remove all line that contain RemoveLineTag
            MemoryStream cleanMemoryStream = Util.RemoveLineTags(memoryStream, FileGeneratorUtilities.RemoveLineTag);

            FileInfo projectFileInfo = new FileInfo(Path.Combine(projectPath, projectFile + ProjectExtension));

            if (_Builder.Context.WriteGeneratedFile(project.GetType(), projectFileInfo, cleanMemoryStream))
            {
                generatedFiles.Add(projectFileInfo.FullName);
            }
            else
            {
                skipFiles.Add(projectFileInfo.FullName);
            }

            writer.Close();

            _Project = null;
        }
Example #4
0
        private void GenerateFilesSection(
            AndroidPackageProject project,
            StreamWriter writer,
            Resolver resolver,
            string projectPath,
            string projectFileName,
            List <string> generatedFiles,
            List <string> skipFiles)
        {
            Strings projectFiles = _Project.GetSourceFilesForConfigurations(_ProjectConfigurationList);

            // Add source files
            List <ProjectFile> allFiles     = new List <ProjectFile>();
            List <ProjectFile> includeFiles = new List <ProjectFile>();
            List <ProjectFile> sourceFiles  = new List <ProjectFile>();

            foreach (string file in projectFiles)
            {
                ProjectFile projectFile = new ProjectFile(file, _ProjectDirectoryCapitalized);
                allFiles.Add(projectFile);
            }

            allFiles.Sort((ProjectFile l, ProjectFile r) => { return(l.FileNameProjectRelative.CompareTo(r.FileNameProjectRelative)); });

            // type -> files
            var customSourceFiles = new Dictionary <string, List <ProjectFile> >();

            foreach (ProjectFile projectFile in allFiles)
            {
                string type = null;
                if (_Project.ExtensionBuildTools.TryGetValue(projectFile.FileExtension, out type))
                {
                    List <ProjectFile> files = null;
                    if (!customSourceFiles.TryGetValue(type, out files))
                    {
                        files = new List <ProjectFile>();
                        customSourceFiles[type] = files;
                    }
                    files.Add(projectFile);
                }
                else if (_Project.SourceFilesCompileExtensions.Contains(projectFile.FileExtension) ||
                         (String.Compare(projectFile.FileExtension, ".rc", StringComparison.OrdinalIgnoreCase) == 0))
                {
                    sourceFiles.Add(projectFile);
                }
                else // if (projectFile.FileExtension == "h")
                {
                    includeFiles.Add(projectFile);
                }
            }

            // Write header files
            Write(Template.Project.ProjectFilesBegin, writer, resolver);
            foreach (ProjectFile file in includeFiles)
            {
                using (resolver.NewScopedParameter("file", file))
                    Write(Template.Project.ProjectFilesHeader, writer, resolver);
            }
            Write(Template.Project.ProjectFilesEnd, writer, resolver);

            Write(Template.Project.ItemGroupBegin, writer, resolver);

            using (resolver.NewScopedParameter("antBuildXml", project.AntBuildXml))
                using (resolver.NewScopedParameter("antProjectPropertiesFile", project.AntProjectPropertiesFile))
                    using (resolver.NewScopedParameter("androidManifest", project.AndroidManifest))
                    {
                        Write(Template.Project.AntBuildXml, writer, resolver);
                        Write(Template.Project.AndroidManifest, writer, resolver);
                        Write(Template.Project.AntProjectPropertiesFile, writer, resolver);
                    }
            Write(Template.Project.ItemGroupEnd, writer, resolver);
        }