Example #1
0
        public void FillInTemplate()
        {
            // -----------------------------------------------------------------------------------------------------------------------------------
            // Fill in the package template

            // we need to be in the directory where we're making the wxs file.
            // since we're playing with relative file paths in the wxs source.
            using (var popd = new PushDirectory(FilesystemExtensions.TempPath)) {
                using (var reader = new StringReader(Model.WixTemplate)) {
                    wixXml = XDocument.Load(reader);
                }

                wix = new DynamicNode(wixXml);

                SetBasicWixProperties();

                // add all the files
                AddFilesToWix();

                // add the assemblies to the package.
                AddAssembliesToWix();

                // add the bootstrappers
                AddBootstrappersToWix();

                // add feed icon images
                AddFeedIcons();

                //Add the CoApp Properties
                AddCoAppProperties();
            }
        }
Example #2
0
        /*
           private IDictionary<string,string> ExternalChildBuilds( Rule build ) {
           var result = new XDictionary<string, string>();

           var uses = build["uses"];
           if (uses != null) {
               foreach (var useLabel in uses.Labels) {
                   var use = build["uses"][useLabel];

                   var config = useLabel;
                   var folder = use.Value;

                   if (string.IsNullOrEmpty(config)) {
                       if ((from rule in _propertySheet.Rules where use.Contains(rule.Name) select rule).Any()) {
                           continue;
                       }
                   }

                   // if it wasn't an internal build, then switch to the folder and run the build specified.

                   folder = folder.GetFullPath();
                   if (!Directory.Exists(folder)) {
                       throw new ConsoleException("Dependency project [{0}] does not exist.", folder);
                   }

                   var depBuildinfo = Path.Combine(folder, @"copkg\.buildinfo");
                   if (!File.Exists(depBuildinfo)) {
                       throw new ConsoleException("Dependency project is missing buildinfo [{0}]", depBuildinfo);
                   }
                   result.Add(folder, config);
               }
           }
           return result;
           }*/
        /// <summary>
        /// Builds all dependencies listed in a given build rule
        /// </summary>
        /// <param name="buildRule">A build rule to which the dependencies should be built</param>
        private void BuildDependencies(Rule buildRule)
        {
            // save current directory
            var uses = buildRule["uses"];
            if (uses != null) {
                foreach (var configuration in uses.Labels) {
                    var locations = buildRule["uses"][configuration];

                    if (string.IsNullOrEmpty(configuration)) {
                        // this could be a use in the local file.
                        var builds = from rule in _propertySheet.Rules where locations.Contains(rule.Name) select rule;

                        if (builds.Any()) {
                            Build(builds);
                            continue;
                        }
                    }

                    /*
                     * uses x86="..\zlib";
                     * uses x86="..\libpng";
                     *
                     * or
                     *
                     * uses : configuration {
                     *      "location",
                     *      "location",
                     *      "location",
                     *      "location"
                     * }
                     *
                     * uses : configuration: location;
                     *
                     */

                    foreach (var folder in locations.Select(path => path.GetFullPath())) {
                        // if it wasn't an internal build, then switch to the folder and run the build specified.
                        if (!Directory.Exists(folder)) {
                            throw new ConsoleException("Dependency project [{0}] does not exist.", folder);
                        }

                        var depBuildinfo = Path.Combine(folder, @"copkg\.buildinfo");
                        if (!File.Exists(depBuildinfo)) {
                            throw new ConsoleException("Dependency project is missing buildinfo [{0}]", depBuildinfo);
                        }

                        using (var popd = new PushDirectory(folder)) {
                            // build dependency project
                            _ptk.ExecNoRedirections("--nologo build {0}", configuration);
                            if (_ptk.ExitCode != 0) {
                                throw new ConsoleException("Dependency project failed to build [{0}] config={1}", depBuildinfo, string.IsNullOrEmpty(configuration) ? "all" : configuration);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Builds all dependencies listed in a given build rule
        /// </summary>
        /// <param name="buildRule">A build rule to which the dependencies should be built</param>
        private void CleanDependencies(Rule buildRule)
        {
            var uses = buildRule["uses"];
            if (uses != null) {
                foreach (var configuration in uses.Labels) {
                    var locations = buildRule["uses"][configuration];

                    if (string.IsNullOrEmpty(configuration)) {
                        // this could be a use in the local file.
                        var builds = from rule in _propertySheet.Rules where locations.Contains(rule.Name) select rule;

                        if (builds.Any()) {
                            Clean(builds);
                            continue;
                        }
                    }

                    foreach (var folder in locations.Select(path => path.GetFullPath())) {
                        // if it wasn't an internal build, then switch to the folder and run the build specified.
                        if (!Directory.Exists(folder)) {
                            throw new ConsoleException("Dependency project [{0}] does not exist.", folder);
                        }

                        var depBuildinfo = Path.Combine(folder, @"copkg\.buildinfo");
                        if (!File.Exists(depBuildinfo)) {
                            throw new ConsoleException("Dependency project is missing buildinfo [{0}]", depBuildinfo);
                        }

                        using (var popd = new PushDirectory(folder)) {
                            // build dependency project
                            _ptk.ExecNoRedirections("--nologo clean {0}", configuration);
                            if (_ptk.ExitCode != 0) {
                                throw new ConsoleException("Dependency project failed to build [{0}] config={1}", depBuildinfo, string.IsNullOrEmpty(configuration) ? "all" : configuration);
                            }
                        }
                    }
                }
            }

            /*
            // save current directory

            var uses = build["uses"];
            if (uses != null) {
                foreach (var useLabel in uses.Labels) {
                    var use = build["uses"][useLabel];

                    var config = string.Empty;
                    var folder = string.Empty;

                    // set folder and configuration as needed
                    config = useLabel;
                    folder = use.Value;

                    if (string.IsNullOrEmpty(config)) {
                        // this could be a use in the local file.

                        var builds = from rule in _propertySheet.Rules where use.Contains(rule.Name) select rule;

                        if (builds.Any()) {
                            Clean(builds);
                            continue;
                        }
                    }

                    // if it wasn't an internal build, then switch to the folder and run the build specified.

                    folder = folder.GetFullPath();
                    if (!Directory.Exists(folder)) {
                        throw new ConsoleException("Dependency project [{0}] does not exist.", folder);
                    }

                    var depBuildinfo = Path.Combine(folder, @"copkg\.buildinfo");
                    if (!File.Exists(depBuildinfo)) {
                        throw new ConsoleException("Dependency project is missing buildinfo [{0}]", depBuildinfo);
                    }

                    // switch project directory
                    using (var popd = new PushDirectory(folder)) {
                        // build dependency project
                        _ptk.ExecNoRedirections("--nologo clean {0}", config);
                        if (_ptk.ExitCode != 0)
                            throw new ConsoleException(
                                "Dependency project failed to clean [{0}] config={1}", depBuildinfo, string.IsNullOrEmpty(config) ? "all" : config);
                        // reset directory to where we came from
                    }
                }
            }*/
        }
        /// <summary>
        ///   The (non-static) startup method
        /// </summary>
        /// <param name = "args">
        ///   The command line arguments.
        /// </param>
        /// <returns>
        ///   Process return code.
        /// </returns>
        protected override int Main(IEnumerable<string> args)
        {
            // force temporary folder to be where we want it to be.
            CurrentTask.Events += new DownloadProgress((remoteLocation, location, progress) => {
                "Downloading {0}".format(remoteLocation.UrlDecode()).PrintProgressBar(progress);
            });

            CurrentTask.Events += new DownloadCompleted((remoteLocation, locallocation) => {
                Console.WriteLine();
            });

            PackageManager.AddSessionFeed(Environment.CurrentDirectory).Wait();

            var macrovals = new XDictionary<string, string>();

            try {
                // default:
                var options = args.Where(each => each.StartsWith("--")).Switches();
                var parameters = args.Where(each => !each.StartsWith("--")).Parameters();

                foreach (var arg in options.Keys) {
                    var argumentParameters = options[arg];
                    var last = argumentParameters.LastOrDefault();
                    var lastAsBool = string.IsNullOrEmpty(last) || last.IsTrue();

                    switch (arg) {
                            /* options  */

                            /* global switches */
                        case "verbose":
                            _verbose = lastAsBool;
                            Logger.Messages = true;
                            Logger.Warnings = true;
                            Logger.Errors = true;
                            break;

                        case "load-config":
                            // all ready done, but don't get too picky.
                            break;

                        case "nologo":
                            this.Assembly().SetLogo(string.Empty);
                            break;

                        case "show-tools":
                            Tools.ShowTools = lastAsBool;
                            break;

                        case "certificate-path":
                            _signingCertPath = Path.GetFullPath(last);
                            break;

                        case "password":
                            _signingCertPassword = last;
                            break;

                        case "remember":
                            _remember = lastAsBool;
                            break;

                        case "override":
                            Override = true;
                            break;

                        case "help":
                            return Help();

                        case "no-toolkit-dependency":
                            break;

                        default:
                            macrovals.Add(arg, last);
                            break;
                    }
                }

                // set up the stuff to catch our errors and warnings

                CurrentTask.Events += new Error(HandleErrors);
                CurrentTask.Events += new Warning(HandleWarnings);
                CurrentTask.Events += new Verbose(Verbose);
                CurrentTask.Events += new Message(HandleMessage);

                // find all the command line tools that we're gonna need.
                Tools.LocateCommandlineTools();

                if (!parameters.Any()) {
                    throw new ConsoleException("Missing .autopkg script.");
                    // throw new ConsoleException(Resources.NoConfigFileLoaded);
                }

                Logo();

                var allFiles = parameters.FindFilesSmarter().ToArray();
                foreach (var file in allFiles) {
                    FilesystemExtensions.ResetTempFolder();
                    using (var popd = new PushDirectory(Path.GetDirectoryName(file.GetFullPath()))) {
                        Binary.UnloadAndResetAll();

                        PackageManager.AddSessionFeed(Path.GetDirectoryName(file.GetFullPath())).Wait();

                        PackageSource = new PackageSource(file, macrovals );

                        var template = PropertySheet.Parse(Resources.template_autopkg,null);

                        PackageSource.ImportedSheets.Add("template", template);

                        FindCertificate();

                        SigningCertPath = _signingCertPath;
                        SigningCertPassword = _signingCertPassword;
                        Remember = _remember;

                        // ------- Create data model for package
                        CreatePackageModel();

                        // ------ Generate package MSI from model
                        CreatePackageFile();
                    }
                }

            } catch (PackageException) {
                return Fail("Autopackage encountered errors.\r\n");
            } catch (ConsoleException failure) {
                return Fail("{0}\r\n\r\n    {1}", failure.Message, Resources.ForCommandLineHelp);
            } catch (Exception failure) {
                if( failure.InnerException != null ) {
                    Fail("Exception Caught: {0}\r\n{1}\r\n\r\n    {2}", failure.InnerException.Message, failure.InnerException.StackTrace, Resources.ForCommandLineHelp);
                }

                return Fail("Exception Caught: {0}\r\n{1}\r\n\r\n    {2}", failure.Message, failure.StackTrace, Resources.ForCommandLineHelp);
            }
            return 0;
        }