Ejemplo n.º 1
0
        void LogSettings()
        {
            // Log all vars
            const bool bQuiet = true;

            Log.TraceInformation("Detected Perforce Settings:");
            Log.TraceInformation("    Port: {0}", InternalUtils.GetEnvironmentVariable(EnvVarNames.P4Port, "", bQuiet));
            Log.TraceInformation("    User: {0}", InternalUtils.GetEnvironmentVariable(EnvVarNames.User, "", bQuiet));
            Log.TraceInformation("    Client: {0}", InternalUtils.GetEnvironmentVariable(EnvVarNames.Client, "", bQuiet));
            Log.TraceInformation("    Branch: {0}", InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootP4, "", bQuiet));
            Log.TraceInformation("    Last Change: {0}", InternalUtils.GetEnvironmentVariable(EnvVarNames.Changelist, "", bQuiet));
            Log.TraceInformation("    Last Code Change: {0}", InternalUtils.GetEnvironmentVariable(EnvVarNames.CodeChangelist, "", bQuiet));

            Log.TraceLog("Perforce Environment Variables:");
            Log.TraceLog("    {0}={1}", EnvVarNames.P4Port, InternalUtils.GetEnvironmentVariable(EnvVarNames.P4Port, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.User, InternalUtils.GetEnvironmentVariable(EnvVarNames.User, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.Client, InternalUtils.GetEnvironmentVariable(EnvVarNames.Client, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.BuildRootP4, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootP4, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.BuildRootEscaped, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootEscaped, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.ClientRoot, InternalUtils.GetEnvironmentVariable(EnvVarNames.ClientRoot, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.Changelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.Changelist, "", bQuiet));
            Log.TraceLog("    {0}={1}", EnvVarNames.CodeChangelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.CodeChangelist, "", bQuiet));
            Log.TraceLog("    {0}={1}", "P4USER", InternalUtils.GetEnvironmentVariable("P4USER", "", bQuiet));
            Log.TraceLog("    {0}={1}", "P4CLIENT", InternalUtils.GetEnvironmentVariable("P4CLIENT", "", bQuiet));
        }
Ejemplo n.º 2
0
        void LogSettings()
        {
            // Log all vars
            const bool bQuiet = true;

            Log.TraceInformation("Perforce Environment settings:");
            Log.TraceInformation("{0}={1}", EnvVarNames.P4Port, InternalUtils.GetEnvironmentVariable(EnvVarNames.P4Port, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.User, InternalUtils.GetEnvironmentVariable(EnvVarNames.User, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.Client, InternalUtils.GetEnvironmentVariable(EnvVarNames.Client, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.BuildRootP4, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootP4, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.BuildRootEscaped, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootEscaped, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.ClientRoot, InternalUtils.GetEnvironmentVariable(EnvVarNames.ClientRoot, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.Changelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.Changelist, "", bQuiet));
            Log.TraceInformation("{0}={1}", EnvVarNames.LabelToSync, InternalUtils.GetEnvironmentVariable(EnvVarNames.LabelToSync, "", bQuiet));
            Log.TraceInformation("{0}={1}", "P4USER", InternalUtils.GetEnvironmentVariable("P4USER", "", bQuiet));
            Log.TraceInformation("{0}={1}", "P4CLIENT", InternalUtils.GetEnvironmentVariable("P4CLIENT", "", bQuiet));
            Log.TraceInformation("LabelPrefix={0}", LabelPrefix);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor. Derives the Perforce environment settings.
        /// </summary>
        internal P4Environment(CommandEnvironment CmdEnv)
        {
            // Get the Perforce port setting
            ServerAndPort = CommandUtils.GetEnvVar(EnvVarNames.P4Port);
            if (String.IsNullOrEmpty(ServerAndPort))
            {
                ServerAndPort = DetectP4Port();
                CommandUtils.SetEnvVar(EnvVarNames.P4Port, ServerAndPort);
            }

            // Get the Perforce user setting
            User = CommandUtils.GetEnvVar(EnvVarNames.User);
            if (String.IsNullOrEmpty(User))
            {
                P4Connection DefaultConnection = new P4Connection(User: null, Client: null, ServerAndPort: ServerAndPort);
                User = DetectUserName(DefaultConnection);
                CommandUtils.SetEnvVar(EnvVarNames.User, User);
            }

            // Get the Perforce client setting
            Client = CommandUtils.GetEnvVar(EnvVarNames.Client);
            if (String.IsNullOrEmpty(Client))
            {
                P4Connection DefaultConnection = new P4Connection(User: User, Client: null, ServerAndPort: ServerAndPort);
                P4ClientInfo ThisClient        = DetectClient(DefaultConnection, User, Environment.MachineName.ToLower(), CmdEnv.UATExe);
                Log.TraceInformation("Using user {0} clientspec {1} {2}", User, ThisClient.Name, ThisClient.RootPath);

                string       BranchPath;
                string       ClientRootPath;
                P4Connection ClientConnection = new P4Connection(User: User, Client: ThisClient.Name, ServerAndPort: ServerAndPort);
                DetectRootPaths(ClientConnection, CmdEnv.LocalRoot, ThisClient, out BranchPath, out ClientRootPath);

                Client = ThisClient.Name;
                CommandUtils.SetEnvVar(EnvVarNames.Client, Client);

                Branch = BranchPath;
                CommandUtils.SetEnvVar(EnvVarNames.BuildRootP4, Branch);

                ClientRoot = ClientRootPath;
                CommandUtils.SetEnvVar(EnvVarNames.ClientRoot, ClientRootPath);
            }
            else
            {
                Branch     = CommandUtils.GetEnvVar(EnvVarNames.BuildRootP4);
                ClientRoot = CommandUtils.GetEnvVar(EnvVarNames.ClientRoot);
                if (String.IsNullOrEmpty(Branch) || String.IsNullOrEmpty(ClientRoot))
                {
                    throw new AutomationException("{0} and {1} must also be set with {2}", EnvVarNames.ClientRoot, EnvVarNames.BuildRootP4, EnvVarNames.Client);
                }
            }

            // We expect the build root to not end with a path separator
            if (Branch.EndsWith("/"))
            {
                Branch = Branch.TrimEnd('/');
                CommandUtils.SetEnvVar(EnvVarNames.BuildRootP4, Branch);
            }

            // Set the current changelist
            string ChangelistString = CommandUtils.GetEnvVar(EnvVarNames.Changelist, null);

            if (String.IsNullOrEmpty(ChangelistString) && CommandUtils.P4CLRequired)
            {
                P4Connection Connection = new P4Connection(User, Client, ServerAndPort);
                ChangelistString = DetectCurrentCL(Connection, ClientRoot);
                CommandUtils.SetEnvVar(EnvVarNames.Changelist, ChangelistString);
            }
            if (!String.IsNullOrEmpty(ChangelistString))
            {
                Changelist = int.Parse(ChangelistString);
            }

            // Set the current code changelist
            string CodeChangelistString = CommandUtils.GetEnvVar(EnvVarNames.CodeChangelist);

            if (String.IsNullOrEmpty(CodeChangelistString) && CommandUtils.P4CLRequired)
            {
                P4Connection Connection = new P4Connection(User, Client, ServerAndPort);
                CodeChangelistString = DetectCurrentCodeCL(Connection, ClientRoot);
                CommandUtils.SetEnvVar(EnvVarNames.CodeChangelist, CodeChangelistString);
            }
            if (!String.IsNullOrEmpty(CodeChangelistString))
            {
                CodeChangelist = int.Parse(CodeChangelistString);
            }

            // Set the standard environment variables based on the values we've found
            CommandUtils.SetEnvVar("P4PORT", ServerAndPort);
            CommandUtils.SetEnvVar("P4USER", User);
            CommandUtils.SetEnvVar("P4CLIENT", Client);

            // Write a summary of the settings to the output window
            if (!CommandUtils.CmdEnv.IsChildInstance)
            {
                Log.TraceInformation("Detected Perforce Settings:");
                Log.TraceInformation("  Server: {0}", ServerAndPort);
                Log.TraceInformation("  User: {0}", User);
                Log.TraceInformation("  Client: {0}", Client);
                Log.TraceInformation("  Branch: {0}", Branch);
                if (ChangelistInternal != -1)
                {
                    Log.TraceInformation("  Last Change: {0}", Changelist);
                }
                if (CodeChangelistInternal != -1)
                {
                    Log.TraceInformation("  Last Code Change: {0}", CodeChangelist);
                }
            }

            // Write all the environment variables to the log
            Log.TraceLog("Perforce Environment Variables:");
            Log.TraceLog("  {0}={1}", EnvVarNames.P4Port, InternalUtils.GetEnvironmentVariable(EnvVarNames.P4Port, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.User, InternalUtils.GetEnvironmentVariable(EnvVarNames.User, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.Client, InternalUtils.GetEnvironmentVariable(EnvVarNames.Client, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.BuildRootP4, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootP4, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.BuildRootEscaped, InternalUtils.GetEnvironmentVariable(EnvVarNames.BuildRootEscaped, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.ClientRoot, InternalUtils.GetEnvironmentVariable(EnvVarNames.ClientRoot, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.Changelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.Changelist, "", true));
            Log.TraceLog("  {0}={1}", EnvVarNames.CodeChangelist, InternalUtils.GetEnvironmentVariable(EnvVarNames.CodeChangelist, "", true));
            Log.TraceLog("  {0}={1}", "P4PORT", InternalUtils.GetEnvironmentVariable("P4PORT", "", true));
            Log.TraceLog("  {0}={1}", "P4USER", InternalUtils.GetEnvironmentVariable("P4USER", "", true));
            Log.TraceLog("  {0}={1}", "P4CLIENT", InternalUtils.GetEnvironmentVariable("P4CLIENT", "", true));
        }