Skip to content

Conversation

@TravisEz13
Copy link
Member

@TravisEz13 TravisEz13 commented Aug 4, 2018

PR Summary

Make sure that SettingFile arg is parsed before we load the settings

  • Add ability to parse some setting before console host is created
  • Trigger the Parse before the console host is created
  • disable snapin loading from loading setting before this point
  • re-enable mac logging tests.

Also, fix the following Travis-ci issues:

  • make sure the Linux and macOS caches are separate to reduce the size
  • update the macOS image to the closest image as used by the official build system (equivalent to VSTS hosted mac builds)

PR Checklist

@TravisEz13 TravisEz13 force-pushed the fix_settings_issue branch 2 times, most recently from f98c185 to ebf9239 Compare August 5, 2018 03:01
{
if (consoleSessionSetting.EnableConsoleSessionConfiguration == true)
{
if (!string.IsNullOrEmpty(consoleSessionSetting.ConsoleSessionConfigurationName))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could combine three if in one or use ? operator in just single return.

if (MatchSwitch(switchKey, "settingsfile", "settings"))
{
// parse setting file arg and don't write error as there is no host yet.
if (!ParseSettingFileHelper(args, ++i, null))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use TryParseSettingFileHelper?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

{
if (switchKey.Length >= smallestUnambiguousMatch.Length)
{
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could exclude if-s and use single return.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I don't follow what you are saying.

Well, looking at the code, I made a guess.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant

return (match.Trim().ToLowerInvariant().IndexOf(switchKey, StringComparison.Ordinal) == 0) && (switchKey.Length >= smallestUnambiguousMatch.Length)

{
// We need to read the settings file before we create the console host
string[] tempArgs = new string[args.GetLength(0)];
args.CopyTo(tempArgs, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why we need clone args?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code cloned the args. I don't want to break something by not cloning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing the code. I don't think it has to be. I especially don't think it has to be twice. compromise, I'll remove the second clone, you file an issue to remove the first one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done #7457.

}

#region Internal properties
internal bool AbortStartup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should #region be in position with the line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@TravisEz13
Copy link
Member Author

@iSazonov I believe I have addressed all your comments one way or another.

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment

/// The command line parameters to be processed.
/// </param>
/// <param name="argIndex">
/// The index in args to the argument following '-SettingFile'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name is generic but comment says that it is used only for '-SettingFile' - should the parameter name reflects the fact?

var consoleSessionSetting = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);

return (consoleSessionSetting?.EnableConsoleSessionConfiguration == true && !string.IsNullOrEmpty(consoleSessionSetting?.ConsoleSessionConfigurationName)) ?
consoleSessionSetting.ConsoleSessionConfigurationName : string.Empty;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use more short name like settings to get more short code strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an existing variable name. Please file an issues

bool noexitSeen = false;
for (int i = 0; i < args.Length; ++i)
{
var switchKeyResults = GetSwitchKey(args, ref i, null, ref noexitSeen);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear that we get from the method. I'd replace var with explicit type.
Can we use:

(string switchKey, bool shouldBreak) = GetSwitchKey(args, ref i, null, ref noexitSeen); 

Named argument for null will be good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved


string switchKey = switchKeyResults.SwitchKey;

if (MatchSwitch(switchKey, "settingsfile", "settings"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named arguments will be good for constants. Below I see some such patterns.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

path = path.Replace(StringLiterals.AlternatePathSeparator,
StringLiterals.DefaultPathSeparator);

return Path.GetFullPath(path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is used once and then we call File.Exist() where Path.GetFullPath() is called again.
https://source.dot.net/#System.IO.FileSystem/System/IO/File.cs,119
We could simplify the TryParseSettingFileHelper() method - remove try-catch there (line 429), move the line 574 to TryParseSettingFileHelper() before File.Exist()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existing code, please file an issue, the method was just changed from an instance to static

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done #7469.

$testPid = & $powershell -NoLogo -NoProfile -SettingsFile $configFile -Command '$PID'

Export-PSOsLog -After $after -Verbose | Set-Content -Path $contentFile
Export-PSOsLog -after $after -LogPid $testPid -Verbose | Set-Content -Path $contentFile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert -after to -After.

{
configFile = NormalizeFilePath(args[argIndex]);
}
catch (Exception ex)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we could remove the try-catch. See my comment for NormalizeFilePath() method.

Copy link
Contributor

@dantraMSFT dantraMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of my comments are blocking but recommend you reconsider adding release logic for the new Dbg.Assert calls.



class PSLogItem
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest updating the comment block at the top of the file to call out the change in format.
Other than that, this file LGTM

env: TRAVIS_CI_CACHE_NAME=linux
- os: osx
osx_image: xcode8.1
osx_image: xcode9.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this means we won't be running tests against the prior OS version, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no differences in the log format, but yes correct

/// </param>
internal static void EarlyParse(string[] args)
{
Dbg.Assert(!_dirtyEarlyParse, "This instance has already been used. Create a new instance.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert message is misleading. The method can only be called once since _dirtyEarlyParse is a static field.
Additionally, back this up with a release test or simply return if true. We don't run debug tests enough to catch this problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, I verified this can be run multiple times

/// </param>
private static void EarlyParseHelper(string[] args)
{
Dbg.Assert(args != null, "Argument 'args' to ParseHelper should never be null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back this up with a check in release mode. At a minimum, silently ignore and return.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

/// The index in args to the argument to process.
/// </param>
/// <param name="parser">
/// Used to allow the helper to write errors to the console. If not supplied, Files will not be parsed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about writing errors doesn't appear to apply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated comment (I have not pushed at this point.)

string[] tempArgs = new string[args.GetLength(0)];
args.CopyTo(tempArgs, 0);

CommandLineParameterParser.EarlyParse(tempArgs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created issue #7460 to move this call to UnmanagedPSEntry.Start prior to PSEtwLog.LogConsoleStartup().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Export-PSOsLog -After $after -Verbose | Set-Content -Path $contentFile
$items = Get-PSOsLog -Path $contentFile -Id $logId -After $after -TotalCount 3 -Verbose
# Made tests more reliable
Start-Sleep -Milliseconds 500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created issue #7462 to address the Start-Sleep workaround as well as the possible false-positive in filtering test below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure tuple field names are case sensitive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@TravisEz13 TravisEz13 merged commit 1523c21 into PowerShell:master Aug 7, 2018
@TravisEz13 TravisEz13 deleted the fix_settings_issue branch August 7, 2018 22:01
@iSazonov iSazonov mentioned this pull request Oct 1, 2018
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants