Beispiel #1
0
        private static void FindAllSources(string[] sourcesArguments)
        {
            MainSources = sourcesArguments;
            RootPath    = Path.GetDirectoryName(sourcesArguments[0]);

            Assembler     assembler  = new Assembler();
            List <string> allsources = assembler.GetSourceFiles(MainSources);

            var references = new HashSet <string>();

            if (assembler.UseDefaultReferences)
            {
                foreach (string defaultReference in Assembler.DefaultReferences)
                {
                    references.Add(Assembler.GetAssemblyDllPath(defaultReference));
                }
            }

            foreach (var assemblerRef in assembler.References)
            {
                references.Add(assemblerRef);
            }

            // find all folders and create associated projects types
            foreach (var source in allsources)
            {
                string dir = Path.GetDirectoryName(source);
                if (!string.IsNullOrEmpty(dir))
                {
                    dir = Util.PathMakeStandard(dir);
                }

                var existing = DebugProjects.FirstOrDefault(dp => dir.Contains(dp.Value.ProjectFolder));
                if (existing.Equals(default(KeyValuePair <Type, ProjectContent>)))
                {
                    string projectName   = Path.GetFileName(dir) + "_sharpmake";
                    Type   myProjectType = CreateProject(projectName);

                    ProjectContent project = new ProjectContent {
                        ProjectFolder = dir
                    };
                    project.References.AddRange(references);
                    foreach (var p in DebugProjects)
                    {
                        p.Value.ProjectReferences.Add(myProjectType);
                    }
                    DebugProjects.Add(myProjectType, project);
                    existing = DebugProjects.Last();
                }

                existing.Value.ProjectFiles.Add(source);
            }
        }
Beispiel #2
0
        private static Type GenerateDebugProject(IAssemblyInfo assemblyInfo, bool isSetupProject, string startArguments, IDictionary <string, Type> visited, string[] defines)
        {
            string displayName = assemblyInfo.DebugProjectName;

            if (string.IsNullOrEmpty(displayName))
            {
                displayName = isSetupProject ? "sharpmake_debug" : $"sharpmake_package_{assemblyInfo.Id.GetHashCode():X8}";
            }

            Type generatedProject;

            if (visited.TryGetValue(assemblyInfo.Id, out generatedProject))
            {
                if (generatedProject == null)
                {
                    throw new Error($"Circular sharpmake package dependency on {displayName}");
                }
                return(generatedProject);
            }

            visited[assemblyInfo.Id] = null;

            ProjectContent project = new ProjectContent
            {
                ProjectFolder  = RootPath,
                IsSetupProject = isSetupProject,
                DisplayName    = displayName,
                StartArguments = startArguments
            };

            generatedProject = CreateProject(displayName);
            DebugProjects.Add(generatedProject, project);

            // Add sources
            foreach (var source in assemblyInfo.SourceFiles)
            {
                project.ProjectFiles.Add(source);
            }

            // Add references
            var references = new HashSet <string>();

            if (assemblyInfo.UseDefaultReferences)
            {
                foreach (string defaultReference in Assembler.DefaultReferences)
                {
                    references.Add(Assembler.GetAssemblyDllPath(defaultReference));
                }
            }

            foreach (var assemblerRef in assemblyInfo.References)
            {
                if (!assemblyInfo.SourceReferences.ContainsKey(assemblerRef))
                {
                    references.Add(assemblerRef);
                }
            }

            project.References.AddRange(references);

            foreach (var refInfo in assemblyInfo.SourceReferences.Values)
            {
                project.ProjectReferences.Add(GenerateDebugProject(refInfo, false, string.Empty, visited, defines));
            }

            if (defines != null)
            {
                project.Defines.AddRange(defines);
            }

            visited[assemblyInfo.Id] = generatedProject;

            return(generatedProject);
        }