1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Merge pull request #2203 from eveningstarinc/Yuvan/CustomBuildProperties

Custom Build Properties: Proof of Concept Implementation
This commit is contained in:
Brian Fiete 2025-05-25 08:52:04 +02:00 committed by GitHub
commit 9add2e1548
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 155 additions and 5 deletions

View file

@ -113,6 +113,7 @@ namespace BeefBuild
{ {
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName); Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
CustomBuildProperties.Load(false);
LoadWorkspace(mVerb); LoadWorkspace(mVerb);
} }
else else
@ -306,6 +307,27 @@ namespace BeefBuild
if (mPackMan.mCleanHashSet.TryAddAlt(value, var entryPtr)) if (mPackMan.mCleanHashSet.TryAddAlt(value, var entryPtr))
*entryPtr = new .(value); *entryPtr = new .(value);
return true; return true;
case "-property":
int splitIdx = (int)value.IndexOf('=');
if (splitIdx != -1)
{
String propertyName = new String();
StringView propertyKeyView = value.Substring(0, splitIdx);
propertyKeyView.ToString(propertyName);
String propertyValue = new String();
StringView propertyValueView = value.Substring(splitIdx + 1, value.Length - splitIdx - 1);
propertyValueView.ToString(propertyValue);
if (!CustomBuildProperties.TryAddProperty(propertyName, propertyValue))
{
delete propertyName;
delete propertyValue;
return false;
}
return true;
}
} }
} }

View file

