Exemple #1
0
        private static bool TryConvertPackageArchitecture(string architectureString, out PackageArchitecture architecture)
        {
            architecture = PackageArchitecture.Unknown;
            switch (architectureString.ToLowerInvariant())
            {
            case "arm":
                architecture = PackageArchitecture.Arm;
                break;

            case "amd64":
            case "x64":
                architecture = PackageArchitecture.X64;
                break;

            case "i386":
            case "x86":
                architecture = PackageArchitecture.X86;
                break;

            case "neutral":
                architecture = PackageArchitecture.Neutral;
                break;
            }

            return(architecture != PackageArchitecture.Unknown);
        }
Exemple #2
0
        /// <summary>
        /// Compiles the added files into a target output appropriate for the output path extension.
        /// </summary>
        /// <param name="type">Package type to generate.</param>
        /// <param name="architecture">Package architecture to generate.</param>
        /// <param name="languages">Package languages to generate.</param>
        /// <param name="outputPath">Path to generate output. Output path file extension determines the output type.</param>
        public void Compile(PackageType type, PackageArchitecture architecture, CultureInfo[] languages, string outputPath)
        {
            FrontendCompiler frontend = new FrontendCompiler(architecture, this.referenceAssemblies);

            frontend.Messages += this.Messages;

            foreach (KeyValuePair <string, string> define in this.PreprocessorDefines)
            {
                frontend.Substitutions.Add(define.Key, define.Value);
            }

            foreach (Swix root in this.roots)
            {
                frontend.AddRoot(root);
            }

            foreach (string path in this.sourceFiles)
            {
                frontend.Parse(path);
            }

            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Resolve();
            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Harvest();
            if (frontend.EncounteredError)
            {
                return;
            }

            Intermediate[] intermediates = frontend.GetIntermediates();

            CompilerFileManager fileManager = this.FileManager ?? new CompilerFileManager();

            fileManager.Architecture = architecture;
            fileManager.Language     = languages.Length == 0 ? null : languages[0];
            fileManager.OutputPath   = outputPath;
            foreach (string searchPath in this.SearchPaths)
            {
                fileManager.SearchPaths.Add(searchPath);
            }

            using (BackendCompiler backend = BackendCompiler.Create(type, outputPath))
            {
                backend.Messages    += this.Messages;
                backend.Architecture = architecture;
                backend.FileManager  = fileManager;
                backend.Languages    = languages;

                backend.Generate(intermediates, outputPath);
            }
        }
        public FrontendCompiler(PackageArchitecture architecture, List <System.Reflection.Assembly> referenceAssemblies)
        {
            this.namedItems    = new Dictionary <string, PackageItem>();
            this.Substitutions = new Dictionary <string, string>();

            this.Architecture = architecture;

            this.items = new List <PackageItem>();
            this.roots = new List <Swix>();

            this.services = new Dictionary <Type, object>();

            this.fileSystemManager = new FileSystemResourceManager(FrontendCompiler.DefaultFileSystemManagerRootFolderId);
            this.services.Add(this.fileSystemManager.GetType(), this.fileSystemManager);

            this.unresolved = new List <PackageItem>();

            this.AddSystemPackage(); // ensure the system resources are always loaded.
        }
