Include metadata in release

This commit is contained in:
vczh
2026-06-20 01:14:12 -07:00
parent 8ee7be825b
commit 1112317063
11 changed files with 1190 additions and 33 deletions
+114
View File
@@ -0,0 +1,114 @@
export type PrimitiveTypes = "Boolean" | "Integer" | "Float" | "Double" | "String" | "Char" | "Key" | "Color" | "Binary";
export type StructType = "Struct" | "Class";
export type Type = PrimitiveType | ReferenceType | OptionalType | ArrayType | ArrayMapType | MapType;
export type Declaration = EnumDecl | UnionDecl | StructDecl | MessageDecl | EventDecl;
export interface Declaration_Common {
attributes: (Attribute | null)[];
name: string;
}
export interface PrimitiveType {
$ast: "PrimitiveType";
type: PrimitiveTypes;
}
export interface ReferenceType {
$ast: "ReferenceType";
name: string;
}
export interface OptionalType {
$ast: "OptionalType";
element: Type | null;
}
export interface ArrayType {
$ast: "ArrayType";
element: Type | null;
}
export interface ArrayMapType {
$ast: "ArrayMapType";
element: string;
keyField: string;
}
export interface MapType {
$ast: "MapType";
element: Type | null;
keyType: Type | null;
}
export interface Attribute {
$ast: "Attribute";
name: string;
cppType: string;
}
export interface EnumMember {
$ast: "EnumMember";
name: string;
}
export interface EnumDecl extends Declaration_Common {
$ast: "EnumDecl";
members: (EnumMember | null)[];
}
export interface UnionMember {
$ast: "UnionMember";
name: string;
}
export interface UnionDecl extends Declaration_Common {
$ast: "UnionDecl";
members: (UnionMember | null)[];
}
export interface StructMember {
$ast: "StructMember";
name: string;
type: Type | null;
}
export interface StructDecl extends Declaration_Common {
$ast: "StructDecl";
type: StructType;
members: (StructMember | null)[];
}
export interface MessageRequest {
$ast: "MessageRequest";
type: Type | null;
}
export interface MessageResponse {
$ast: "MessageResponse";
type: Type | null;
}
export interface MessageDecl extends Declaration_Common {
$ast: "MessageDecl";
request: MessageRequest | null;
response: MessageResponse | null;
}
export interface EventRequest {
$ast: "EventRequest";
type: Type | null;
}
export interface EventDecl extends Declaration_Common {
$ast: "EventDecl";
request: EventRequest | null;
}
export interface Schema {
$ast: "Schema";
declarations: (Declaration | null)[];
}
+35
View File
@@ -0,0 +1,35 @@
export type LiteralValue = "True" | "False" | "Null";
export type Node = Literal | String | Number | Array | Object;
export interface Literal {
$ast: "Literal";
value: LiteralValue;
}
export interface String {
$ast: "String";
content: string;
}
export interface Number {
$ast: "Number";
content: string;
}
export interface Array {
$ast: "Array";
items: (Node | null)[];
}
export interface ObjectField {
$ast: "ObjectField";
name: string;
value: Node | null;
}
export interface Object {
$ast: "Object";
fields: (ObjectField | null)[];
}
+139
View File
@@ -0,0 +1,139 @@
export declare const RpcTypeId_IValueEnumerable: -1;
export declare const RpcTypeId_IValueEnumerator: -2;
export declare const RpcTypeId_IValueArray: -3;
export declare const RpcTypeId_IValueList: -4;
export declare const RpcTypeId_IValueObservableList: -5;
export declare const RpcTypeId_IValueDictionary: -6;
export declare const RpcTypeId_IValueReadonlyList: -7;
export declare const RpcMethodId_IValueEnumerable_CreateEnumerator: -1;
export declare const RpcMethodId_IValueEnumerator_Next: -2;
export declare const RpcMethodId_IValueEnumerator_GetCurrent: -3;
export declare const RpcMethodId_IValueReadonlyList_GetCount: -4;
export declare const RpcMethodId_IValueReadonlyList_Get: -5;
export declare const RpcMethodId_IValueList_Set: -6;
export declare const RpcMethodId_IValueList_Add: -7;
export declare const RpcMethodId_IValueList_Insert: -8;
export declare const RpcMethodId_IValueList_RemoveAt: -9;
export declare const RpcMethodId_IValueList_Clear: -10;
export declare const RpcMethodId_IValueReadonlyList_Contains: -11;
export declare const RpcMethodId_IValueReadonlyList_IndexOf: -12;
export declare const RpcMethodId_IValueReadonlyDictionary_GetCount: -13;
export declare const RpcMethodId_IValueReadonlyDictionary_Get: -14;
export declare const RpcMethodId_IValueDictionary_Set: -15;
export declare const RpcMethodId_IValueDictionary_Remove: -16;
export declare const RpcMethodId_IValueDictionary_Clear: -17;
export declare const RpcMethodId_IValueReadonlyDictionary_ContainsKey: -18;
export declare const RpcMethodId_IValueReadonlyDictionary_GetKeys: -19;
export declare const RpcMethodId_IValueReadonlyDictionary_GetValues: -20;
export declare const RpcMethodId_IValueArray_Resize: -21;
export declare const RpcEventId_IValueObservableList_ItemChanged: -1;
export interface system_RpcObjectReference
{
clientId: number;
objectId: number;
typeId: number;
}
export interface system_RpcException
{
message: string;
}
export interface system_RpcByvalReturnValue<T>
{
value: T;
slot: number;
}
export type RpcEventExceptionMap =
| null
| [number, system_RpcException][]
;
export interface MessageBase {
rpcRequestId: number;
sourceClientId: number;
}
export interface BroadcastRequest extends MessageBase {
}
export interface DirectRequest extends MessageBase {
targetClientId: number;
}
export interface IObjectOps_InvokeMethod_Request<T> extends DirectRequest
{
rpcMethod: "Request:IObjectOps_InvokeMethod";
ref: system_RpcObjectReference;
methodId: number;
arguments: T[];
}
export interface IObjectOps_InvokeMethod_Response<T> extends DirectRequest
{
rpcMethod: "Response:IObjectOps_InvokeMethod";
response: T | system_RpcByvalReturnValue<T>;
}
export interface IObjectOps_EndInvokeMethod_Request extends DirectRequest
{
rpcMethod: "Request:IObjectOps_EndInvokeMethod";
slot: number;
}
export interface IObjectOps_EndInvokeMethod_Response extends DirectRequest
{
rpcMethod: "Response:IObjectOps_EndInvokeMethod";
}
export interface IObjectOps_ObjectHold_Request extends DirectRequest
{
rpcMethod: "Request:IObjectOps_ObjectHold";
ref: system_RpcObjectReference;
remoteClientId: number;
hold: boolean;
}
export interface IObjectOps_ObjectHold_Response extends DirectRequest
{
rpcMethod: "Response:IObjectOps_ObjectHold";
}
export interface IObjectEventOps_InvokeEvent_Request<T> extends BroadcastRequest
{
rpcMethod: "Request:IObjectEventOps_InvokeEvent";
ref: system_RpcObjectReference;
eventId: number;
arguments: T[];
}
export interface IRpcDispatcher_DeclareRemoteService_Request extends BroadcastRequest
{
rpcMethod: "Request:IRpcDispatcher_DeclareRemoteService";
ref: system_RpcObjectReference;
}
export interface Broadcast_Response extends DirectRequest
{
rpcMethod: "Response:Broadcast_Response";
response?: RpcEventExceptionMap;
}
export type Request<T> =
| IObjectOps_InvokeMethod_Request<T>
| IObjectOps_EndInvokeMethod_Request
| IObjectOps_ObjectHold_Request
| IObjectEventOps_InvokeEvent_Request<T>
| IRpcDispatcher_DeclareRemoteService_Request
;
export type Response<T> =
| IObjectOps_InvokeMethod_Response<T>
| IObjectOps_EndInvokeMethod_Response
| IObjectOps_ObjectHold_Response
| Broadcast_Response
;
File diff suppressed because it is too large Load Diff
+43
View File
@@ -0,0 +1,43 @@
export type Node = Text | CData | Comment | Element | Instruction | Document;
export interface Text {
$ast: "Text";
content: string;
}
export interface CData {
$ast: "CData";
content: string;
}
export interface Attribute {
$ast: "Attribute";
name: string;
value: string;
}
export interface Comment {
$ast: "Comment";
content: string;
}
export interface Element {
$ast: "Element";
name: string;
closingName: string;
attributes: (Attribute | null)[];
subNodes: (Node | null)[];
}
export interface Instruction {
$ast: "Instruction";
name: string;
attributes: (Attribute | null)[];
}
export interface Document {
$ast: "Document";
prologs: (Node | null)[];
rootElement: Element | null;
}
+41 -2
View File
@@ -18,12 +18,51 @@ extern const vint systemInclude_path;
extern const vint instruction_name;
extern const vint instruction_param;
inline WString ConvertPathDelimiters(const WString& path, wchar_t delimiter)
{
if (path.Length() == 0) return path;
Array<wchar_t> buffer(path.Length() + 1);
for (vint i = 0; i < path.Length(); i++)
{
auto c = path[i];
buffer[i] = (c == L'/' || c == L'\\') ? delimiter : c;
}
buffer[path.Length()] = 0;
return &buffer[0];
}
inline FilePath NormalizePathForFileSystem(const WString& path)
{
return FilePath(ConvertPathDelimiters(path, FilePath::GetPathDelimiter()));
}
inline FilePath NormalizePathForFileSystem(const FilePath& path)
{
return NormalizePathForFileSystem(path.GetFullPath());
}
inline WString GetCodePackPath(const WString& path)
{
return ConvertPathDelimiters(path, L'\\');
}
inline WString GetCodePackCommentPath(const WString& path)
{
auto codePackPath = GetCodePackPath(path);
if (codePackPath.Length() == 0 || codePackPath[0] == L'.')
{
return codePackPath;
}
return L".\\" + codePackPath;
}
inline WString ReadFile(const FilePath& path)
{
WString text;
BomEncoder::Encoding encoding;
bool containsBom;
File(path).ReadAllTextWithEncodingTesting(text, encoding, containsBom);
File(NormalizePathForFileSystem(path)).ReadAllTextWithEncodingTesting(text, encoding, containsBom);
return text;
}
@@ -63,4 +102,4 @@ extern void Combine(
FilePath outputIncludeFilePath,
SortedList<WString>& systemIncludes,
LazyList<WString> externalIncludes
);
);
@@ -27,7 +27,7 @@ void CategorizeCodeFiles(
filterFiles,
From(files).Where([&](const FilePath& f)
{
auto path = f.GetFullPath();
auto path = GetCodePackPath(f.GetFullPath());
return INVLOC.FindFirst(path, pattern, Locale::IgnoreCase).key != -1
&& From(exceptions).All([&](const WString& ex)
{
@@ -60,4 +60,4 @@ void CategorizeCodeFiles(
}
}
}
}
}
+111 -17
View File
@@ -46,14 +46,40 @@ void CombineWriteHeader(
Group<FilePath, Tuple<WString, FilePath>>& conditionOns,
Group<FilePath, Tuple<WString, FilePath>>& conditionOffs,
const List<FilePath>& files,
LazyList<WString> externalIncludes
LazyList<WString> externalIncludes,
const Dictionary<WString, vint>& externalIncludeOrder
)
{
lines.Add(L"/***********************************************************************");
lines.Add(L"THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY");
lines.Add(L"DEVELOPER: Zihan Chen(vczh)");
lines.Add(L"***********************************************************************/");
for (auto path : externalIncludes)
List<WString> sortedExternalIncludes;
CopyFrom(
sortedExternalIncludes,
externalIncludes.OrderBy([&](const WString& a, const WString& b)
{
auto aIndex = externalIncludeOrder.Keys().IndexOf(a);
auto bIndex = externalIncludeOrder.Keys().IndexOf(b);
if (aIndex != -1 && bIndex != -1)
{
return externalIncludeOrder.Values()[aIndex] <=> externalIncludeOrder.Values()[bIndex];
}
else if (aIndex != -1)
{
return std::strong_ordering::less;
}
else if (bIndex != -1)
{
return std::strong_ordering::greater;
}
else
{
return a <=> b;
}
})
);
for (auto path : sortedExternalIncludes)
{
lines.Add(L"#include \"" + path + L"\"");
}
@@ -89,6 +115,63 @@ void CombineWriteHeader(
}
}
void LoadExistingIncludeOrder(
FilePath outputIncludeFilePath,
const List<FilePath>& files,
Dictionary<FilePath, vint>& fileOrder,
Dictionary<WString, vint>& externalIncludeOrder
)
{
vint order = 0;
StringReader reader(ReadFile(outputIncludeFilePath));
while (!reader.IsEnd())
{
auto line = reader.ReadLine();
if (auto match = regexInclude.MatchHead(line))
{
auto path = match->Groups()[include_path][0].Value();
auto filePath = NormalizePathForFileSystem(outputIncludeFilePath.GetFolder() / path);
if (files.Contains(filePath))
{
if (!fileOrder.Keys().Contains(filePath))
{
fileOrder.Add(filePath, order++);
}
}
else if (!externalIncludeOrder.Keys().Contains(path))
{
externalIncludeOrder.Add(path, order++);
}
}
}
}
std::strong_ordering CompareFilePathWithExistingOrder(
const FilePath& a,
const FilePath& b,
const Dictionary<FilePath, vint>& fileOrder
)
{
auto aIndex = fileOrder.Keys().IndexOf(a);
auto bIndex = fileOrder.Keys().IndexOf(b);
if (aIndex != -1 && bIndex != -1)
{
return fileOrder.Values()[aIndex] <=> fileOrder.Values()[bIndex];
}
else if (aIndex != -1)
{
return std::strong_ordering::less;
}
else if (bIndex != -1)
{
return std::strong_ordering::greater;
}
else
{
return GetCodePackPath(a.GetFullPath()) <=> GetCodePackPath(b.GetFullPath());
}
}
void Combine(
const Dictionary<FilePath, WString>& inputFileToOutputFiles, // (in)
const Dictionary<WString, FilePath>& skippedImportFiles, // (in)
@@ -103,30 +186,41 @@ void Combine(
)
{
auto workingDir = outputFilePath.GetFolder();
Dictionary<FilePath, vint> fileOrder;
Dictionary<WString, vint> externalIncludeOrder;
LoadExistingIncludeOrder(outputIncludeFilePath, files, fileOrder, externalIncludeOrder);
List<FilePath> orderedFiles;
CopyFrom(
orderedFiles,
From(files).OrderBy([&](const FilePath& a, const FilePath& b)
{
return CompareFilePathWithExistingOrder(a, b, fileOrder);
})
);
List<FilePath> sortedFiles;
{
PartialOrderingProcessor popFiles;
Group<FilePath, FilePath> depGroup;
for (auto file : files)
for (auto file : orderedFiles)
{
for (auto dep : GetIncludedFiles(file, skippedImportFiles, cachedFileToIncludes, conditionOns, conditionOffs))
{
if (files.Contains(dep))
if (orderedFiles.Contains(dep))
{
depGroup.Add(file, dep);
}
}
}
popFiles.InitWithGroup(files, depGroup);
popFiles.InitWithGroup(orderedFiles, depGroup);
popFiles.Sort();
bool needExit = false;
for (vint i = 0; i < popFiles.components.Count(); i++)
{
auto& component = popFiles.components[i];
sortedFiles.Add(files[component.firstNode[0]]);
sortedFiles.Add(orderedFiles[component.firstNode[0]]);
if (component.nodeCount > 1)
{
@@ -134,7 +228,7 @@ void Combine(
Console::WriteLine(
L"Error: Cycle dependency found in categories: "
+ From(component.firstNode, component.firstNode + component.nodeCount)
.Select([&](vint nodeIndex) { return L"\r\n" + files[nodeIndex].GetFullPath(); })
.Select([&](vint nodeIndex) { return L"\r\n" + orderedFiles[nodeIndex].GetFullPath(); })
.Aggregate([](const WString& a, const WString& b) {return a + b; })
+ L"\r\n.");
Console::SetColor(true, true, true, false);
@@ -145,14 +239,14 @@ void Combine(
}
{
List<WString> lines;
CombineWriteHeader(lines, inputFileToOutputFiles, conditionOns, conditionOffs, files, externalIncludes);
CombineWriteHeader(lines, inputFileToOutputFiles, conditionOns, conditionOffs, orderedFiles, externalIncludes, externalIncludeOrder);
{
auto prefix = GetCommonFolder(files);
for (auto file : From(sortedFiles).Intersect(files))
auto prefix = GetCommonFolder(orderedFiles);
for (auto file : From(sortedFiles).Intersect(orderedFiles))
{
lines.Add(L"");
lines.Add(L"/***********************************************************************");
lines.Add(wupper(prefix.GetRelativePathFor(file)));
lines.Add(wupper(GetCodePackCommentPath(prefix.GetRelativePathFor(file))));
lines.Add(L"***********************************************************************/");
StringReader reader(ReadFile(file));
@@ -191,22 +285,22 @@ void Combine(
}
}
}
File(outputFilePath).WriteAllLines(lines, true, BomEncoder::Utf8);
File(NormalizePathForFileSystem(outputFilePath)).WriteAllLines(lines, true, BomEncoder::Utf8);
}
{
List<WString> lines;
CombineWriteHeader(lines, inputFileToOutputFiles, conditionOns, conditionOffs, files, externalIncludes);
CombineWriteHeader(lines, inputFileToOutputFiles, conditionOns, conditionOffs, orderedFiles, externalIncludes, externalIncludeOrder);
lines.Add(L"");
{
auto prefix = outputIncludeFilePath.GetFolder();
for (auto file : From(sortedFiles).Intersect(files))
for (auto file : From(sortedFiles).Intersect(orderedFiles))
{
lines.Add(L"#include \"" + prefix.GetRelativePathFor(file) + L"\"");
lines.Add(L"#include \"" + GetCodePackPath(prefix.GetRelativePathFor(file)) + L"\"");
}
}
File(outputIncludeFilePath).WriteAllLines(lines, true, BomEncoder::Utf8);
File(NormalizePathForFileSystem(outputIncludeFilePath)).WriteAllLines(lines, true, BomEncoder::Utf8);
}
Console::SetColor(false, true, false, true);
Console::WriteLine(L"Succeeded to write: " + outputFilePath.GetFullPath());
Console::SetColor(true, true, true, false);
}
}
@@ -1,15 +1,30 @@
#include "Codepack.h"
LazyList<FilePath> SearchFiles(
const Folder& folder,
const FilePath& folderPath,
const WString& extension,
List<WString>& exceptions
)
{
auto files = Ptr(new List<File>);
auto folders = Ptr(new List<Folder>);
auto folder = Folder(NormalizePathForFileSystem(folderPath));
folder.GetFiles(*files.Obj());
folder.GetFolders(*folders.Obj());
CopyFrom(
*files.Obj(),
From(*files.Obj()).OrderBy([](const File& a, const File& b)
{
return GetCodePackPath(a.GetFilePath().GetFullPath()) <=> GetCodePackPath(b.GetFilePath().GetFullPath());
})
);
CopyFrom(
*folders.Obj(),
From(*folders.Obj()).OrderBy([](const Folder& a, const Folder& b)
{
return GetCodePackPath(a.GetFilePath().GetFullPath()) <=> GetCodePackPath(b.GetFilePath().GetFullPath());
})
);
return LazyList<File>(files)
.Select([](const File& file)
@@ -18,10 +33,11 @@ LazyList<FilePath> SearchFiles(
})
.Where([&](const FilePath& filePath)
{
auto fullPath = GetCodePackPath(filePath.GetFullPath());
return From(exceptions)
.All([&](const WString& except)
{
return INVLOC.FindFirst(filePath.GetFullPath(), except, Locale::IgnoreCase).key == -1;
return INVLOC.FindFirst(fullPath, except, Locale::IgnoreCase).key == -1;
});
})
.Where([=](const FilePath& path)
@@ -32,7 +48,7 @@ LazyList<FilePath> SearchFiles(
LazyList<Folder>(folders)
.SelectMany([&](const Folder& folder)
{
return SearchFiles(folder, extension, exceptions);
return SearchFiles(folder.GetFilePath(), extension, exceptions);
})
);
}
@@ -51,4 +67,4 @@ LazyList<FilePath> GetHeaderFiles(
)
{
return SearchFiles(folder, L".h", exceptions);
}
}
@@ -69,7 +69,7 @@ LazyList<FilePath> GetIncludedFiles(
{
if (params && params->Count() == 2)
{
conditionOns.Add(codeFile, { params->Get(0).Value(),codeFile.GetFolder() / params->Get(1).Value() });
conditionOns.Add(codeFile, { params->Get(0).Value(),NormalizePathForFileSystem(codeFile.GetFolder() / params->Get(1).Value()) });
continue;
}
}
@@ -77,7 +77,7 @@ LazyList<FilePath> GetIncludedFiles(
{
if (params && params->Count() == 2)
{
conditionOffs.Add(codeFile, { params->Get(0).Value(),codeFile.GetFolder() / params->Get(1).Value() });
conditionOffs.Add(codeFile, { params->Get(0).Value(),NormalizePathForFileSystem(codeFile.GetFolder() / params->Get(1).Value()) });
continue;
}
}
@@ -89,7 +89,7 @@ LazyList<FilePath> GetIncludedFiles(
{
if (!skip)
{
auto path = codeFile.GetFolder() / match->Groups()[include_path][0].Value();
auto path = NormalizePathForFileSystem(codeFile.GetFolder() / match->Groups()[include_path][0].Value());
if (!includes.Contains(path))
{
includes.Add(path);
@@ -127,4 +127,4 @@ LazyList<FilePath> GetIncludedFiles(
cachedFileToIncludes.Add(codeFile, result);
return result;
}
}
+5 -4
View File
@@ -12,7 +12,7 @@ int main(int argc, char* argv[])
}
// load configuration
auto workingDir = FilePath(atow(argv[1])).GetFolder();
auto workingDir = NormalizePathForFileSystem(atow(argv[1])).GetFolder();
Ptr<XmlDocument> config;
{
Parser parser;
@@ -213,9 +213,10 @@ int main(int argc, char* argv[])
// prepare output folder
auto outputFolder = workingDir / (XmlGetAttribute(XmlGetElement(config->rootElement, L"output"), L"path")->value.value);
auto outputIncludeOnlyFolder = outputFolder / L"IncludeOnly";
if (!Folder(outputIncludeOnlyFolder).Exists())
auto outputIncludeOnlyFolderForIO = NormalizePathForFileSystem(outputIncludeOnlyFolder);
if (!Folder(outputIncludeOnlyFolderForIO).Exists())
{
Folder(outputIncludeOnlyFolder).Create(true);
Folder(outputIncludeOnlyFolderForIO).Create(true);
}
// generate categorized header dependencies
@@ -295,4 +296,4 @@ int main(int argc, char* argv[])
}
return 0;
}
}