Esempio n. 1
0
        private static void ExportVmBundle(Dictionary <string, string> argLookup)
        {
            using (new PerformanceSection("ExportVmBundle"))
            {
                BuildContext buildContext          = GetBuildContext(argLookup);
                Platform.AbstractPlatform platform = GetPlatformInstance(buildContext);
                if (platform == null)
                {
                    throw new InvalidOperationException("Unrecognized platform. See usage.");
                }

                CompilationBundle compilationResult = CompilationBundle.Compile(buildContext);

                // Need to re-instantiate the libraries. The libraries are instantiated in a platform-context-free
                // for the purpose of compiling the byte code. For the VM bundle, they need to know about the platform.
                Library[] libraries;
                using (new PerformanceSection("Program.ExportVmBundle.CloneLibraries"))
                {
                    libraries = compilationResult.LibrariesUsed
                                .Select(lib => lib.CloneWithNewPlatform(platform))
                                .ToArray();
                }

                ResourceDatabase resourceDatabase = PrepareResources(buildContext, compilationResult.ByteCode);

                string outputDirectory = buildContext.OutputFolder;
                if (!FileUtil.IsAbsolutePath(outputDirectory))
                {
                    outputDirectory = FileUtil.JoinPath(buildContext.ProjectDirectory, outputDirectory);
                }
                outputDirectory = FileUtil.GetCanonicalizeUniversalPath(outputDirectory);
                FileOutputExporter exporter = new FileOutputExporter(outputDirectory);

                VmGenerator vmGenerator = new VmGenerator();
                Dictionary <string, FileOutput> result = vmGenerator.GenerateVmSourceCodeForPlatform(
                    platform,
                    compilationResult,
                    resourceDatabase,
                    libraries,
                    outputDirectory,
                    VmGenerationMode.EXPORT_SELF_CONTAINED_PROJECT_SOURCE);

                exporter.ExportFiles(result);

                if (argLookup.ContainsKey(FlagParser.LIBRARY_DEP_TREE))
                {
                    string libs = LibraryDependencyResolver.GetDependencyTreeLog(compilationResult.LibrariesUsed.ToArray());
                    Console.WriteLine("<LibraryDependencies>");
                    Console.WriteLine(libs.Trim());
                    Console.WriteLine("</LibraryDependencies>");
                }
            }
        }
Esempio n. 2
0
        public CbxExporter Export()
        {
            using (new PerformanceSection("ExportCbx"))
            {
                if (!this.args.ContainsKey(FlagParser.BUILD_FILE))
                {
                    throw new InvalidOperationException("No build path was provided.");
                }

                BuildContext      buildContext      = GetBuildContextCbx(this.args[FlagParser.BUILD_FILE]);
                CompilationBundle compilationResult = CompilationBundle.Compile(buildContext);
                ResourceDatabase  resDb             = Program.PrepareResources(buildContext, null);
                string            byteCode          = ByteCodeEncoder.Encode(compilationResult.ByteCode);
                List <byte>       cbxOutput         = new List <byte>()
                {
                    0
                };
                cbxOutput.AddRange("CBX".ToCharArray().Select(c => (byte)c));
                cbxOutput.AddRange(GetBigEndian4Byte(0));
                cbxOutput.AddRange(GetBigEndian4Byte(2));
                cbxOutput.AddRange(GetBigEndian4Byte(0));

                byte[] code = StringToBytes(byteCode);
                cbxOutput.AddRange("CODE".ToCharArray().Select(c => (byte)c));
                cbxOutput.AddRange(GetBigEndian4Byte(code.Length));
                cbxOutput.AddRange(code);

                List <string> libraries = new List <string>();
                foreach (Library library in compilationResult.LibrariesUsed.Where(lib => lib.IsMoreThanJustEmbedCode))
                {
                    libraries.Add(library.Name);
                    libraries.Add(library.Version);
                }
                string libsData      = string.Join(",", libraries);
                byte[] libsDataBytes = StringToBytes(libsData);
                cbxOutput.AddRange("LIBS".ToCharArray().Select(c => (byte)c));
                cbxOutput.AddRange(GetBigEndian4Byte(libsDataBytes.Length));
                cbxOutput.AddRange(libsDataBytes);

                byte[] resourceManifest = StringToBytes(resDb.ResourceManifestFile.TextContent);
                cbxOutput.AddRange("RSRC".ToCharArray().Select(c => (byte)c));
                cbxOutput.AddRange(GetBigEndian4Byte(resourceManifest.Length));
                cbxOutput.AddRange(resourceManifest);

                if (resDb.ImageSheetManifestFile != null)
                {
                    byte[] imageSheetManifest = StringToBytes(resDb.ImageSheetManifestFile.TextContent);
                    cbxOutput.AddRange("IMSH".ToCharArray().Select(c => (byte)c));
                    cbxOutput.AddRange(GetBigEndian4Byte(imageSheetManifest.Length));
                    cbxOutput.AddRange(imageSheetManifest);
                }

                string outputFolder = buildContext.OutputFolder.Replace("%TARGET_NAME%", "cbx");
                string fullyQualifiedOutputFolder = FileUtil.JoinPath(buildContext.ProjectDirectory, outputFolder);
                string cbxPath = FileUtil.JoinPath(fullyQualifiedOutputFolder, buildContext.ProjectID + ".cbx");
                cbxPath = FileUtil.GetCanonicalizeUniversalPath(cbxPath);
                FileUtil.EnsureParentFolderExists(fullyQualifiedOutputFolder);
                Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>();
                output[buildContext.ProjectID + ".cbx"] = new FileOutput()
                {
                    Type          = FileOutputType.Binary,
                    BinaryContent = cbxOutput.ToArray(),
                };

                // Resource manifest and image sheet manifest is embedded into the CBX file

                foreach (FileOutput txtResource in resDb.TextResources)
                {
                    output["res/txt/" + txtResource.CanonicalFileName] = txtResource;
                }
                foreach (FileOutput sndResource in resDb.AudioResources)
                {
                    output["res/snd/" + sndResource.CanonicalFileName] = sndResource;
                }
                foreach (FileOutput fontResource in resDb.FontResources)
                {
                    output["res/ttf/" + fontResource.CanonicalFileName] = fontResource;
                }
                foreach (FileOutput binResource in resDb.BinaryResources)
                {
                    output["res/bin/" + binResource.CanonicalFileName] = binResource;
                }
                foreach (FileOutput imgResource in resDb.ImageResources)
                {
                    output["res/img/" + imgResource.CanonicalFileName] = imgResource;
                }
                foreach (string key in resDb.ImageSheetFiles.Keys)
                {
                    output["res/img/" + key] = resDb.ImageSheetFiles[key];
                }
                new FileOutputExporter(fullyQualifiedOutputFolder).ExportFiles(output);

                this.finalCbxPath = cbxPath;
            }
            return(this);
        }