Example #1
0
 //---------------------------------------------------------------------
 public DebugSettingsRestorer(VCDebugSettings settings)
 {
     this.Value            = settings;
     this.command          = settings.Command;
     this.commandArguments = settings.CommandArguments;
     this.workingDirectory = settings.WorkingDirectory;
 }
        private void SetWorkingDirectory(string value)
        {
            Project startupProj = GetStartUpProject();

            if (startupProj != null)
            {
                VCProject vcProj = startupProj.Object as VCProject;
                if (vcProj != null)
                {
                    foreach (VCConfiguration config in vcProj.Configurations)
                    {
                        VCDebugSettings debugSetting = config.DebugSettings;
                        debugSetting.WorkingDirectory = value;
                    }
                }
                else
                {
                    Configuration configuration = startupProj.ConfigurationManager.ActiveConfiguration;
                    configuration.Properties.Item("StartWorkingDirectory").Value = value;
                }
            }
        }
        private void UpdateTextBoxes()
        {
            Project startupProj = GetStartUpProject();

            if (startupProj != null)
            {
                VCProject vcProj = startupProj.Object as VCProject;
                if (vcProj != null)
                {
                    foreach (VCConfiguration config in vcProj.Configurations)
                    {
                        VCDebugSettings debugSetting = config.DebugSettings;
                        textboxwd.Text  = debugSetting.WorkingDirectory;
                        textboxcla.Text = debugSetting.CommandArguments;
                    }
                }
                else
                {
                    Configuration configuration = startupProj.ConfigurationManager.ActiveConfiguration;
                    textboxwd.Text  = configuration.Properties.Item("StartWorkingDirectory").Value.ToString();
                    textboxcla.Text = configuration.Properties.Item("StartArguments").Value.ToString();
                }
            }
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event args</param>
        private async void Execute(object sender, EventArgs e)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var     dte       = Package.GetGlobalService(typeof(SDTE)) as DTE;
            Project project   = GetActiveProject(dte);
            var     vcProject = project.Object as VCProject;

            if (IsEnclave(project))
            {
                MessageBox.Show("The project to import into must not be another enclave.");
                return;
            }

            var filePath = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                // InitialDirectory must be an absolute, not relative, path.
                openFileDialog.InitialDirectory = Path.GetDirectoryName(dte.Solution.FileName);
                openFileDialog.Filter           = "EDL files (*.EDL)|*.edl";
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    // Get the path of specified file.
                    filePath = openFileDialog.FileName;
                    WizardImplementation.EdlLocation = Path.GetDirectoryName(filePath);

                    // Extract base name of enclave.
                    string baseName = System.IO.Path.GetFileNameWithoutExtension(filePath);

                    // Add list of generated files to the project.
                    ProjectItem generatedFilesFolder = FindOrAddVirtualFolder(project, "Generated Files");
                    try
                    {
                        generatedFilesFolder.ProjectItems.AddFromFile(baseName + "_u.h");
                        generatedFilesFolder.ProjectItems.AddFromFile(baseName + "_args.h");
                        ProjectItem ucItem = generatedFilesFolder.ProjectItems.AddFromFile(baseName + "_u.c");
                        var         ucFile = ucItem.Object as VCFile;
                        foreach (var config in ucFile.FileConfigurations)
                        {
                            var tool = config.Tool;
                            tool.UsePrecompiledHeader = 0; // none
                        }
                    } catch (Exception)
                    {
                        // File couldn't be added, it may already exist.
                    }

                    // Add nuget package to project.
                    // See https://stackoverflow.com/questions/41803738/how-to-programmatically-install-a-nuget-package/41895490#41895490
                    // and more particularly https://docs.microsoft.com/en-us/nuget/visual-studio-extensibility/nuget-api-in-visual-studio
                    var packageVersions = new Dictionary <string, string>()
                    {
                        { "open-enclave-cross", "0.12.0.2" }
                    };
                    var componentModel   = (IComponentModel)(await this.ServiceProvider.GetServiceAsync(typeof(SComponentModel)));
                    var packageInstaller = componentModel.GetService <IVsPackageInstaller2>();
                    packageInstaller.InstallPackagesFromVSExtensionRepository(
                        "OpenEnclaveVisualStudioExtension-1", // extensionId
                        false,                                // isPreUnzipped
                        false,                                // skipAssemblyReferences
                        false,                                // ignoreDependencies
                        project,
                        packageVersions);

                    // Add the EDL file to the project.
                    // We need to do this after adding the OE extension so the EdlItem type can be found.
                    ProjectItem sourceFilesFolder = FindOrAddVirtualFolder(project, "Source Files");
                    try
                    {
                        ProjectItem edlItem = sourceFilesFolder.ProjectItems.AddFromFile(filePath);
                    }
                    catch (Exception)
                    {
                        // File couldn't be added, it may already exist.
                    }

                    bool isWindows = (vcProject.keyword != "Linux");

                    foreach (VCConfiguration config in vcProject.Configurations)
                    {
                        var    config3 = config as VCConfiguration3;
                        string name    = config.Name;

                        if (name.Contains("ARM"))
                        {
                            var    clRule = config.Rules.Item("CL") as IVCRulePropertyStorage;
                            string value  = clRule.GetUnevaluatedPropertyValue("PreprocessorDefinitions");
                            clRule.SetPropertyValue("PreprocessorDefinitions", "_ARM_;" + value);
                        }

                        if (!isWindows && name.Contains("Debug"))
                        {
                            // GCC has no preprocessor define for debug mode, but the generated host file
                            // expects _DEBUG, so set it here.
                            var    clRule = config.Rules.Item("CL") as IVCRulePropertyStorage;
                            string value  = clRule.GetUnevaluatedPropertyValue("PreprocessorDefinitions");
                            clRule.SetPropertyValue("PreprocessorDefinitions", "_DEBUG;" + value);
                        }

                        if (isWindows)
                        {
                            // Change OutDir to $(SolutionDir)bin\$(Platform)\$(Configuration)\
                            // so it's the same as the enclave.
                            config.OutputDirectory = "$(SolutionDir)bin\\$(Platform)\\$(Configuration)\\";
                        }
                        else
                        {
                            // Add a post-build event to copy the enclave binary to the existing OutDir.
                            string cmd     = "cp $(RemoteRootDir)/" + baseName + "/bin/$(Platform)/$(Configuration)/" + baseName + ".signed $(RemoteOutDir)" + baseName;
                            var    cbeRule = config.Rules.Item("ConfigurationBuildEvents") as IVCRulePropertyStorage;
                            cbeRule.SetPropertyValue("RemotePostBuildCommand", cmd);
                            cbeRule.SetPropertyValue("RemotePostBuildMessage", "Copying enclave binary");
                        }

                        if (name.Contains("OPTEE") || name.Contains("ARM") || isWindows)
                        {
                            // Set the debugger's working directory to where the binary is placed.
                            VCDebugSettings debugging = config.DebugSettings;
                            debugging.WorkingDirectory = "$(OutDir)";
                            continue;
                        }

                        // Linux SGX remote compilation.
                        // Configure gdb like the oe-gdb script does.
                        var gdbRule = config.Rules.Item("LinuxDebugger");
                        if (gdbRule != null)
                        {
                            // Configure GDB debugger settings.
                            string gdbEnvironmentSettings = "export PYTHONPATH=/opt/openenclave/lib/openenclave/debugger/gdb-sgx-plugin;export LD_PRELOAD=/opt/openenclave/lib/openenclave/debugger/liboe_ptrace.so";
                            gdbRule.SetPropertyValue("PreLaunchCommand", gdbEnvironmentSettings);
                            gdbRule.SetPropertyValue("AdditionalDebuggerCommands", "directory /opt/openenclave/lib/openenclave/debugger/gdb-sgx-plugin;source /opt/openenclave/lib/openenclave/debugger/gdb-sgx-plugin/gdb_sgx_plugin.py;set environment LD_PRELOAD;add-auto-load-safe-path /usr/lib");
                        }
                    }

                    // Add a host code item to the project.
                    AddProjectItem("OEHostItem", "VC", baseName + "_host.c");

                    // Add a reference to the enclave project if it's in the same solution.
                    Project enclaveProject = FindProject(dte.Solution, WizardImplementation.EdlLocation);
                    if (enclaveProject != null)
                    {
                        try
                        {
                            var vcProjectReference = vcProject.AddProjectReference(enclaveProject) as VCProjectReference;
                            vcProjectReference.LinkLibraryDependency = false;
                        } catch (Exception)
                        {
                            // Reference couldn't be added, it may already exist.
                        }
                    }

                    Cursor.Current = Cursors.Default;
                }
            }
        }
