Exemple #1
0
        public static void Add(View view, Project project)
        {
            var prjPlus = project.Lookup();
            if (prjPlus.View != null) {
                throw new ClrPlusException("Configurations already registered for project");
            }
            prjPlus.View = view;

            var pkgName = view.GetMacroValue("pkgname");

            // add the startup/init tasks
            var task = project.Xml.AddUsingTask(pkgName + "_Contains", @"$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll", null);
            task.TaskFactory = "CodeTaskFactory";
            var pgroup = task.AddParameterGroup();
            pgroup.AddParameter("Text", "false", string.Empty, "System.String");
            pgroup.AddParameter("Library", "false", "true", "System.String");
            pgroup.AddParameter("Value", "false", "true", "System.String");
            pgroup.AddParameter("Result", "true", string.Empty, "System.String");

            var body = task.AddUsingTaskBody(string.Empty, string.Empty);

            // thank you.
            body.XmlElement().Append("Code").InnerText = @"Result = ((Text ?? """").Split(';').Contains(Library) ) ? Value : String.Empty;";

            var initTarget = project.AddInitTarget(pkgName + "_init");

            var pivots = view.GetChildPropertyNames();

            foreach (var pivot in pivots) {
                dynamic cfg = view.GetProperty(pivot);
                IEnumerable<string> choices = cfg.choices;

                if(!((View)cfg).GetChildPropertyNames().Contains("key")) {
                    // add init steps for this.
                    var finalPropName = "{0}-{1}".format(pivot, pkgName);

                    foreach (var choice in choices) {

                        var choicePropName = "{0}-{1}".format(pivot, choice);

                        var tsk = initTarget.AddTask("pkgName_Contains");
                        tsk.SetParameter("Text", choicePropName);
                        tsk.SetParameter("Library", pkgName);
                        tsk.SetParameter("Value", choice);
                        tsk.Condition = @"'$({0})'==''".format(finalPropName);
                        tsk.AddOutputProperty("Result", finalPropName);
                    }

                    project.Xml.AddPropertyGroup().AddProperty(finalPropName, choices.FirstOrDefault()).Condition = @"'$({0})' == ''".format(finalPropName);
                }
            }
        }
Exemple #2
0
        private void ProcessFiles(View files, string fileRoot, bool implictRules, string appliedCondition)
        {
            appliedCondition = Configurations.NormalizeConditionKey((appliedCondition ?? ""), _sheet.View.configurations);

            foreach(var containerName in files.GetChildPropertyNames()) {
                View container = files.GetProperty(containerName);
                if (containerName == "condition" || containerName == "*" ) {
                    foreach(var condition in container.GetChildPropertyNames()) {
                        ProcessFiles(container.GetElement(condition), fileRoot, implictRules, condition);
                    }
                    continue;
                }

                // get the destination directory
                var destinationDirectory = container.GetMetadataValue("destination", false);
                var dest = string.IsNullOrEmpty(destinationDirectory) ? files.GetMacroValue("d_" + containerName) : destinationDirectory;

                // locate all the files in the collection.
                var filemasks = container.Values;
                var foundFiles = Enumerable.Empty<string>();

                foreach (var mask in filemasks) {
                    var fileset = mask.FindFilesSmarterComplex(fileRoot).ToCacheEnumerable();

                    if (!fileset.Any()) {
                        Console.WriteLine("WARNING: file selection '{0}' failed to find any files ",mask);
                    }
                    foundFiles = foundFiles.Union(fileset);
                }

                if(implictRules && containerName == "include") {
                    // add this folder to the appropriate target
                    _targets.LookupItemDefinitionGroup(appliedCondition).LookupItemDefinitionElement("ClCompile").LookupMetadataList("AdditionalIncludeDirectories").AddUnique((files.GetMacroValue("pkg_root") + dest).Replace("${condition}", appliedCondition).Replace("\\\\", "\\"));
                }

                var flatten = container.GetMetadataValue("flatten", false).IsPositive();

                var relativePaths = foundFiles.GetMinimalPathsToDictionary();

                foreach (var src in relativePaths.Keys) {
                    string target = Path.Combine(dest, flatten ? Path.GetFileName(relativePaths[src]) : relativePaths[src]).Replace("${condition}", appliedCondition).Replace("\\\\", "\\");

                    var file = _nuspec.files.Add("file");
                    file.Attributes.src = src.GetFullPath().Replace("\\\\", "\\");
                    file.Attributes.target = target;

                    if (implictRules) {
                        switch (containerName) {
                            case "bin":
                                // add a per-file copy rule to the appropriate target
                                var tsk = _targets.LookupTarget("AfterBuild", appliedCondition).AddTask("Copy");
                                tsk.SetParameter("SourceFiles", (files.GetMacroValue("pkg_root") + target).Replace("\\\\", "\\"));
                                tsk.SetParameter("DestinationFolder", "$(TargetDir)");
                                tsk.SetParameter("SkipUnchangedFiles","true");
                                break;

                            case "lib":
                                // add a Libraries += rule to the appropriate target
                                _targets.LookupItemDefinitionGroup(appliedCondition).LookupItemDefinitionElement("Link").LookupMetadataList("AdditionalDependencies").AddUnique((files.GetMacroValue("pkg_root") + target).Replace("${condition}", appliedCondition).Replace("\\\\", "\\"));
                                break;
                        }
                    }
                }

                // Console.WriteLine("SET : {0}, => {1}", containerName, dest);
            }
        }