Skip to content

Commit a213190

Browse files
authored
Add option for using custom license text (#1262)
1 parent 983f659 commit a213190

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

cppwinrt/code_writers.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ namespace cppwinrt
2424
{
2525
w.write(R"(// C++/WinRT v%
2626
27-
// Copyright (c) Microsoft Corporation. All rights reserved.
28-
// Licensed under the MIT License.
29-
30-
)", CPPWINRT_VERSION_STRING);
27+
%
28+
)", CPPWINRT_VERSION_STRING, settings.license_template);
3129
}
3230
else
3331
{

cppwinrt/main.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace cppwinrt
3434
{ "?", 0, option::no_max, {}, {} },
3535
{ "library", 0, 1, "<prefix>", "Specify library prefix (defaults to winrt)" },
3636
{ "filter" }, // One or more prefixes to include in input (same as -include)
37-
{ "license", 0, 0 }, // Generate license comment
37+
{ "license", 0, 1, "[<path>]", "Generate license comment from template file" },
3838
{ "brackets", 0, 0 }, // Use angle brackets for #includes (defaults to quotes)
3939
{ "fastabi", 0, 0 }, // Enable support for the Fast ABI
4040
{ "ignore_velocity", 0, 0 }, // Ignore feature staging metadata and always include implementations
@@ -115,6 +115,40 @@ R"( local Local ^%WinDir^%\System32\WinMetadata folder
115115
settings.exclude.insert(exclude);
116116
}
117117

118+
if (settings.license)
119+
{
120+
std::string license_arg = args.value("license");
121+
if (license_arg.empty())
122+
{
123+
settings.license_template = R"(// Copyright (c) Microsoft Corporation. All rights reserved.
124+
// Licensed under the MIT License.
125+
)";
126+
}
127+
else
128+
{
129+
std::filesystem::path template_path{ license_arg };
130+
std::ifstream template_file(absolute(template_path));
131+
if (template_file.fail())
132+
{
133+
throw_invalid("Cannot read license template file '", absolute(template_path).string() + "'");
134+
}
135+
std::string line_buf;
136+
while (getline(template_file, line_buf))
137+
{
138+
if (line_buf.empty())
139+
{
140+
settings.license_template += "//\n";
141+
}
142+
else
143+
{
144+
settings.license_template += "// ";
145+
settings.license_template += line_buf;
146+
settings.license_template += "\n";
147+
}
148+
}
149+
}
150+
}
151+
118152
if (settings.component)
119153
{
120154
settings.component_overwrite = args.exists("overwrite");

cppwinrt/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace cppwinrt
1010
std::string output_folder;
1111
bool base{};
1212
bool license{};
13+
std::string license_template;
1314
bool brackets{};
1415
bool verbose{};
1516
bool component{};

0 commit comments

Comments
 (0)