Exemple #4
0
        private bool Run(Messaging messaging)
        {
            if (this.SourcePaths.Length == 0)
            {
                messaging.OnError(null, "No inputs specified. Specify at least one file.");
            }

            if (String.IsNullOrEmpty(this.Type))
            {
                if (this.OutputPath == null)
                {
                    messaging.OnError(this, "Package type cannot be inferred from output path. Explicitly specify PackageType in your MSBuild project or -type from the swc.exe command-line. Valid options are: appx, msi, vsix, or wixlib");
                }
                else
                {
                    this.Type = Path.GetExtension(this.OutputPath.ItemSpec);
                }
            }
            else if (this.OutputPath == null && this.SourcePaths.Length > 0)
            {
                string outputPath = Path.ChangeExtension(this.SourcePaths[0].ItemSpec, this.Type.ToLowerInvariant());
                this.OutputPath = new FilePathTaskItem(outputPath);
            }

            PackageArchitecture architecture = PackageArchitecture.Unknown;

            if (String.IsNullOrEmpty(this.Architecture))
            {
                messaging.OnError(this, "A package architecture must specified. Set the PackageArchitecture in your MSBuild project or -arch from the swc.exe command-line. Valid options are: arm, x64, x86 or neutral");
            }
            else if (!SimplifiedWixCompiler.TryConvertPackageArchitecture(this.Architecture, out architecture))
            {
                messaging.OnError(this, "Unknown architecture specified: {0}. Valid options are: arm, x64, x86 or neutral", this.Architecture);
            }

            List <CultureInfo> locales = new List <CultureInfo>();

            if (this.Languages != null)
            {
                foreach (string language in this.Languages)
                {
                    try
                    {
                        CultureInfo locale;

                        int lcid = 0;
                        if (Int32.TryParse(language, out lcid))
                        {
                            locale = new CultureInfo(lcid);
                        }
                        else
                        {
                            locale = new CultureInfo(language);
                        }

                        locales.Add(locale);
                    }
                    catch (CultureNotFoundException)
                    {
                        messaging.OnError(this, "Unknown language: {0}", language);
                    }
                }
            }

            PackageType type = PackageType.Unknown;

            if (String.IsNullOrEmpty(this.Type))
            {
                messaging.OnError(this, "A package type must specified. Use the PackageType in your MSBuild project or -type from the swc.exe command-line. Valid options are: appx, msi, vsix or wixlib");
            }
            else if (!SimplifiedWixCompiler.TryConvertPackageType(this.Type, out type))
            {
                messaging.OnError(this, "Unknown package type specified: {0}. Valid options are: appx, msi, vsix or wixlib", this.Type);
            }

            if (type == PackageType.Appx && locales.Count == 0)
            {
                messaging.OnError(this, "AppX packages do not support language neutral packages. At least one language to be specified. Use the PackageLanguages property in your MSBuild project or -lang from the swc.exe command-line.");
            }

            if (!messaging.Errored)
            {
                SimplifiedCompiler compiler = new SimplifiedCompiler();
                compiler.Messages += messaging.MessageDelegate;

                if (this.SearchPaths != null)
                {
                    foreach (ITaskItem searchPath in this.SearchPaths)
                    {
                        compiler.SearchPaths.Add(searchPath.ItemSpec);
                    }
                }

                if (this.PreprocessorDefines != null)
                {
                    foreach (string define in this.PreprocessorDefines)
                    {
                        string[] defineSplit = define.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                        compiler.PreprocessorDefines.Add(defineSplit[0], defineSplit.Length > 1 ? defineSplit[1] : null);
                    }
                }

                // Load the extensions.
                if (this.Extensions != null)
                {
                    SimplifiedWixCompiler.LoadExtensions(compiler, messaging, this.Extensions);
                }

                // Finally, load the sources and compile!
                if (!messaging.Errored)
                {
                    SimplifiedWixCompiler.LoadPackageSources(compiler, this.SourcePaths);
                    compiler.Compile(type, architecture, locales.ToArray(), this.OutputPath.ItemSpec);
                }
            }

            return(!messaging.Errored);
        }
Exemple #5
0
 /// <summary>
 /// Compiles the added files using the given CompilerExtension to generate the output
 /// </summary>
 /// <param name="outputExtension">Extension used to generated the output.</param>
 /// <param name="architecture">Package architecture to generate.</param>
 /// <param name="languages">Package languages to generate.</param>
 /// <param name="outputPath">Path to generate output.</param>
 public void Compile(CompilerExtension outputExtension, PackageArchitecture architecture, CultureInfo[] languages, string outputPath)
 {
     CoreCompile(architecture, languages, outputPath, () => outputExtension.CreateBackendCompiler());
 }
Exemple #6
0
 /// <summary>
 /// Compiles the added files into a target output appropriate for the output path extension.
 /// </summary>
 /// <param name="type">Package type to generate.</param>
 /// <param name="architecture">Package architecture to generate.</param>
 /// <param name="languages">Package languages to generate.</param>
 /// <param name="outputPath">Path to generate output. Output path file extension determines the output type.</param>
 public void Compile(PackageType type, PackageArchitecture architecture, CultureInfo[] languages, string outputPath)
 {
     CoreCompile(architecture, languages, outputPath, () => BackendCompiler.Create(type, outputPath));
 }