Exemple #1
0
        public static Path ParseWithContainer(string path)
        {
            if (_parsedLocationCache.ContainsKey(path))
            {
                return(_parsedLocationCache[path]);
            }

            var endswithslash = path.LastIndexOfAny(Slashes) == path.Length;

            var pathToParse = (path ?? string.Empty).UrlDecode();

            var match = UriRx.Match(pathToParse);

            if (match.Success)
            {
                pathToParse = match.Groups[3].Value;
            }

            var segments = pathToParse.Split(Slashes, StringSplitOptions.RemoveEmptyEntries);

            return(_parsedLocationCache.AddOrSet(path, new Path {
                HostAndPort = segments.Length > 0 ? segments[0] : string.Empty,
                Container = segments.Length > 1 ? segments[1] : string.Empty,
                Parts = segments.Length > 2 ? segments.Skip(2).ToArray() : new string[0],
                SubPath = segments.Length > 2 ? segments.Skip(2).Aggregate((current, each) => current + Slash + each) : string.Empty,
                ParentPath = segments.Length > 3 ? segments.Skip(2).Take(segments.Length - 3).Aggregate((current, each) => current + Slash + each) : string.Empty,
                Name = segments.Length > 2 ? segments.Last() : string.Empty,
                StartsWithSlash = pathToParse.IndexOfAny(Slashes) == 0,
                EndsWithSlash = endswithslash, // pathToParse.LastIndexOfAny(Slashes) == pathToParse.Length,
                Scheme = match.Success ? match.Groups[1].Value.ToLower() : string.Empty,
                OriginalPath = path,
            }));
        }
Exemple #2
0
        internal static StringPropertyList LookupMetadataList(this ProjectItemDefinitionElement pide, string metadataName, string defaultValue = null)
        {
            foreach (var m in pide.Metadata.Where(metadata => metadata.Name == metadataName))
            {
                var metadata = m;
                return(_stringPropertyList.GetOrAdd(metadata, () => _stringPropertyList.AddOrSet(metadata, new StringPropertyList(() => metadata.Value, v => metadata.Value = v))));
            }
            var n = pide.AddMetadata(metadataName, defaultValue ?? "");

            return(_stringPropertyList.GetOrAdd(n, () => _stringPropertyList.AddOrSet(n, new StringPropertyList(() => n.Value, v => n.Value = v))));
        }
Exemple #3
0
        private void Clean(IEnumerable<Rule> builds)
        {
            foreach( var build in builds ) {
                try {
                    // set environment variables:
                    var savedVariables = _originalEnvironment;
                    _originalEnvironment = new XDictionary<string, string>(savedVariables);

                    var sets = build["set"];
                    if (sets != null) {
                        foreach (var label in sets.Labels) {
                            _originalEnvironment.AddOrSet(label, sets[label].Value);
                            Environment.SetEnvironmentVariable(label, sets[label].Value);
                        }
                    }

                    // build dependencies first
                    CleanDependencies(build);

                    SetCompilerSdkAndPlatform(build);

                    var cmd = build["clean-command"];
                    try {
                        if (cmd != null && !string.IsNullOrEmpty(cmd.Value)) {
                            Exec(cmd.Value);
                        }
                    }
                    catch  {
                        //ignoring any failures from clean command.
                    }
                    File.Delete(Path.Combine(Environment.CurrentDirectory, "trace[{0}].xml".format(build.Name)));

                    _originalEnvironment = savedVariables;
                }
                catch (Exception e) {
                    Console.WriteLine("Uh, throw? {0} : {1}", e.Message, e.StackTrace);
                    //ignoring any failures from clean command.
                }

            }
        }
