Skip to content

Commit 6540534

Browse files
authored
Dscv3 source resource (#5418)
## Change Add a new DSC v3 resource: `source`. This largely follows the design of the v2 resource, but uses the v3 paradigm for existence. Other minor changes: - Refactor the existing package resource tests into a test base. - Fix an issue building valijson.
1 parent 3556a3e commit 6540534

File tree

16 files changed

+1185
-132
lines changed

16 files changed

+1185
-132
lines changed

src/AppInstallerCLICore/AppInstallerCLICore.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
<ClInclude Include="Commands\DscCommandBase.h" />
307307
<ClInclude Include="Commands\DscComposableObject.h" />
308308
<ClInclude Include="Commands\DscPackageResource.h" />
309+
<ClInclude Include="Commands\DscSourceResource.h" />
309310
<ClInclude Include="Commands\DscTestFileResource.h" />
310311
<ClInclude Include="Commands\DscTestJsonResource.h" />
311312
<ClInclude Include="Commands\ErrorCommand.h" />
@@ -392,6 +393,7 @@
392393
<ClCompile Include="Commands\DscCommandBase.cpp" />
393394
<ClCompile Include="Commands\DscComposableObject.cpp" />
394395
<ClCompile Include="Commands\DscPackageResource.cpp" />
396+
<ClCompile Include="Commands\DscSourceResource.cpp" />
395397
<ClCompile Include="Commands\DscTestFileResource.cpp" />
396398
<ClCompile Include="Commands\DscTestJsonResource.cpp" />
397399
<ClCompile Include="Commands\ErrorCommand.cpp" />

src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@
284284
<ClInclude Include="Commands\DscPackageResource.h">
285285
<Filter>Commands\Configuration</Filter>
286286
</ClInclude>
287+
<ClInclude Include="Commands\DscSourceResource.h">
288+
<Filter>Commands\Configuration</Filter>
289+
</ClInclude>
287290
</ItemGroup>
288291
<ItemGroup>
289292
<ClCompile Include="pch.cpp">
@@ -535,6 +538,9 @@
535538
<ClCompile Include="Commands\DscPackageResource.cpp">
536539
<Filter>Commands\Configuration</Filter>
537540
</ClCompile>
541+
<ClCompile Include="Commands\DscSourceResource.cpp">
542+
<Filter>Commands\Configuration</Filter>
543+
</ClCompile>
538544
</ItemGroup>
539545
<ItemGroup>
540546
<None Include="PropertySheet.props" />

src/AppInstallerCLICore/Commands/DscCommand.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "pch.h"
44
#include "DscCommand.h"
55
#include "DscPackageResource.h"
6+
#include "DscSourceResource.h"
67

78
#ifndef AICLI_DISABLE_TEST_HOOKS
89
#include "DscTestFileResource.h"
@@ -15,6 +16,7 @@ namespace AppInstaller::CLI
1516
{
1617
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
1718
std::make_unique<DscPackageResource>(FullName()),
19+
std::make_unique<DscSourceResource>(FullName()),
1820
#ifndef AICLI_DISABLE_TEST_HOOKS
1921
std::make_unique<DscTestFileResource>(FullName()),
2022
std::make_unique<DscTestJsonResource>(FullName()),

src/AppInstallerCLICore/Commands/DscComposableObject.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ namespace AppInstaller::CLI
101101
//
102102
// struct Property
103103
// {
104-
// using Type = { bool, std::string };
104+
// using PropertyType = { bool, std::string };
105105
// static std::string_view Name();
106106
// static void FromJson(Property*, const Json::Value*);
107107
// static std::optional<Json::Value> ToJson(const Property*);
108108
//
109-
// const Type& PROPERTY_NAME() const;
110-
// void PROPERTY_NAME(const Type&);
109+
// const PropertyType& PROPERTY_NAME() const;
110+
// void PROPERTY_NAME(const PropertyType&);
111111
// }
112112
template <typename... Property>
113113
struct DscComposableObject : public Property...
@@ -149,15 +149,15 @@ namespace AppInstaller::CLI
149149
static Json::Value Schema(const std::string& title)
150150
{
151151
Json::Value result = details::GetBaseSchema(title);
152-
(FoldHelper{}, ..., details::AddPropertySchema(result, Property::Name(), Property::Flags, GetJsonTypeValue<typename Property::Type>::SchemaType(), Property::Description(), Property::EnumValues(), Property::Default()));
152+
(FoldHelper{}, ..., details::AddPropertySchema(result, Property::Name(), Property::Flags, GetJsonTypeValue<typename Property::PropertyType>::SchemaType(), Property::Description(), Property::EnumValues(), Property::Default()));
153153
return result;
154154
}
155155
};
156156

157-
template <typename Derived, typename PropertyType, DscComposablePropertyFlag PropertyFlags>
157+
template <typename Derived, typename PropertyTypeT, DscComposablePropertyFlag PropertyFlags>
158158
struct DscComposableProperty
159159
{
160-
using Type = PropertyType;
160+
using PropertyType = PropertyTypeT;
161161
static constexpr DscComposablePropertyFlag Flags = PropertyFlags;
162162

163163
static void FromJson(Derived* self, const Json::Value* value, bool ignoreFieldRequirements)
@@ -201,7 +201,7 @@ namespace AppInstaller::CLI
201201
}
202202

203203
protected:
204-
std::optional<Type> m_value;
204+
std::optional<PropertyType> m_value;
205205
};
206206