@ -1027,6 +1027,12 @@ namespace IDE
AddBuildFileDependency(project.mWindowsOptions.mIconFile); AddBuildFileDependency(project.mWindowsOptions.mIconFile);
AddBuildFileDependency(project.mWindowsOptions.mManifestFile); AddBuildFileDependency(project.mWindowsOptions.mManifestFile);
String fileVersion = scope String();
gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, project.mWindowsOptions.mFileVersion, "file version", fileVersion);
String productVersion = scope String();
gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, project.mWindowsOptions.mProductVersion, "product version", productVersion);
switch (mPlatformType) switch (mPlatformType)
{ {
case .Windows: case .Windows:
@ -1035,8 +1041,8 @@ namespace IDE
cacheStr.AppendF("Company\t{}\n", project.mWindowsOptions.mCompany); cacheStr.AppendF("Company\t{}\n", project.mWindowsOptions.mCompany);
cacheStr.AppendF("Product\t{}\n", project.mWindowsOptions.mProduct); cacheStr.AppendF("Product\t{}\n", project.mWindowsOptions.mProduct);
cacheStr.AppendF("Copyright\t{}\n", project.mWindowsOptions.mCopyright); cacheStr.AppendF("Copyright\t{}\n", project.mWindowsOptions.mCopyright);
cacheStr.AppendF("FileVersion\t{}\n", project.mWindowsOptions.mFileVersion); cacheStr.AppendF("FileVersion\t{}\n", fileVersion);
cacheStr.AppendF("ProductVersion\t{}\n", project.mWindowsOptions.mProductVersion); cacheStr.AppendF("ProductVersion\t{}\n", productVersion);
case .Linux: case .Linux:
cacheStr.AppendF("Options\t{}\n", project.mLinuxOptions.mOptions); cacheStr.AppendF("Options\t{}\n", project.mLinuxOptions.mOptions);
case .Wasm: case .Wasm:
@ -1265,11 +1271,17 @@ namespace IDE
} }
} }
String fileVersion = scope String();
gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, winOptions.mFileVersion, "file version", fileVersion);
String productVersion = scope String();
gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, winOptions.mProductVersion, "product version", productVersion);
let targetFileName = scope String(); let targetFileName = scope String();
Path.GetFileName(targetPath, targetFileName); Path.GetFileName(targetPath, targetFileName);
if (resGen.AddVersion(winOptions.mDescription, winOptions.mComments, winOptions.mCompany, winOptions.mProduct, if (resGen.AddVersion(winOptions.mDescription, winOptions.mComments, winOptions.mCompany, winOptions.mProduct,
winOptions.mCopyright, winOptions.mFileVersion, winOptions.mProductVersion, targetFileName) case .Err) winOptions.mCopyright, fileVersion, productVersion, targetFileName) case .Err)
{ {
gApp.OutputErrorLine("Failed to add version"); gApp.OutputErrorLine("Failed to add version");
return .Err; return .Err;

View file

@ -0,0 +1,99 @@
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using Beefy.utils;
namespace IDE
{
class CustomBuildProperties
{
static Dictionary<String, String> mProperties = new .() ~ DeleteDictionaryAndKeysAndValues!(_);
static public void GetFileName(String outResult)
{
String workspaceDir = scope String();
if (gApp.mWorkspace.mDir == null)
Directory.GetCurrentDirectory(workspaceDir);
else
workspaceDir = gApp.mWorkspace.mDir;
outResult.Append(workspaceDir, "/BeefProperties.toml");
}
static public void Clear()
{
for (var entry in mProperties)
{
delete entry.key;
delete entry.value;
}
mProperties.Clear();
}
static public void Load(bool clearExistingProperties = true)
{
const char8* PROPERTIES_STR = "Properties";
if (clearExistingProperties)
Clear();
String propertiesFileName = scope String();
GetFileName(propertiesFileName);
if (!File.Exists(propertiesFileName))
return;
StructuredData data = scope StructuredData();
if (gApp.StructuredLoad(data, propertiesFileName) case .Err(let err))
{
gApp.OutputErrorLine("Failed to load properties from: '{0}'", propertiesFileName);
return;
}
if (!data.Contains(PROPERTIES_STR))
return;
for (var property in data.Enumerate(PROPERTIES_STR))
{
String propertyName = new String();
property.ToString(propertyName);
if (Contains(propertyName))
{
delete propertyName;
continue;
}
String propertyValue = new String();
data.GetCurString(propertyValue);
TryAddProperty(propertyName, propertyValue);
}
}
static public bool TryAddProperty(String propertyName, String propertyValue)
{
if (Contains(propertyName))
return false;
mProperties.Add(propertyName, propertyValue);
return true;
}
static public bool Contains(String property)
{
return mProperties.ContainsKey(property);
}
static public String Get(String property)
{
if (!Contains(property))
return null;
return mProperties[property];
}
}
}

View file

@ -984,6 +984,7 @@ namespace IDE
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName); Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
CustomBuildProperties.Load();
LoadWorkspace(.OpenOrNew); LoadWorkspace(.OpenOrNew);
FinishShowingNewWorkspace(); FinishShowingNewWorkspace();
} }
@ -3191,6 +3192,7 @@ namespace IDE
CloseWorkspace(); CloseWorkspace();
mWorkspace.mDir = new String(workspaceDir); mWorkspace.mDir = new String(workspaceDir);
mWorkspace.mName = new String(workspaceName); mWorkspace.mName = new String(workspaceName);
CustomBuildProperties.Load();
LoadWorkspace(.Open); LoadWorkspace(.Open);
FinishShowingNewWorkspace(); FinishShowingNewWorkspace();
} }
@ -3320,7 +3322,13 @@ namespace IDE
switch (useVerSpec) switch (useVerSpec)
{ {
case .Path(let path): case .Path(let path):
var relPath = scope String(path); Project.Options options = GetCurProjectOptions(project);
Workspace.Options workspaceOptions = GetCurWorkspaceOptions();
var resolvedPath = scope String();
ResolveConfigString(mPlatformName, workspaceOptions, project, options, path, "project path", resolvedPath);
var relPath = scope String(resolvedPath);
IDEUtils.FixFilePath(relPath); IDEUtils.FixFilePath(relPath);
if (!relPath.EndsWith(IDEUtils.cNativeSlash)) if (!relPath.EndsWith(IDEUtils.cNativeSlash))
relPath.Append(IDEUtils.cNativeSlash); relPath.Append(IDEUtils.cNativeSlash);
@ -10961,6 +10969,12 @@ namespace IDE
case "BeefPath": case "BeefPath":
newString = gApp.mInstallDir; newString = gApp.mInstallDir;
default: default:
// Check if any custom properties match the string.
if (CustomBuildProperties.Contains(replaceStr))
{
newString = scope:ReplaceBlock String();
newString.Append(CustomBuildProperties.Get(replaceStr));
}
} }
} }
@ -12869,12 +12883,14 @@ namespace IDE
{ {
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName); Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
CustomBuildProperties.Load();
LoadWorkspace(mVerb); LoadWorkspace(mVerb);
} }
else if (mWorkspace.IsSingleFileWorkspace) else if (mWorkspace.IsSingleFileWorkspace)
{ {
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileNameWithoutExtension(mWorkspace.mCompositeFile.mFilePath, mWorkspace.mName); Path.GetFileNameWithoutExtension(mWorkspace.mCompositeFile.mFilePath, mWorkspace.mName);
CustomBuildProperties.Load();
LoadWorkspace(mVerb); LoadWorkspace(mVerb);
} }

View file

@ -143,6 +143,7 @@ namespace IDE.ui
app.mWorkspace.mDir = new String(projDirectory); app.mWorkspace.mDir = new String(projDirectory);
app.mWorkspace.mName = new String(projName); app.mWorkspace.mName = new String(projName);
CustomBuildProperties.Load();
app.[Friend]LoadWorkspace(.OpenOrNew); app.[Friend]LoadWorkspace(.OpenOrNew);
app.[Friend]FinishShowingNewWorkspace(false); app.[Friend]FinishShowingNewWorkspace(false);