Exemple #4
0
        private bool CheckTargets(Rule build, bool haltOnFail = true )
        {
            // we need the environment set correctly here.
            var savedVariables = _originalEnvironment;
            _originalEnvironment = new XDictionary<string, string>(savedVariables);

            var sets = build["set"];
            if (sets != null) {
                foreach (var label in sets.Labels) {
                    _originalEnvironment.AddOrSet(label, sets[label].Value);
                    Environment.SetEnvironmentVariable(label, sets[label].Value);
                }
            }

            ResetEnvironment();

            // var kids = LocalChildBuilds(build);
            var failed = LocalChildBuilds(build).Aggregate(false, (current, childBuild) => current || (!CheckTargets(childBuild, haltOnFail)));

            // if there are no targets, then you can't skip them if they aren't there.
            if (build["targets"] == null && !haltOnFail ) {
                return false;
            }

            if (build["targets"] != null) {
                foreach (var targ in build["targets"].Values.Where(targ => !File.Exists(targ))) {
                    failed = true;
                    if (haltOnFail) {
                        throw new ConsoleException("Target [{0}] was not found.", targ);
                    }
                }

                using (new ConsoleColors(ConsoleColor.Gray, ConsoleColor.Black)) {
                    Console.WriteLine("Targets Verified.");
                }
            }

            _originalEnvironment = savedVariables;
            return !failed;
        }
Exemple #5
0
        /// <summary>
        /// Runs build rules
        /// </summary>
        /// <param name="builds">A list of build rules to build</param>
        private void Build(IEnumerable<Rule> builds)
        {
            foreach (var build in builds) {
                // set environment variables:
                var savedVariables = _originalEnvironment;
                _originalEnvironment = new XDictionary<string, string>(savedVariables);

                var sets = build["set"];
                if (sets != null) {
                    foreach( var label in sets.Labels ) {
                        _originalEnvironment.AddOrSet(label, sets[label].Value);
                        Environment.SetEnvironmentVariable(label, sets[label].Value);
                    }
                }

                // build dependencies first
                BuildDependencies(build);

                // install required packages...
                var requires = build["requires"];
                if( requires != null ) {
                    foreach( var pkg in requires.Values ) {
                        Console.WriteLine("Looking for {0}", pkg);
                        var installedPkgs = _easy.QueryPackages(pkg, Package.Properties.Installed.Is(true)).Result;
                        if( !installedPkgs.Any()) {
                            // there isn't a matching installed package, we'd better install one.
                            // refresh the feeds, as a package dependency might have recently been built...
                            foreach( var feed in sessionFeeds) {
                                _easy.AddSessionFeed(feed);
                            }

                            var pkgToInstall = _easy.QueryPackages(pkg, Package.Properties.Installed.Is(false)).Result;
                            bool failed = false;
                            _easy.InstallPackage(pkgToInstall.First().CanonicalName, autoUpgrade: true).Wait();

                            if( failed ) {
                                throw new ConsoleException("Unable to install dependent package.");
                            }
                        }
                    }
                }

                SetCompilerSdkAndPlatform(build);

                var generate = build["generate"];
                if(generate !=null &&  generate.HasValues ) {
                    var files = build["generate"].Labels;
                    if (!files.IsNullOrEmpty()) {
                        foreach (var file in files) {
                            File.WriteAllText(file,generate[file].Value);
                        }
                    }
                }

                if( !(_skipBuilt && CheckTargets(build, false)) )  {
                    // read the build command from PropertySheet
                    var cmd = build["build-command"];

                    // tell the user which build rule we are processing right now
                    if (_verbose || (cmd != null && !string.IsNullOrEmpty(cmd.Value))) {
                        using (new ConsoleColors(ConsoleColor.White, ConsoleColor.Black)) {
                            Console.WriteLine("Building Configuration [{0}]", build.Name);
                        }
                    }

                    // run this build command
                    if (cmd != null && !string.IsNullOrEmpty(cmd.Value)) {
                        Exec(cmd.Value);
                    }
                }

                // check to see that the right things got built
                CheckTargets(build);

                _originalEnvironment = savedVariables;
            }
        }