Skip to content

Commit

Permalink
Release new version of vswhere (#259)
Browse files Browse the repository at this point in the history
* Update docker image (#240)

* Update microbuild pool to VS2019

* Use correct pool name

* Update docker images

* Colorize vswhere output (#244)

* Refactor formatters to consolidate arguments

* Colorize output by default unless piped

* Opt into color and add tests

Fails in PowerShell if you do something like `[xml](vswhere -format xml)` if color is enabled, so had to add -color switch. Not ideal since it otherwise disables color when piped, but still easier to read if colorized explicitly.

* Enable colors by default, add -nocolor switch

* Resolve PR feedback

* Ensure console is initialized

Could simply call Initialize wherever it needs to be called, but would rather be explicit.

* Update AzDO build to use new 1ES pool

* Add compliance build

* Update targeting to Windows 7

* Enable ControlFlowGuard

* Fix Prefast errors in source

* Fix test prefast issues

* Update to latest cached docker image

* Suppress individual prefast warnings for fallthrough cases

* FIxup comments for variants

* Upgrade agent to Server 2019 with VS2019 (#260)

Co-authored-by: Laurel Williams <20650063+lwillia@users.noreply.github.com>
Co-authored-by: Davi Paulino <dalimapa@microsoft.com>
Co-authored-by: Davi Paulino <davilimap@gmail.com>
Co-authored-by: Tyler Dunkel <40210514+tydunkel@users.noreply.github.com>
  • Loading branch information
5 people committed Feb 25, 2022
1 parent ff0de50 commit e2e4e03
Show file tree
Hide file tree
Showing 49 changed files with 775 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .vsconfig
Expand Up @@ -14,7 +14,7 @@
"Microsoft.VisualStudio.Component.VC.DiagnosticTools",
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Component.Windows10SDK.16299",
"Microsoft.VisualStudio.Component.Windows10SDK.17763",
"Microsoft.VisualStudio.Component.VC.v141.x86.x64",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.Component.Git",
Expand Down
2 changes: 1 addition & 1 deletion .vsts-ci.yml
Expand Up @@ -14,7 +14,7 @@ trigger:
pr: none

queue:
name: VSEng-MicroBuildVS2017
name: VSEngSS-MicroBuild2019-1ES
timeoutInMinutes: 120
demands:
- ChocolateyInstall
Expand Down
78 changes: 78 additions & 0 deletions .vsts-compliance.yml
@@ -0,0 +1,78 @@
# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt in the project root for license information.

trigger:
batch: true
branches:
include:
- master
- develop
paths:
exclude:
- README.md

pr: none

queue:
name: VSEngSS-MicroBuild2019-1ES
timeoutInMinutes: 120
demands:
- ChocolateyInstall
- MSBuild
- VisualStudio
- VSTest

steps:
- template: inc/build.yml
parameters:
BuildConfiguration: $(BuildConfiguration)
BuildPlatform: $(BuildPlatform)
Sign: false

- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
displayName: Detect components
inputs:
sourceScanPath: $(Build.SourcesDirectory)

- task: securedevelopmentteam.vss-secure-development-tools.build-task-prefast.SDLNativeRules@2
displayName: 'Run the PREfast SDL Native Rules for MSBuild'
continueOnError: true

- task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@1
displayName: 'Run PoliCheck'
inputs:
targetType: F
targetArgument: '$(Build.SourcesDirectory)'
optionsFC: 0
optionsXS: 1
optionsHMENABLE: 0
continueOnError: true

- task: securedevelopmentteam.vss-secure-development-tools.build-task-binskim.BinSkim@3
displayName: 'Run BinSkim'
inputs:
InputType: Basic
Function: analyze
AnalyzeTarget: 'bin\$(BuildConfiguration)\*.exe'
AnalyzeSymPath: 'bin\$(BuildConfiguration)'
AnalyzeVerbose: true
AnalyzeHashes: true
continueOnError: true

- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
displayName: 'Run CredScan'
inputs:
debugMode: false

# Publish compliance results
- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
displayName: 'Publish Security Analysis Logs'

- task: securedevelopmentteam.vss-secure-development-tools.build-task-postanalysis.PostAnalysis@1
displayName: Check SDL results
inputs:
AllTools: true

- task: ms-vseng.MicroBuildTasks.521a94ea-9e68-468a-8167-6dcf361ea776.MicroBuildCleanup@1
displayName: Clean up
condition: succeededOrFailed()
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Expand Up @@ -13,7 +13,7 @@ pr:
- README.md

pool:
vmImage: vs2017-win2016
vmImage: windows-2019

variables:
BuildConfiguration: Release
Expand Down
2 changes: 1 addition & 1 deletion docker/Debug.dockerfile
Expand Up @@ -4,7 +4,7 @@
# Licensed under the MIT license. See LICENSE.txt in the project root for license information.

# Based on latest image cached by Azure Pipelines: https://docs.microsoft.com/azure/devops/pipelines/agents/hosted#software
FROM microsoft/windowsservercore@sha256:c60a7376f5147e40b65c51fce34ac17710742f97e91b5c3a71e1667e671112f1
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]

ENV INSTALLER_VERSION=1.14.190.31519 `
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Expand Up @@ -4,7 +4,7 @@
# Licensed under the MIT license. See LICENSE.txt in the project root for license information.

# Based on latest image cached by Azure Pipelines: https://docs.microsoft.com/azure/devops/pipelines/agents/hosted#software
FROM microsoft/windowsservercore@sha256:05de0a0ac13d3652bd1f2281b8589459ebb611092e3fe4d8f1be91f1f6984266
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]

ENV INSTALLER_VERSION=1.14.190.31519 `
Expand Down
8 changes: 6 additions & 2 deletions src/vswhere.lib/CommandArgs.cpp
Expand Up @@ -110,9 +110,9 @@ void CommandArgs::Parse(_In_ vector<CommandParser::Token> args)
else if (ArgumentEquals(arg.Value, L"format"))
{
auto format = ParseArgument(it, args.end(), arg);
auto it = Formatter::Formatters.find(format);
auto formatterIt = Formatter::Formatters.find(format);

if (it != Formatter::Formatters.end())
if (formatterIt != Formatter::Formatters.end())
{
m_format = format;
}
Expand Down Expand Up @@ -161,6 +161,10 @@ void CommandArgs::Parse(_In_ vector<CommandParser::Token> args)

m_find = ParseArgument(it, args.end(), arg);
}
else if (ArgumentEquals(arg.Value, L"nocolor"))
{
m_nocolor = true;
}
else if (ArgumentEquals(arg.Value, L"nologo"))
{
m_nologo = true;
Expand Down
8 changes: 8 additions & 0 deletions src/vswhere.lib/CommandArgs.h
Expand Up @@ -17,6 +17,7 @@ class CommandArgs
m_legacy(false),
m_prerelease(false),
m_includePackages(false),
m_nocolor(false),
m_nologo(false),
m_utf8(false),
m_help(false)
Expand All @@ -39,6 +40,7 @@ class CommandArgs
m_property(obj.m_property),
m_includePackages(obj.m_includePackages),
m_find(obj.m_find),
m_nocolor(obj.m_nocolor),
m_nologo(obj.m_nologo),
m_utf8(obj.m_utf8),
m_help(obj.m_help)
Expand Down Expand Up @@ -130,6 +132,11 @@ class CommandArgs
return m_find;
}

const bool get_Color() const noexcept
{
return !m_nocolor;
}

const bool get_Logo() const noexcept
{
return !m_nologo;
Expand Down Expand Up @@ -172,6 +179,7 @@ class CommandArgs
std::wstring m_property;
bool m_includePackages;
std::wstring m_find;
bool m_nocolor;
bool m_nologo;
bool m_utf8;
bool m_help;
Expand Down
2 changes: 1 addition & 1 deletion src/vswhere.lib/CommandParser.cpp
Expand Up @@ -20,7 +20,7 @@ vector<CommandParser::Token> CommandParser::Parse(_In_ LPCWSTR wszCommandLine)
}

// Make sure the argument array is released when it falls out of scope.
unique_ptr<LPWSTR*, void(*)(LPWSTR**)> args(&argv, [](LPWSTR** ppwsz)
unique_ptr<LPWSTR*, void(*)(LPWSTR**)> args(&argv, [](_In_opt_ LPWSTR** ppwsz)
{
if (ppwsz)
{
Expand Down
48 changes: 41 additions & 7 deletions src/vswhere.lib/Console.cpp
Expand Up @@ -13,24 +13,45 @@ void Console::Initialize() noexcept
{
if (m_args.get_UTF8())
{
::_setmode(_fileno(stdout), _O_U8TEXT);
static_cast<void>(::_setmode(_fileno(stdout), _O_U8TEXT));
}
else if (IsConsole(stdout))
{
::_setmode(_fileno(stdout), _O_WTEXT);
static_cast<void>(::_setmode(_fileno(stdout), _O_WTEXT));
}
else
{
char sz[10];
::sprintf_s(sz, ".%d", ::GetConsoleCP());
::sprintf_s(sz, ".%u", ::GetConsoleCP());

::setlocale(LC_CTYPE, sz);
}

m_fColorSupported = IsVirtualTerminal(stdout);
m_fInitialized = true;
}
}

LPCWSTR Console::Color(_In_ LPCWSTR wzColor) const
{
if (IsColorSupported())
{
return wzColor;
}

return L"";
}

LPCWSTR Console::ResetColor() const
{
if (IsColorSupported())
{
return L"\033[0m";
}

return L"";
}

void __cdecl Console::Write(_In_ LPCWSTR wzFormat, ...)
{
va_list args;
Expand All @@ -45,7 +66,7 @@ void __cdecl Console::Write(_In_ const std::wstring& value)
Write(value.c_str(), NULL);
}

void __cdecl Console::WriteLine(_In_ LPCWSTR wzFormat, ...)
void __cdecl Console::WriteLine(_In_opt_ LPCWSTR wzFormat, ...)
{
if (wzFormat)
{
Expand All @@ -66,12 +87,11 @@ void __cdecl Console::WriteLine(_In_ const std::wstring& value)

void Console::Write(_In_ LPCWSTR wzFormat, va_list args)
{
Initialize();

_ASSERTE(m_fInitialized);
::_vwprintf_p(wzFormat, args);
}

bool Console::IsConsole(_In_ FILE* f) const noexcept
bool Console::IsConsole(_In_ FILE* f) noexcept
{
auto fno = ::_fileno(f);
auto hFile = (HANDLE)::_get_osfhandle(fno);
Expand All @@ -92,3 +112,17 @@ bool Console::IsConsole(_In_ FILE* f) const noexcept

return true;
}

bool Console::IsVirtualTerminal(_In_ FILE* f) noexcept
{
auto fno = ::_fileno(f);
auto hFile = (HANDLE)::_get_osfhandle(fno);

DWORD dwMode;
if (::GetConsoleMode(hFile, &dwMode))
{
return 0 != ::SetConsoleMode(hFile, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}

return false;
}
32 changes: 26 additions & 6 deletions src/vswhere.lib/Console.h
Expand Up @@ -10,28 +10,48 @@ class Console
public:
Console(_In_ const CommandArgs& args) :
m_args(args),
m_fInitialized(false)
m_fInitialized(false),
m_fColorSupported(false)
{
}

Console(_In_ const Console& obj) :
m_args(obj.m_args),
m_fInitialized(obj.m_fInitialized)
m_fInitialized(obj.m_fInitialized),
m_fColorSupported(obj.m_fColorSupported)
{
}

virtual void Initialize() noexcept;

LPCWSTR Color(_In_ LPCWSTR wzColor) const;
LPCWSTR ResetColor() const;

void __cdecl Write(_In_ LPCWSTR wzFormat, ...);
void __cdecl Write(_In_ const std::wstring& value);
void __cdecl WriteLine(_In_ LPCWSTR wzFormat = NULL, ...);
void __cdecl WriteLine(_In_opt_ LPCWSTR wzFormat = NULL, ...);
void __cdecl WriteLine(_In_ const std::wstring& value);

virtual bool IsColorSupported() const
{
_ASSERTE(m_fInitialized);
return m_fColorSupported && m_args.get_Color();
}

protected:
virtual void Initialize() noexcept;
virtual void Write(_In_ LPCWSTR wzFormat, va_list args);

const CommandArgs& Args() const noexcept
{
return m_args;
}

bool m_fInitialized;

private:
bool IsConsole(_In_ FILE* f) const noexcept;
bool static IsConsole(_In_ FILE* f) noexcept;
bool static IsVirtualTerminal(_In_ FILE* f) noexcept;

const CommandArgs& m_args;
bool m_fInitialized;
bool m_fColorSupported;
};

0 comments on commit e2e4e03

Please sign in to comment.