Example #1
0
        private void Initialize(Type targetType, Type configurationType)
        {
            var expectedType = typeof(Solution.Configuration);

            if (configurationType == null || (configurationType != expectedType && !configurationType.IsSubclassOf(expectedType)))
            {
                throw new InternalError("configuration type {0} must be a subclass of {1}", targetType.FullName, expectedType.FullName);
            }

            ConfigurationType = configurationType;

            ClassName = GetType().Name;
            Targets.Initialize(targetType);

            string file;

            if (Util.GetStackSourceFileTopMostTypeOf(GetType(), out file))
            {
                FileInfo fileInfo = new FileInfo(file);
                SharpmakeCsFileName = Util.PathMakeStandard(fileInfo.FullName);
                SharpmakeCsPath     = Util.PathMakeStandard(fileInfo.DirectoryName);
            }
            else
            {
                throw new InternalError("Cannot locate cs source for type: {0}", GetType().FullName);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        private void Initialize(Type targetType)
        {
            ClassName = GetType().Name;
            Targets.Initialize(targetType);

            string file;

            if (Util.GetStackSourceFileTopMostTypeOf(GetType(), out file))
            {
                FileInfo fileInfo = new FileInfo(file);
                SharpmakeCsFileName = Util.PathMakeStandard(fileInfo.FullName);
                SharpmakeCsPath     = Util.PathMakeStandard(fileInfo.DirectoryName);
            }
            else
            {
                throw new InternalError("Cannot locate cs source for type: {}", GetType().FullName);
            }
        }
Example #4
0
        /// <summary>
        /// The input path got its beginning of path matching the inputHeadPath replaced by the replacementHeadPath.
        ///
        /// Throws if the fullInputPath doesn't start with inputHeadPath.
        ///
        /// Function is case insensitive but preserves path casing.
        /// </summary>
        /// <param name="fullInputPath">The path to be modified.</param>
        /// <param name="inputHeadPath">The subpath in the head of fullInputPath to replace.</param>
        /// <param name="replacementHeadPath">The subpath that will replace the inputHeadPath</param>
        /// <returns></returns>
        public static string ReplaceHeadPath(this string fullInputPath, string inputHeadPath, string replacementHeadPath)
        {
            // Normalize paths before comparing and combining them, to prevent false mismatch between '\\' and '/'.
            fullInputPath       = Util.PathMakeStandard(fullInputPath, false);
            inputHeadPath       = Util.PathMakeStandard(inputHeadPath, false);
            replacementHeadPath = Util.PathMakeStandard(replacementHeadPath, false);

            inputHeadPath = EnsureTrailingSeparator(inputHeadPath);

            if (!fullInputPath.StartsWith(inputHeadPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException($"The subpath to be replaced '{inputHeadPath}'\n is not found at the beginning of the input path '{fullInputPath}'.");
            }

            var pathRelativeToOutput = fullInputPath.Substring(inputHeadPath.Length);
            var modifiedPath         = Path.Combine(replacementHeadPath, pathRelativeToOutput);

            return(modifiedPath);
        }
Example #5
0
 public static string ResolvePath(string root, string path)
 {
     return(Util.PathGetAbsolute(root, Util.PathMakeStandard(path)));
 }