Ejemplo n.º 1
0
        public static string Run(ExportCommand command, BuildContext buildContext)
        {
            string           outputDirectory   = new GetOutputDirectoryWorker().DoWorkImpl(buildContext);
            ExportBundle     compilationResult = ExportBundle.Compile(buildContext);
            ResourceDatabase resDb             = ResourceDatabaseBuilder.PrepareResources(buildContext, null);
            string           byteCode          = ByteCodeEncoder.Encode(compilationResult.ByteCode);

            byte[] cbxFileBytes = new GenerateCbxFileContentWorker().GenerateCbxBinaryData(buildContext, resDb, compilationResult, byteCode);
            Dictionary <string, FileOutput> fileOutputContext = new Dictionary <string, FileOutput>();

            new PopulateFileOutputContextForCbxWorker().GenerateFileOutput(fileOutputContext, buildContext, resDb, cbxFileBytes);
            new EmitFilesToDiskWorker().DoWorkImpl(fileOutputContext, outputDirectory);
            string absoluteCbxFilePath = new GetCbxFileLocation().DoWorkImpl(outputDirectory, buildContext);

            return(absoluteCbxFilePath);
        }
Ejemplo n.º 2
0
        public ExportBundle ExportVmBundle(ExportCommand command, BuildContext buildContext)
        {
            // TODO: Worker: platform = GetPlatform(buildContext, command)
            string platformId = buildContext.Platform.ToLowerInvariant();

            Platform.AbstractPlatform platform = command.PlatformProvider.GetPlatform(platformId);
            if (platform == null)
            {
                throw new InvalidOperationException("Unrecognized platform. See usage.");
            }

            // TODO: Worker: Compile
            ExportBundle compilationResult = ExportBundle.Compile(buildContext);

            AssemblyMetadata[] libraries = compilationResult.LibraryScopesUsed.Select(scope => scope.Metadata).ToArray();

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

            string outputDirectory = command.HasOutputDirectoryOverride
                ? command.OutputDirectoryOverride
                : buildContext.OutputFolder;

            if (!Path.IsAbsolute(outputDirectory))
            {
                outputDirectory = FileUtil.JoinPath(buildContext.ProjectDirectory, outputDirectory);
            }
            outputDirectory = FileUtil.GetCanonicalizeUniversalPath(outputDirectory);
            FileOutputExporter exporter = new FileOutputExporter(outputDirectory);

            VmGenerator vmGenerator = new VmGenerator();
            Dictionary <string, FileOutput> result = new Dictionary <string, FileOutput>();

            vmGenerator.GenerateVmSourceCodeForPlatform(
                result,
                platform,
                compilationResult,
                resourceDatabase,
                libraries,
                outputDirectory,
                VmGenerationMode.EXPORT_SELF_CONTAINED_PROJECT_SOURCE);

            exporter.ExportFiles(result);

            // TODO: this needs to be the result of an earlier step after this is split into workers.
            return(compilationResult);
        }
Ejemplo n.º 3
0
        public byte[] GenerateCbxBinaryData(BuildContext buildContext, ResourceDatabase resDb, ExportBundle compilationResult, string byteCode)
        {
            List <byte> cbxOutput = new List <byte>()
            {
                0
            };

            cbxOutput.AddRange("CBX".ToCharArray().Select(c => (byte)c));
            cbxOutput.AddRange(GetBigEndian4Byte(VersionInfo.VersionMajor));
            cbxOutput.AddRange(GetBigEndian4Byte(VersionInfo.VersionMinor));
            cbxOutput.AddRange(GetBigEndian4Byte(VersionInfo.VersionBuild));

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

            List <string> libraries = new List <string>();

            foreach (CompilationScope scopeForLibrary in compilationResult.LibraryScopesUsed.Where(scope => scope.Metadata.HasNativeCode))
            {
                libraries.Add(scopeForLibrary.Metadata.ID);
                libraries.Add(scopeForLibrary.Metadata.Version);
            }
            string libsData = string.Join(",", libraries);

            byte[] libsDataBytes = StringUtil.ToUtf8Bytes(libsData);
            cbxOutput.AddRange("LIBS".ToCharArray().Select(c => (byte)c));
            cbxOutput.AddRange(GetBigEndian4Byte(libsDataBytes.Length));
            cbxOutput.AddRange(libsDataBytes);

            byte[] resourceManifest = StringUtil.ToUtf8Bytes(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 = StringUtil.ToUtf8Bytes(resDb.ImageSheetManifestFile.TextContent);
                cbxOutput.AddRange("IMSH".ToCharArray().Select(c => (byte)c));
                cbxOutput.AddRange(GetBigEndian4Byte(imageSheetManifest.Length));
                cbxOutput.AddRange(imageSheetManifest);
            }

            return(cbxOutput.ToArray());
        }
