1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 14:24:10 +02:00
Beef/BeefBuild/src/BuildApp.bf

420 lines
9 KiB
Beef
Raw Normal View History

2019-08-23 11:56:54 -07:00
using IDE;
using System;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Collections;
2019-08-23 11:56:54 -07:00
using IDE.Util;
namespace BeefBuild
{
class BuildApp : IDEApp
{
2024-10-21 09:18:07 -04:00
public enum MainVerbState
{
None,
UpdateList,
End
}
2019-08-23 11:56:54 -07:00
const int cProgressSize = 30;
int mProgressIdx = 0;
public bool mIsTest;
2019-12-13 14:25:15 -08:00
public bool mTestIncludeIgnored;
public bool mDidRun;
2020-01-12 09:20:35 -08:00
public bool mWantsGenerate = false;
2024-10-21 09:18:07 -04:00
public bool mHandledVerb;
public String mRunArgs ~ delete _;
MainVerbState mMainVerbState;
2019-08-23 11:56:54 -07:00
/*void Test()
{
/*CURL.Easy easy = new CURL.Easy();
easy.SetOpt(.URL, "http://raw.githubusercontent.com/alexcrichton/curl-rust/master/Cargo.toml");
easy.SetOpt(.Verbose, true);
easy.Perform();*/
Transfer transfer = new Transfer();
//transfer.Setup("https://curl.haxx.se/download/curl-7.57.0.zip");
transfer.Setup("https://secure-appldnld.apple.com/itunes12/091-56359-20171213-EDF2198A-E039-11E7-9A9F-D21A1E4B8CED/iTunes64Setup.exe");
transfer.PerformBackground();
while (transfer.IsRunning)
{
Thread.Sleep(100);
Console.WriteLine("{0}/{1} @{2}Kps", transfer.BytesReceived, transfer.TotalBytes, transfer.BytesPerSecond / 1024);
}
#unwarn
let result = transfer.GetResult();
}*/
public this()
{
//mConfigName.Clear();
//mPlatformName.Clear();
//Test();
}
public override void Init()
{
2020-01-24 11:55:57 -08:00
GetVersionInfo(var exeTime);
2019-10-09 16:08:45 -07:00
if (mVerbosity == .Default)
mVerbosity = .Normal;
2019-08-23 11:56:54 -07:00
if (mConfigName.IsEmpty)
{
mConfigName.Set(mIsTest ? "Test" : "Debug");
}
if (mPlatformName.IsEmpty)
{
mPlatformName.Set(sPlatform64Name);
}
mMainThread = Thread.CurrentThread;
if (mConfigName.IsEmpty)
Fail("Config not specified");
if (mPlatformName.IsEmpty)
Fail("Platform not specified");
base.Init();
mSettings.Load();
mSettings.Apply();
2019-08-23 11:56:54 -07:00
mInitialized = true;
CreateBfSystems();
if (mWantsClean)
{
mBfBuildCompiler.ClearBuildCache();
mWantsClean = false;
}
if (mWorkspace.mDir == null)
{
mWorkspace.mDir = new String();
Directory.GetCurrentDirectory(mWorkspace.mDir);
}
if (mWorkspace.mDir != null)
{
mWorkspace.mName = new String();
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
2019-09-05 11:16:59 -07:00
LoadWorkspace(mVerb);
2019-08-23 11:56:54 -07:00
}
else
Fail("Workspace not specified");
if (mFailed)
return;
WorkspaceLoaded();
2020-01-12 09:20:35 -08:00
if (mWantsGenerate)
2019-08-23 11:56:54 -07:00
{
2020-01-12 09:20:35 -08:00
if (mWorkspace.mStartupProject != null)
{
if (mWorkspace.mStartupProject.IsEmpty)
AutoGenerateStartupCode(mWorkspace.mStartupProject);
else
OutputErrorLine("The project '{}' is not empty, but '-generate' was specified.", mWorkspace.mStartupProject.mProjectName);
}
}
2024-10-21 09:18:07 -04:00
}
2020-01-12 09:20:35 -08:00
2024-10-21 09:18:07 -04:00
public override bool HandleCommandLineParam(String key, String value)
{
if (mRunArgs != null)
2020-01-12 09:20:35 -08:00
{
2024-10-21 09:18:07 -04:00
if (!mRunArgs.IsEmpty)
mRunArgs.Append(" ");
if (value != null)
{
String qKey = scope .(key);
String qValue = scope .(value);
IDEApp.QuoteIfNeeded(qKey);
IDEApp.QuoteIfNeeded(qValue);
mRunArgs.Append(qKey);
mRunArgs.Append('=');
mRunArgs.Append(qValue);
}
else
2020-01-12 09:20:35 -08:00
{
2024-10-21 09:18:07 -04:00
String qKey = scope .(key);
IDEApp.QuoteIfNeeded(qKey);
mRunArgs.Append(qKey);
2020-01-12 09:20:35 -08:00
}
2024-10-21 09:18:07 -04:00
return true;
2019-08-23 11:56:54 -07:00
}
2019-10-09 16:08:45 -07:00
if (key.StartsWith("--"))
key.Remove(0, 1);
2019-08-23 11:56:54 -07:00
if (value == null)
{
switch (key)
{
2024-10-21 09:18:07 -04:00
case "-args":
if (mRunArgs == null)
mRunArgs = new .();
return true;
case "-new":
mVerb = .New;
return true;
2020-01-12 09:20:35 -08:00
case "-generate":
mWantsGenerate = true;
return true;
case "-run":
if (mVerbosity == .Default)
mVerbosity = .Minimal;
mVerb = .Run;
return true;
2019-08-23 11:56:54 -07:00
case "-test":
mIsTest = true;
return true;
2019-12-13 14:25:15 -08:00
case "-testall":
mIsTest = true;
mTestIncludeIgnored = true;
2019-08-23 11:56:54 -07:00
return true;
case "-clean":
mWantsClean = true;
return true;
case "-noir":
mConfig_NoIR = true;
return true;
2024-10-21 09:18:07 -04:00
case "-update":
if (mWantUpdateVersionLocks == null)
mWantUpdateVersionLocks = new .();
return true;
2019-10-09 16:08:45 -07:00
case "-version":
mVerb = .GetVersion;
return true;
2020-05-21 06:58:26 -07:00
case "-crash":
Runtime.FatalError("-crash specified on command line");
2019-08-23 11:56:54 -07:00
}
2024-10-21 09:18:07 -04:00
if (!key.StartsWith('-'))
{
switch (mMainVerbState)
{
case .None:
mMainVerbState = .End;
switch (key)
{
case "build":
mVerb = .None;
case "new":
mVerb = .New;
case "generate":
mWantsGenerate = true;
case "run":
if (mVerbosity == .Default)
mVerbosity = .Minimal;
mVerb = .Run;
case "test":
mIsTest = true;
case "testall":
mIsTest = true;
mTestIncludeIgnored = true;
case "clean":
mWantsClean = true;
case "version":
mVerb = .GetVersion;
case "crash":
Runtime.FatalError("-crash specified on command line");
case "update":
mVerb = .Update;
mWantUpdateVersionLocks = new .();
mMainVerbState = .UpdateList;
default:
mMainVerbState = .None;
}
if (mMainVerbState != .None)
return true;
case .UpdateList:
mWantUpdateVersionLocks.Add(new .(key));
return true;
case .End:
return false;
default:
}
}
2019-08-23 11:56:54 -07:00
}
else
{
if ((key == "-proddir") || (key == "-workspace"))
{
var relDir = scope String(value);
if ((relDir.EndsWith("\\")) || relDir.EndsWith("\""))
relDir.RemoveToEnd(relDir.Length - 1); //...
IDEUtils.FixFilePath(relDir);
String fullDir = new String();
Path.GetFullPath(relDir, fullDir);
mWorkspace.mDir = fullDir;
return true;
}
switch (key)
{
case "-config":
mConfigName.Set(value);
return true;
case "-platform":
mPlatformName.Set(value);
return true;
2024-10-21 09:18:07 -04:00
case "-update":
if (mWantUpdateVersionLocks == null)
mWantUpdateVersionLocks = new .();
mWantUpdateVersionLocks.Add(new .(value));
return true;
2019-08-23 11:56:54 -07:00
case "-verbosity":
if (value == "quiet")
2019-09-07 07:09:33 -07:00
mVerbosity = .Quiet;
else if (value == "minimal")
mVerbosity = .Minimal;
else if (value == "normal")
mVerbosity = .Normal;
else if (value == "detailed")
mVerbosity = .Detailed;
else if (value == "diagnostic")
mVerbosity = .Diagnostic;
else
Fail(scope String()..AppendF("Invalid verbosity option: {}", value));
return true;
2019-08-23 11:56:54 -07:00
}
}
#if BF_PLATFORM_WINDOWS
if (key == "-wait")
{
Windows.MessageBoxA((Windows.HWnd)0, "Wait2", "Wait", 0);
return true;
}
#endif //BF_PLATFORM_WINDOWS
return false;
}
protected override void BeefCompileStarted()
{
base.BeefCompileStarted();
if (mVerbosity >= .Normal)
{
if (cProgressSize > 0)
{
String str = scope String();
str.Append("[");
str.Append(' ', cProgressSize);
str.Append("]");
str.Append('\b', cProgressSize + 1);
Console.Write(str);
}
}
}
void WriteProgress(float pct)
{
if (mVerbosity >= .Normal)
{
int progressIdx = (int)Math.Round(pct * cProgressSize);
while (progressIdx > mProgressIdx)
{
mProgressIdx++;
Console.Write("*");
}
}
}
protected override void BeefCompileDone()
{
base.BeefCompileDone();
WriteProgress(1.0f);
if (mVerbosity >= .Normal)
Console.WriteLine("");
2019-08-23 11:56:54 -07:00
}
public override void LoadFailed()
{
mFailed = true;
}
public override void TestFailed()
{
mFailed = true;
}
protected override void CompileFailed()
{
base.CompileFailed();
mFailed = true;
}
protected override void CompileDone(bool succeeded)
{
if (!succeeded)
mFailed = true;
}
public override void Update(bool batchStart)
{
base.Update(batchStart);
if ((mWorkspace.mProjectLoadState != .None) && (mWorkspace.mProjectLoadState != .Loaded))
2019-08-23 11:56:54 -07:00
{
2024-10-21 09:18:07 -04:00
// Wait for workspace to complete loading
2019-08-23 11:56:54 -07:00
}
2024-10-21 09:18:07 -04:00
else
2019-08-23 11:56:54 -07:00
{
2024-10-21 09:18:07 -04:00
if ((!mFailed) && (!mHandledVerb))
{
2024-10-21 09:18:07 -04:00
mHandledVerb = true;
if (mIsTest)
{
RunTests(mTestIncludeIgnored, false);
}
else if (mVerb == .Update)
{
// No-op here
}
else if (mVerb != .New)
Compile(.Normal, null);
}
2024-10-21 09:18:07 -04:00
if (mCompilingBeef)
{
WriteProgress(mBfBuildCompiler.GetCompletionPercentage());
}
2024-10-21 09:18:07 -04:00
if ((!IsCompiling) && (!AreTestsRunning()))
{
if ((mVerb == .Run) && (!mDidRun) && (!mFailed))
{
let curPath = scope String();
Directory.GetCurrentDirectory(curPath);
let workspaceOptions = gApp.GetCurWorkspaceOptions();
let options = gApp.GetCurProjectOptions(mWorkspace.mStartupProject);
let targetPaths = scope List<String>();
defer ClearAndDeleteItems(targetPaths);
this.[Friend]GetTargetPaths(mWorkspace.mStartupProject, gApp.mPlatformName, workspaceOptions, options, targetPaths);
if (targetPaths.IsEmpty)
return;
ExecutionQueueCmd executionCmd = QueueRun(targetPaths[0], mRunArgs ?? "", curPath);
executionCmd.mIsTargetRun = true;
mDidRun = true;
return;
}
Stop();
}
2019-08-23 11:56:54 -07:00
}
}
}
}