2016-01-07 08:17:16 -05:00
|
|
|
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
2014-04-29 06:45:18 -04:00
|
|
|
|
|
|
|
|
#include "ScriptGeneratorPluginPrivatePCH.h"
|
|
|
|
|
#include "ScriptCodeGeneratorBase.h"
|
|
|
|
|
#include "GenericScriptCodeGenerator.h"
|
|
|
|
|
#include "LuaScriptCodeGenerator.h"
|
2015-03-27 03:51:19 -04:00
|
|
|
#include "IProjectManager.h"
|
2015-05-27 11:12:26 -04:00
|
|
|
#include "Runtime/Core/Public/Features/IModularFeatures.h"
|
2014-04-29 06:45:18 -04:00
|
|
|
|
|
|
|
|
DEFINE_LOG_CATEGORY(LogScriptGenerator);
|
|
|
|
|
|
|
|
|
|
class FScriptGeneratorPlugin : public IScriptGeneratorPlugin
|
|
|
|
|
{
|
|
|
|
|
/** Specialized script code generator */
|
|
|
|
|
TAutoPtr<FScriptCodeGeneratorBase> CodeGenerator;
|
|
|
|
|
|
|
|
|
|
/** IModuleInterface implementation */
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual void StartupModule() override;
|
|
|
|
|
virtual void ShutdownModule() override;
|
2014-04-29 06:45:18 -04:00
|
|
|
|
|
|
|
|
/** IScriptGeneratorPlugin interface */
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual FString GetGeneratedCodeModuleName() const override { return TEXT("ScriptPlugin"); }
|
2015-04-01 07:20:55 -04:00
|
|
|
virtual bool ShouldExportClassesForModule(const FString& ModuleName, EBuildModuleType::Type ModuleType, const FString& ModuleGeneratedIncludeDirectory) const override;
|
2015-03-27 03:51:19 -04:00
|
|
|
virtual bool SupportsTarget(const FString& TargetName) const override;
|
2014-06-23 06:27:04 -04:00
|
|
|
virtual void Initialize(const FString& RootLocalPath, const FString& RootBuildPath, const FString& OutputDirectory, const FString& IncludeBase) override;
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual void ExportClass(UClass* Class, const FString& SourceHeaderFilename, const FString& GeneratedHeaderFilename, bool bHasChanged) override;
|
|
|
|
|
virtual void FinishExport() override;
|
2015-05-27 11:12:26 -04:00
|
|
|
virtual FString GetGeneratorName() const override;
|
2014-04-29 06:45:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_MODULE( FScriptGeneratorPlugin, ScriptGeneratorPlugin )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FScriptGeneratorPlugin::StartupModule()
|
|
|
|
|
{
|
2015-05-27 11:12:26 -04:00
|
|
|
// Register ourselves as an editor feature
|
|
|
|
|
IModularFeatures::Get().RegisterModularFeature(TEXT("ScriptGenerator"), this);
|
2014-04-29 06:45:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FScriptGeneratorPlugin::ShutdownModule()
|
|
|
|
|
{
|
|
|
|
|
CodeGenerator.Reset();
|
2015-05-27 11:12:26 -04:00
|
|
|
|
|
|
|
|
// Unregister our feature
|
|
|
|
|
IModularFeatures::Get().UnregisterModularFeature(TEXT("ScriptGenerator"), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString FScriptGeneratorPlugin::GetGeneratorName() const
|
|
|
|
|
{
|
|
|
|
|
#if WITH_LUA
|
|
|
|
|
return TEXT("Lua Example Code Generator Plugin");
|
|
|
|
|
#else
|
|
|
|
|
return TEXT("Example Code Generator Plugin");
|
|
|
|
|
#endif
|
2014-04-29 06:45:18 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-23 06:27:04 -04:00
|
|
|
void FScriptGeneratorPlugin::Initialize(const FString& RootLocalPath, const FString& RootBuildPath, const FString& OutputDirectory, const FString& IncludeBase)
|
2014-04-29 06:45:18 -04:00
|
|
|
{
|
|
|
|
|
#if WITH_LUA
|
|
|
|
|
UE_LOG(LogScriptGenerator, Log, TEXT("Using Lua Script Generator."));
|
2014-06-23 06:27:04 -04:00
|
|
|
CodeGenerator = new FLuaScriptCodeGenerator(RootLocalPath, RootBuildPath, OutputDirectory, IncludeBase);
|
2014-04-29 06:45:18 -04:00
|
|
|
#else
|
|
|
|
|
UE_LOG(LogScriptGenerator, Log, TEXT("Using Generic Script Generator."));
|
2014-06-23 06:27:04 -04:00
|
|
|
CodeGenerator = new FGenericScriptCodeGenerator(RootLocalPath, RootBuildPath, OutputDirectory, IncludeBase);
|
2014-04-29 06:45:18 -04:00
|
|
|
#endif
|
|
|
|
|
UE_LOG(LogScriptGenerator, Log, TEXT("Output directory: %s"), *OutputDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-29 04:03:28 -04:00
|
|
|
bool FScriptGeneratorPlugin::ShouldExportClassesForModule(const FString& ModuleName, EBuildModuleType::Type ModuleType, const FString& ModuleGeneratedIncludeDirectory) const
|
2014-05-22 01:20:24 -04:00
|
|
|
{
|
2016-01-27 12:09:53 -05:00
|
|
|
bool bCanExport = (ModuleType == EBuildModuleType::EngineRuntime || ModuleType == EBuildModuleType::GameRuntime);
|
2014-05-22 01:20:24 -04:00
|
|
|
if (bCanExport)
|
|
|
|
|
{
|
|
|
|
|
// Only export functions from selected modules
|
|
|
|
|
static struct FSupportedModules
|
|
|
|
|
{
|
|
|
|
|
TArray<FString> SupportedScriptModules;
|
|
|
|
|
FSupportedModules()
|
|
|
|
|
{
|
|
|
|
|
GConfig->GetArray(TEXT("Plugins"), TEXT("ScriptSupportedModules"), SupportedScriptModules, GEngineIni);
|
|
|
|
|
}
|
|
|
|
|
} SupportedModules;
|
|
|
|
|
bCanExport = SupportedModules.SupportedScriptModules.Num() == 0 || SupportedModules.SupportedScriptModules.Contains(ModuleName);
|
|
|
|
|
}
|
|
|
|
|
return bCanExport;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 06:45:18 -04:00
|
|
|
void FScriptGeneratorPlugin::ExportClass(UClass* Class, const FString& SourceHeaderFilename, const FString& GeneratedHeaderFilename, bool bHasChanged)
|
|
|
|
|
{
|
|
|
|
|
CodeGenerator->ExportClass(Class, SourceHeaderFilename, GeneratedHeaderFilename, bHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FScriptGeneratorPlugin::FinishExport()
|
|
|
|
|
{
|
|
|
|
|
CodeGenerator->FinishExport();
|
|
|
|
|
}
|
2015-03-27 03:51:19 -04:00
|
|
|
|
|
|
|
|
bool FScriptGeneratorPlugin::SupportsTarget(const FString& TargetName) const
|
|
|
|
|
{
|
|
|
|
|
// We only support the target if it explicitly enables the required script plugin in its uproject file
|
|
|
|
|
bool bSupportsTarget = false;
|
|
|
|
|
if (FPaths::IsProjectFilePathSet())
|
|
|
|
|
{
|
|
|
|
|
FProjectDescriptor ProjectDescriptor;
|
|
|
|
|
FText OutError;
|
|
|
|
|
if (ProjectDescriptor.Load(FPaths::GetProjectFilePath(), OutError))
|
|
|
|
|
{
|
|
|
|
|
for (auto& PluginDescriptor : ProjectDescriptor.Plugins)
|
|
|
|
|
{
|
|
|
|
|
// For your own script plugin you might want to change the hardcoded name here to something else
|
|
|
|
|
if (PluginDescriptor.bEnabled && PluginDescriptor.Name == TEXT("ScriptPlugin"))
|
|
|
|
|
{
|
|
|
|
|
bSupportsTarget = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bSupportsTarget;
|
|
|
|
|
}
|