Ejemplo n.º 4
0
        public static void Run()
        {
            ExportCommand command = new TopLevelCheckWorker().DoWorkImpl();

            if (command.UseOutputPrefixes)
            {
                ConsoleWriter.EnablePrefixes();
            }

            BuildContext buildContext;

            switch (TopLevelCheckWorker.IdentifyUseCase(command))
            {
            case ExecutionType.SHOW_USAGE:
                new UsageDisplayWorker().DoWorkImpl();
                break;

            case ExecutionType.SHOW_VERSION:
                new VersionDisplayWorker().DoWorkImpl();
                break;

            case ExecutionType.GENERATE_DEFAULT_PROJECT:
                new GenerateDefaultProjectWorker().DoWorkImpl(command);
                break;

            case ExecutionType.EXPORT_VM_BUNDLE:
                buildContext = new GetBuildContextWorker().DoWorkImpl(command);
                ExportBundle result = Exporter.Pipeline.ExportCbxVmBundlePipeline.Run(command, buildContext);
                if (command.ShowLibraryDepTree)
                {
                    new ShowAssemblyDepsWorker().DoWorkImpl(result.UserCodeScope);
                }
                break;

            case ExecutionType.EXPORT_VM_STANDALONE:
                Exporter.Pipeline.ExportStandaloneVmPipeline.Run(command);
                break;

            case ExecutionType.ERROR_CHECK_ONLY:
                NotifyStatusChange("COMPILE-START");
                if (command.IsJsonOutput)
                {
                    try
                    {
                        DoExportStandaloneCbxFileAndGetPath(command, true);
                    }
                    catch (Exception e)
                    {
                        RenderErrorInfoAsJson(command, e);
                    }
                }
                else
                {
                    DoExportStandaloneCbxFileAndGetPath(command, true);
                    RenderErrorInfoAsJson(command, null);     // renders the JSON object with the right schema, but empty.
                }
                NotifyStatusChange("COMPILE-END");
                break;

            case ExecutionType.EXPORT_CBX:
                NotifyStatusChange("COMPILE-START");
                if (command.IsJsonOutput)
                {
                    try
                    {
                        DoExportStandaloneCbxFileAndGetPath(command, false);
                    }
                    catch (Exception e)
                    {
                        RenderErrorInfoAsJson(command, e);
                    }
                }
                else
                {
                    DoExportStandaloneCbxFileAndGetPath(command, false);
                }
                NotifyStatusChange("COMPILE-END");
                break;

            case ExecutionType.RUN_CBX:
                NotifyStatusChange("COMPILE-START");
                string cbxFileLocation = null;
                if (command.IsJsonOutput)
                {
                    try
                    {
                        cbxFileLocation = DoExportStandaloneCbxFileAndGetPath(command, false);
                        NotifyStatusChange("COMPILE-END");
                    }
                    catch (Exception e)
                    {
                        RenderErrorInfoAsJson(command, e);
                        NotifyStatusChange("COMPILE-END");
                        NotifyStatusChange("RUN-ABORTED");
                        return;
                    }
                }
                else
                {
                    cbxFileLocation = DoExportStandaloneCbxFileAndGetPath(command, false);
                    NotifyStatusChange("COMPILE-END");
                }

                string cmdLineFlags = new RunCbxFlagBuilderWorker().DoWorkImpl(command, cbxFileLocation);

                if (command.ShowPerformanceMarkers)
                {
                    ShowPerformanceMetrics(command);
                }

                NotifyStatusChange("RUN-START");

                new RunCbxWorker().DoWorkImpl(cmdLineFlags);
                NotifyStatusChange("RUN-END");
                return;
            }

            if (command.ShowPerformanceMarkers)
            {
                ShowPerformanceMetrics(command);
            }
        }
Ejemplo n.º 5
0
        public static void Run(ExportCommand command, BuildContext buildContext)
        {
            ExportBundle compilationResult = ExportBundle.Compile(buildContext);

            ByteCodeEncoder.Encode(compilationResult.ByteCode);
        }