Example #5
0
        public void CreateTestCocoonConfig(String config, string project, List <string> additionalParamsList, List <string> additiona_includes, bool QtConfiguration)
        {
            bool foundProject = false;

            IEnumerator ProjectsEnumaror = GetVCProjectRefs();

            ProjectsEnumaror.Reset();
            // traverse all projects to find the right one
            while (ProjectsEnumaror.MoveNext())
            {
                VCProject actVCP = (VCProject)ProjectsEnumaror.Current;
                if (actVCP.Name == project)
                {
                    foundProject = true;
                    VCConfiguration vcC = null;
                    //vcC = (VCConfiguration)(((IVCCollection)actVCP.Configurations).Item(config));
                    IEnumerator ConfigurationEnumarator = ((IVCCollection)actVCP.Configurations).GetEnumerator();
                    for (ConfigurationEnumarator.Reset(); ConfigurationEnumarator.MoveNext();)
                    {
                        vcC = ConfigurationEnumarator.Current as VCConfiguration;
                        if ((vcC != null) && (vcC.ConfigurationName == config))
                        {
                            Log("Modifying configuration '" + config + "' for the project '" + project + "' for the platform '" + vcC.Name + "'");

                            // change settings for sepcified compiler
                            IVCCollection ctools = (IVCCollection)vcC.Tools;

                            VCActiveXReference  cVCActiveXReference  = ctools.Item("VCActiveXReference") as VCActiveXReference;
                            VCALinkTool         cVCALinkTool         = ctools.Item("VCALinkTool") as VCALinkTool;
                            VCAppVerifierTool   cVCAppVerifierTool   = ctools.Item("VCAppVerifierTool") as VCAppVerifierTool;
                            VCAssemblyReference cVCAssemblyReference = ctools.Item("VCAssemblyReference") as VCAssemblyReference;
                            VCBscMakeTool       cVCBscMakeTool       = ctools.Item("VCBscMakeTool") as VCBscMakeTool;
                            VCCLCompilerTool    cVCCLCompilerTool    = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool;
                            VCConfiguration     cVCConfiguration     = ctools.Item("VCConfiguration") as VCConfiguration;
                            VCCustomBuildRule   cVCCustomBuildRule   = ctools.Item("VCCustomBuildRule") as VCCustomBuildRule;
                            VCCustomBuildTool   cVCCustomBuildTool   = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool;
                            VCDebugSettings     cVCDebugSettings     = ctools.Item("VCDebugSettings") as VCDebugSettings;
                            VCFile cVCFile = ctools.Item("VCFile") as VCFile;
                            VCFileConfiguration            cVCFileConfiguration            = ctools.Item("VCFileConfiguration") as VCFileConfiguration;
                            VCFilter                       cVCFilter                       = ctools.Item("VCFilter") as VCFilter;
                            VCFxCopTool                    cVCFxCopTool                    = ctools.Item("VCFxCopTool") as VCFxCopTool;
                            VCLibrarianTool                cVCLibrarianTool                = ctools.Item("VCLibrarianTool") as VCLibrarianTool;
                            VCLinkerTool                   cVCLinkerTool                   = ctools.Item("VCLinkerTool") as VCLinkerTool;
                            VCManagedResourceCompilerTool  cVCManagedResourceCompilerTool  = ctools.Item("VCManagedResourceCompilerTool") as VCManagedResourceCompilerTool;
                            VCManifestTool                 cVCManifestTool                 = ctools.Item("VCManifestTool") as VCManifestTool;
                            VCMidlTool                     cVCMidlTool                     = ctools.Item("VCMidlTool") as VCMidlTool;
                            VCNMakeTool                    cVCNMakeTool                    = ctools.Item("VCNMakeTool") as VCNMakeTool;
                            VCPlatform                     cVCPlatform                     = ctools.Item("VCPlatform") as VCPlatform;
                            VCPostBuildEventTool           cVCPostBuildEventTool           = ctools.Item("VCPostBuildEventTool") as VCPostBuildEventTool;
                            VCPreBuildEventTool            cVCPreBuildEventTool            = ctools.Item("VCPreBuildEventTool") as VCPreBuildEventTool;
                            VCPreLinkEventTool             cVCPreLinkEventTool             = ctools.Item("VCPreLinkEventTool") as VCPreLinkEventTool;
                            VCProject                      cVCProject                      = ctools.Item("VCProject") as VCProject;
                            VCProjectEngine                cVCProjectEngine                = ctools.Item("VCProjectEngine") as VCProjectEngine;
                            VCProjectEngineEvents          cVCProjectEngineEvents          = ctools.Item("VCProjectEngineEvents") as VCProjectEngineEvents;
                            VCProjectEngineObject          cVCProjectEngineObject          = ctools.Item("VCProjectEngineObject") as VCProjectEngineObject;
                            VCProjectItem                  cVCProjectItem                  = ctools.Item("VCProjectItem") as VCProjectItem;
                            VCProjectReference             cVCProjectReference             = ctools.Item("VCProjectReference") as VCProjectReference;
                            VCPropertySheet                cVCPropertySheet                = ctools.Item("VCPropertySheet") as VCPropertySheet;
                            VCReference                    cVCReference                    = ctools.Item("VCReference") as VCReference;
                            VCReferences                   cVCReferences                   = ctools.Item("VCReferences") as VCReferences;
                            VCResourceCompilerTool         cVCResourceCompilerTool         = ctools.Item("VCResourceCompilerTool") as VCResourceCompilerTool;
                            VCRuntimeBooleanProperty       cVCRuntimeBooleanProperty       = ctools.Item("VCRuntimeBooleanProperty") as VCRuntimeBooleanProperty;
                            VCRuntimeEnumProperty          cVCRuntimeEnumProperty          = ctools.Item("VCRuntimeEnumProperty") as VCRuntimeEnumProperty;
                            VCRuntimeEnumValue             cVCRuntimeEnumValue             = ctools.Item("VCRuntimeEnumValue") as VCRuntimeEnumValue;
                            VCRuntimeIntegerProperty       cVCRuntimeIntegerProperty       = ctools.Item("VCRuntimeIntegerProperty") as VCRuntimeIntegerProperty;
                            VCRuntimeProperty              cVCRuntimeProperty              = ctools.Item("VCRuntimeProperty") as VCRuntimeProperty;
                            VCRuntimeStringProperty        cVCRuntimeStringProperty        = ctools.Item("VCRuntimeStringProperty") as VCRuntimeStringProperty;
                            VCToolFile                     cVCToolFile                     = ctools.Item("VCToolFile") as VCToolFile;
                            VCUserMacro                    cVCUserMacro                    = ctools.Item("VCUserMacro") as VCUserMacro;
                            VCWebDeploymentTool            cVCWebDeploymentTool            = ctools.Item("VCWebDeploymentTool") as VCWebDeploymentTool;
                            VCWebServiceProxyGeneratorTool cVCWebServiceProxyGeneratorTool = ctools.Item("VCWebServiceProxyGeneratorTool") as VCWebServiceProxyGeneratorTool;
                            VCXDCMakeTool                  cVCXDCMakeTool                  = ctools.Item("VCXDCMakeTool") as VCXDCMakeTool;
                            VCXMLDataGeneratorTool         cVCXMLDataGeneratorTool         = ctools.Item("VCXMLDataGeneratorTool") as VCXMLDataGeneratorTool;

                            VCLinkerTool      linkerTool                    = ctools.Item("VCLinkerTool") as VCLinkerTool;
                            VCLibrarianTool   librarianTool                 = ctools.Item("VCLibrarianTool") as VCLibrarianTool;
                            VCCLCompilerTool  compilerTool                  = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool;
                            VCCustomBuildTool customBuildTool               = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool;
                            string            libgen                        = FindCslibConfig(ref compilerTool);
                            List <string>     additionalParamsListLink      = new List <string>(additionalParamsList);
                            List <string>     additionalParamsListLibrarian = new List <string>(additionalParamsList);
                            if (libgen != null)
                            {
                                additionalParamsListLink.Add("--cs-libgen=" + libgen);
                                additionalParamsListLibrarian.Add("--cs-libgen=" + libgen);
                            }

                            if (compilerTool != null)
                            {
                                CreateClConfig(ref compilerTool, additionalParamsList, additiona_includes, actVCP.ProjectDirectory, config);
                            }
                            if (linkerTool != null)
                            {
                                CreateLinkConfig(ref linkerTool, additionalParamsListLink, config);
                            }
                            if (customBuildTool != null)
                            {
                                CreateCustomBuildConfig(ref customBuildTool, additionalParamsList, config);
                            }
                            if (librarianTool != null)
                            {
                                CreateLibrarianConfig(ref librarianTool, additionalParamsListLibrarian, config);
                            }
                            if (actVCP != null)
                            {
                                CreateConfigForEachFile(ref actVCP, additionalParamsList, config);
                            }
                        }
                    }
                }
            }
            if (!foundProject)
            {
                ShowMessageBox("Could not find the project", "Warning");
            }
        }
        private void ProjectContextMenuItemCallback(object sender, EventArgs e)
        {
            var          dte          = this.dte.DTE;
            OutputWindow outputWindow = null;

            try
            {
                outputWindow = new OutputWindow(dte);

                OleMenuCommand menuCommand = sender as OleMenuCommand;
                if (menuCommand != null && dte != null)
                {
                    Array selectedProjects = (Array)dte.ActiveSolutionProjects;
                    //only support 1 selected project
                    if (selectedProjects.Length == 1)
                    {
                        EnvDTE.Project project = (EnvDTE.Project)selectedProjects.GetValue(0);
                        var            vcproj  = project.Object as VCProject;
                        if (vcproj != null)
                        {
                            IVCCollection   configs = (IVCCollection)vcproj.Configurations;
                            VCConfiguration cfg     = (VCConfiguration)vcproj.ActiveConfiguration;
                            VCDebugSettings debug   = (VCDebugSettings)cfg.DebugSettings;

                            string command          = null;
                            string arguments        = null;
                            string workingDirectory = null;
                            if (debug != null)
                            {
                                command          = cfg.Evaluate(debug.Command);
                                workingDirectory = cfg.Evaluate(debug.WorkingDirectory);
                                arguments        = cfg.Evaluate(debug.CommandArguments);
                            }

                            VCPlatform currentPlatform = (VCPlatform)cfg.Platform;

                            string platform = currentPlatform == null ? null : currentPlatform.Name;
                            if (platform != null)
                            {
                                platform = platform.ToLower();
                                if (platform.Contains("x64"))
                                {
                                    platform = "x64";
                                }
                                else if (platform.Contains("x86") || platform.Contains("win32"))
                                {
                                    platform = "x86";
                                }
                                else
                                {
                                    throw new NotSupportedException("Platform is not supported.");
                                }
                            }
                            else
                            {
                                cfg      = (VCConfiguration)configs.Item("Debug|x64");
                                platform = "x64";

                                if (cfg == null)
                                {
                                    throw new NotSupportedException("Cannot find x64 platform for project.");
                                }
                            }

                            if (command == null || String.IsNullOrEmpty(command))
                            {
                                command = cfg.PrimaryOutput;
                            }

                            if (command != null)
                            {
                                var solutionFolder = System.IO.Path.GetDirectoryName(dte.Solution.FileName);

                                CoverageExecution executor = new CoverageExecution(dte, outputWindow);
                                executor.Start(
                                    solutionFolder,
                                    platform,
                                    System.IO.Path.GetDirectoryName(command),
                                    System.IO.Path.GetFileName(command),
                                    workingDirectory,
                                    arguments);
                            }
                        }
                    }
                }
            }
            catch (NotSupportedException ex)
            {
                if (outputWindow != null)
                {
                    outputWindow.WriteLine("Error running coverage: {0}", ex.Message);
                }
            }
            catch (Exception ex)
            {
                if (outputWindow != null)
                {
                    outputWindow.WriteLine("Unexpected code coverage failure; error: {0}", ex.ToString());
                }
            }
        }