mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-07 19:18:19 +02:00
Merge pull request #2203 from eveningstarinc/Yuvan/CustomBuildProperties
Custom Build Properties: Proof of Concept Implementation
This commit is contained in:
commit
9add2e1548
5 changed files with 155 additions and 5 deletions
|
@ -113,6 +113,7 @@ namespace BeefBuild
|
|||
{
|
||||
mWorkspace.mName = new String();
|
||||
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
|
||||
CustomBuildProperties.Load(false);
|
||||
LoadWorkspace(mVerb);
|
||||
}
|
||||
else
|
||||
|
@ -306,6 +307,27 @@ namespace BeefBuild
|
|||
if (mPackMan.mCleanHashSet.TryAddAlt(value, var entryPtr))
|
||||
*entryPtr = new .(value);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1027,6 +1027,12 @@ namespace IDE
|
|||
AddBuildFileDependency(project.mWindowsOptions.mIconFile);
|
||||
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)
|
||||
{
|
||||
case .Windows:
|
||||
|
@ -1035,8 +1041,8 @@ namespace IDE
|
|||
cacheStr.AppendF("Company\t{}\n", project.mWindowsOptions.mCompany);
|
||||
cacheStr.AppendF("Product\t{}\n", project.mWindowsOptions.mProduct);
|
||||
cacheStr.AppendF("Copyright\t{}\n", project.mWindowsOptions.mCopyright);
|
||||
cacheStr.AppendF("FileVersion\t{}\n", project.mWindowsOptions.mFileVersion);
|
||||
cacheStr.AppendF("ProductVersion\t{}\n", project.mWindowsOptions.mProductVersion);
|
||||
cacheStr.AppendF("FileVersion\t{}\n", fileVersion);
|
||||
cacheStr.AppendF("ProductVersion\t{}\n", productVersion);
|
||||
case .Linux:
|
||||
cacheStr.AppendF("Options\t{}\n", project.mLinuxOptions.mOptions);
|
||||
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();
|
||||
Path.GetFileName(targetPath, targetFileName);
|
||||
|
||||
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");
|
||||
return .Err;
|
||||
|
|
99
IDE/src/CustomBuildProperties.bf
Normal file
99
IDE/src/CustomBuildProperties.bf
Normal 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];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -984,6 +984,7 @@ namespace IDE
|
|||
mWorkspace.mName = new String();
|
||||
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
|
||||
|
||||
CustomBuildProperties.Load();
|
||||
LoadWorkspace(.OpenOrNew);
|
||||
FinishShowingNewWorkspace();
|
||||
}
|
||||
|
@ -3191,6 +3192,7 @@ namespace IDE
|
|||
CloseWorkspace();
|
||||
mWorkspace.mDir = new String(workspaceDir);
|
||||
mWorkspace.mName = new String(workspaceName);
|
||||
CustomBuildProperties.Load();
|
||||
LoadWorkspace(.Open);
|
||||
FinishShowingNewWorkspace();
|
||||
}
|
||||
|
@ -3320,7 +3322,13 @@ namespace IDE
|
|||
switch (useVerSpec)
|
||||
{
|
||||
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);
|
||||
if (!relPath.EndsWith(IDEUtils.cNativeSlash))
|
||||
relPath.Append(IDEUtils.cNativeSlash);
|
||||
|
@ -10961,6 +10969,12 @@ namespace IDE
|
|||
case "BeefPath":
|
||||
newString = gApp.mInstallDir;
|
||||
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();
|
||||
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
|
||||
CustomBuildProperties.Load();
|
||||
LoadWorkspace(mVerb);
|
||||
}
|
||||
else if (mWorkspace.IsSingleFileWorkspace)
|
||||
{
|
||||
mWorkspace.mName = new String();
|
||||
Path.GetFileNameWithoutExtension(mWorkspace.mCompositeFile.mFilePath, mWorkspace.mName);
|
||||
CustomBuildProperties.Load();
|
||||
LoadWorkspace(mVerb);
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,8 @@ namespace IDE.ui
|
|||
DeleteAndNullify!(app.mWorkspace.mDir);
|
||||
app.mWorkspace.mDir = new String(projDirectory);
|
||||
app.mWorkspace.mName = new String(projName);
|
||||
|
||||
|
||||
CustomBuildProperties.Load();
|
||||
app.[Friend]LoadWorkspace(.OpenOrNew);
|
||||
app.[Friend]FinishShowingNewWorkspace(false);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue