コード例 #1
0
ファイル: CustomCommand.cs プロジェクト: wqhbuaa/PTVS
        internal void AddPropertiesAfter(IProjectLaunchProperties projectLaunchProperties)
        {
            // Fill PYTHONPATH from interpreter settings before we load values from Environment metadata item,
            // so that commands can explicitly override it if they want to.
            var props = PythonProjectLaunchProperties.Merge(this, projectLaunchProperties);

            Arguments            = props.GetArguments();
            WorkingDirectory     = props.GetWorkingDirectory();
            EnvironmentVariables = props.GetEnvironment(true);
        }
コード例 #2
0
ファイル: CustomCommand.cs プロジェクト: wqhbuaa/PTVS
        public CommandStartInfo GetStartInfo(IPythonProject2 project)
        {
            var outputs = BuildTarget(project, _target);
            var config  = PythonProjectLaunchProperties.Create(project);

            var item = outputs.Values
                       .SelectMany(result => result.Items)
                       .FirstOrDefault(i =>
                                       !string.IsNullOrEmpty(i.ItemSpec) &&
                                       !string.IsNullOrEmpty(i.GetMetadata(BuildTasks.CreatePythonCommandItem.TargetTypeKey))
                                       );

            if (item == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.ErrorBuildingCustomCommand, _target));
            }

            var startInfo = new CommandStartInfo {
                Filename             = item.ItemSpec,
                Arguments            = item.GetMetadata(BuildTasks.CreatePythonCommandItem.ArgumentsKey),
                WorkingDirectory     = item.GetMetadata(BuildTasks.CreatePythonCommandItem.WorkingDirectoryKey),
                EnvironmentVariables = PythonProjectLaunchProperties.ParseEnvironment(item.GetMetadata(BuildTasks.CreatePythonCommandItem.EnvironmentKey)),
                TargetType           = item.GetMetadata(BuildTasks.CreatePythonCommandItem.TargetTypeKey),
                ExecuteIn            = item.GetMetadata(BuildTasks.CreatePythonCommandItem.ExecuteInKey),
                RequiredPackages     = item.GetMetadata(BuildTasks.CreatePythonCommandItem.RequiredPackagesKey).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
            };

            try {
                startInfo.WorkingDirectory = CommonUtils.GetAbsoluteFilePath(project.ProjectHome, startInfo.WorkingDirectory);
            } catch (ArgumentException) {
            }

            string errorRegex = item.GetMetadata(BuildTasks.CreatePythonCommandItem.ErrorRegexKey);

            if (!string.IsNullOrEmpty(errorRegex))
            {
                startInfo.ErrorRegex = new Regex(errorRegex);
            }

            string warningRegex = item.GetMetadata(BuildTasks.CreatePythonCommandItem.WarningRegexKey);

            if (!string.IsNullOrEmpty(warningRegex))
            {
                startInfo.WarningRegex = new Regex(warningRegex);
            }

            startInfo.EnvironmentVariables["PYTHONUNBUFFERED"] = "1";
            startInfo.AddPropertiesAfter(PythonProjectLaunchProperties.Create(project));

            Debug.Assert(!string.IsNullOrEmpty(startInfo.WorkingDirectory));
            Debug.Assert(Path.IsPathRooted(startInfo.WorkingDirectory));

            return(startInfo);
        }
コード例 #3
0
ファイル: DefaultPythonLauncher.cs プロジェクト: krus/PTVS
        public int LaunchFile(string file, bool debug, IProjectLaunchProperties props)
        {
            if (debug)
            {
                StartWithDebugger(file, PythonProjectLaunchProperties.Create(_project, _serviceProvider, props));
            }
            else
            {
                StartWithoutDebugger(file, PythonProjectLaunchProperties.Create(_project, _serviceProvider, props));
            }

            return(VSConstants.S_OK);
        }
コード例 #4
0
ファイル: DefaultPythonLauncher.cs プロジェクト: krus/PTVS
        /// <summary>
        /// Creates process info used to start the project with no debugging.
        /// </summary>
        private ProcessStartInfo CreateProcessStartInfoNoDebug(string startupFile, IPythonProjectLaunchProperties props)
        {
            string command = CreateCommandLineNoDebug(startupFile, props);

            ProcessStartInfo startInfo;

            if (!(props.GetIsWindowsApplication() ?? false) &&
                (_pyService.DebuggerOptions.WaitOnAbnormalExit || _pyService.DebuggerOptions.WaitOnNormalExit))
            {
                command = "/c \"\"" + props.GetInterpreterPath() + "\" " + command;

                if (_pyService.DebuggerOptions.WaitOnNormalExit &&
                    _pyService.DebuggerOptions.WaitOnAbnormalExit)
                {
                    command += " & pause";
                }
                else if (_pyService.DebuggerOptions.WaitOnNormalExit)
                {
                    command += " & if not errorlevel 1 pause";
                }
                else if (_pyService.DebuggerOptions.WaitOnAbnormalExit)
                {
                    command += " & if errorlevel 1 pause";
                }

                command  += "\"";
                startInfo = new ProcessStartInfo(Path.Combine(Environment.SystemDirectory, "cmd.exe"), command);
            }
            else
            {
                startInfo = new ProcessStartInfo(props.GetInterpreterPath(), command);
            }

            startInfo.WorkingDirectory = props.GetWorkingDirectory();

            //In order to update environment variables we have to set UseShellExecute to false
            startInfo.UseShellExecute = false;

            var env = new Dictionary <string, string>(props.GetEnvironment(true));

            PythonProjectLaunchProperties.MergeEnvironmentBelow(env, null, true);
            foreach (var kv in env)
            {
                startInfo.EnvironmentVariables[kv.Key] = kv.Value;
            }
            return(startInfo);
        }