207207
#define WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_IMPL_START(_property_type_, _value_type_, _property_name_, _json_name_, _flags_, _description_, _enum_vals_, _default_) \
@@ -211,9 +211,9 @@ namespace AppInstaller::CLI
211211
static Resource::LocString Description() { return _description_; } \
212212
static std::vector<std::string> EnumValues() { return std::vector<std::string> _enum_vals_; } \
213213
static std::optional<std::string> Default() { return _default_; } \
214-
std::optional<Type>& _property_name_() { return m_value; } \
215-
const std::optional<Type>& _property_name_() const { return m_value; } \
216-
void _property_name_(std::optional<Type> value) { m_value = std::move(value); } \
214+
std::optional<PropertyType>& _property_name_() { return m_value; } \
215+
const std::optional<PropertyType>& _property_name_() const { return m_value; } \
216+
void _property_name_(std::optional<PropertyType> value) { m_value = std::move(value); } \
217217

218218
#define WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_IMPL(_property_type_, _value_type_, _property_name_, _json_name_, _flags_, _description_, _enum_vals_, _default_) \
219219
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_IMPL_START(_property_type_, _value_type_, _property_name_, _json_name_, _flags_, _description_, _enum_vals_, _default_) \

src/AppInstallerCLICore/Commands/DscPackageResource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace AppInstaller::CLI
2424
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(MatchOptionProperty, std::string, MatchOption, "matchOption", Resource::String::DscResourcePropertyDescriptionPackageMatchOption, ({ "equals", "equalsCaseInsensitive", "startsWithCaseInsensitive", "containsCaseInsensitive" }), "equalsCaseInsensitive");
2525
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_DEFAULT(UseLatestProperty, bool, UseLatest, "useLatest", Resource::String::DscResourcePropertyDescriptionPackageUseLatest, "false");
2626
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(InstallModeProperty, std::string, InstallMode, "installMode", Resource::String::DscResourcePropertyDescriptionPackageInstallMode, ({ "default", "silent", "interactive" }), "silent");
27-
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY(AcceptAgreementsProperty, bool, AcceptAgreements, "acceptAgreements", Resource::String::DscResourcePropertyDescriptionPackageAcceptAgreements);
27+
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY(AcceptAgreementsProperty, bool, AcceptAgreements, "acceptAgreements", Resource::String::DscResourcePropertyDescriptionAcceptAgreements);
2828

2929
// TODO: To support Scope on this resource:
3030
// 1. Change the installed source to pull in all package info for both scopes by default

0 commit comments

Comments
 (0)