コード例 #5
0
 /// <summary>
 /// Returns a sequence of absolute search paths for the provided project.
 /// </summary>
 public static IEnumerable <string> GetSearchPaths(this IPythonProject project)
 {
     return(PythonProjectLaunchProperties.EnumerateSearchPaths(project));
 }
コード例 #6
0
ファイル: DefaultPythonLauncher.cs プロジェクト: krus/PTVS
        /// <summary>
        /// Sets up debugger information.
        /// </summary>
        private unsafe void SetupDebugInfo(
            ref VsDebugTargetInfo dbgInfo,
            string startupFile,
            IPythonProjectLaunchProperties props
            )
        {
            bool enableNativeCodeDebugging = false;

            dbgInfo.dlo                       = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            dbgInfo.bstrExe                   = props.GetInterpreterPath();
            dbgInfo.bstrCurDir                = props.GetWorkingDirectory();
            dbgInfo.bstrArg                   = CreateCommandLineDebug(startupFile, props);
            dbgInfo.bstrRemoteMachine         = null;
            dbgInfo.fSendStdoutToOutputWindow = 0;

            if (!enableNativeCodeDebugging)
            {
                string interpArgs = _project.GetProperty(PythonConstants.InterpreterArgumentsSetting);
                dbgInfo.bstrOptions = AD7Engine.VersionSetting + "=" + _project.GetInterpreterFactory().GetLanguageVersion().ToString();
                if (!(props.GetIsWindowsApplication() ?? false))
                {
                    if (_pyService.DebuggerOptions.WaitOnAbnormalExit)
                    {
                        dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnAbnormalExitSetting + "=True";
                    }
                    if (_pyService.DebuggerOptions.WaitOnNormalExit)
                    {
                        dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnNormalExitSetting + "=True";
                    }
                }
                if (_pyService.DebuggerOptions.TeeStandardOutput)
                {
                    dbgInfo.bstrOptions += ";" + AD7Engine.RedirectOutputSetting + "=True";
                }
                if (_pyService.DebuggerOptions.BreakOnSystemExitZero)
                {
                    dbgInfo.bstrOptions += ";" + AD7Engine.BreakSystemExitZero + "=True";
                }
                if (_pyService.DebuggerOptions.DebugStdLib)
                {
                    dbgInfo.bstrOptions += ";" + AD7Engine.DebugStdLib + "=True";
                }
                if (!String.IsNullOrWhiteSpace(interpArgs))
                {
                    dbgInfo.bstrOptions += ";" + AD7Engine.InterpreterOptions + "=" + interpArgs.Replace(";", ";;");
                }

                var  djangoDebugging = _project.GetProperty("DjangoDebugging");
                bool enableDjango;
                if (!String.IsNullOrWhiteSpace(djangoDebugging) && Boolean.TryParse(djangoDebugging, out enableDjango))
                {
                    dbgInfo.bstrOptions += ";" + AD7Engine.EnableDjangoDebugging + "=True";
                }
            }

            var env = new Dictionary <string, string>(props.GetEnvironment(true));

            PythonProjectLaunchProperties.MergeEnvironmentBelow(env, null, true);
            if (env.Any())
            {
                //Environment variables should be passed as a
                //null-terminated block of null-terminated strings.
                //Each string is in the following form:name=value\0
                var buf = new StringBuilder();
                foreach (var kv in env)
                {
                    buf.AppendFormat("{0}={1}\0", kv.Key, kv.Value);
                }
                buf.Append("\0");
                dbgInfo.bstrEnv = buf.ToString();
            }

            if (props.GetIsNativeDebuggingEnabled() ?? false)
            {
                dbgInfo.dwClsidCount = 2;
                dbgInfo.pClsidList   = Marshal.AllocCoTaskMem(sizeof(Guid) * 2);
                var engineGuids = (Guid *)dbgInfo.pClsidList;
                engineGuids[0] = dbgInfo.clsidCustom = DkmEngineId.NativeEng;
                engineGuids[1] = AD7Engine.DebugEngineGuid;
            }
            else
            {
                // Set the Python debugger
                dbgInfo.clsidCustom = new Guid(AD7Engine.DebugEngineId);
                dbgInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
            }
        }