Files
o3de/Code/Tools/AssetProcessor/native/utilities/PlatformConfiguration.h
T
lumberyard-employee-dm 3dec5d3b71 LYN-2537 engine assets (#254)
* LYN-2537 Moved the Engine and Editor folder to be within the EngineAssets folder

* Fixed Documentation in bootstrap.cfg to correct the path to the user project specific registry file

* Adding a newline to the output of AssetCatalog 'Registering asset..., but type is not set' message

* Updating the AssetProcessorPlatformConfig.setreg Scan Folder to detect
the @ENGINEROOT@/EngineAssets/Engine path for engine runtime assets and
@ENGINEROOT@/EngineAssets/Editor path for engine tool assets

* Updating references to Icons and other assets to account for moving the
Engine and Editor folder under a single EngineAssets folder

* Moving the Engine Settings Registry folder from Engine/Registry -> Registry

* Removed the LY_PROJECT_CMAKE_PATH define as it is not portable to other locations. It is hard coded to the project location that was used for the CMake configuration. Furthermore it paths with backslashes within it are treated as escape characters and not a path separator

* Updated the LyTestTools asset_processor.py script to copy the exclude.filetag from the EngineAssets/Engine directory now

* Fixed Atom Shader Preprocessing when running using an External Project

* Updated the TSGenerateAction.cpp to fix the build error with using a renamed variable

* Updated the Install_Common.cmake ly_setup_others function to install the
EngineAssets directory and the each of the Gem's Assets directory while
maintaining the relative directory structure to the Engine Root
Also updated the install step to install the Registry folder at the
engine root

* Fixed the copying of the Registry folder to be in the install root, instead of under a second 'Registry' folder

* Moving the AssetProcessorPlatformConfig.setreg file over to the Registry folder

* Updated the LyTestTools and C++ code to point that the new location of
the AssetProcessorPlatformConfig.setreg file inside of the Registry
folder

* Renamed Test AssetProcessor*Config.ini files to have the .setreg extension

* Converted the AssetProcessor test setreg files from ini format to json
format using the SerializeContextTools convert-ini command

* Updated the AssetProcessor CMakeLists.txt to copy over the test setreg files to the build folder

* Updated the assetprocessor test file list to point at the renamed AsssetProcessor*Config setreg filenames

* Removed the Output Prefix code from the AssetProcessor. The complexity that it brought to the AP code is not needed, as users can replicate the behavior by just moving there assets underneath a another folder, underneath the scan folder

* Adding back support to read the AssetProcessorPlatformConfig.setreg file from the asset root. This is only needed for C++ UnitTests as they run in an environment where the accessing the Engine Settings Registry is not available

* Updating the Install_common.cmake logic to copy any "Assets" folder to
the install layout.
The Script has also been updated to copy over the "Assets" folder in the
Engine Root to the install layout instead of an "EngineAssets" folder

* Updating References to EngineAssets source asset folder in code to be the Assets source folder

* Moved the Engine Source Asset folder of 'EngineAssets' to a new folder name of 'Assets'. This is inline with the naming scheme we use for Gem asset folders

* Adding the EngineFinder.cmake to the AutomatedTesting project to allow it to work in a project centric manner

* Updating the LyTestTools copy_assets_to_project function to be able to copy assets with folders to the temporary project root
Fixed an issue in LyTestTools where the temporary log directory could have shutil.rmtree being called twice on it leading to an exception which fails an automated test

Updated the asset_procesor_gui_tests_2 AddScanFolder test to not use the
output prefix, but instead place the source asset root into a
subdirectory

* Correct the AssetProcessorPlatformConfig Scan Folders for the EngineAssets directory to point at the Assets directory

* Updated the asset procesor batch dependency test scan folder to point at the 'Assets' folder instead of 'EngineAssets'
2021-04-28 21:38:43 -05:00

359 lines
17 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#ifndef PLATFORMCONFIGURATION_H
#define PLATFORMCONFIGURATION_H
#if !defined(Q_MOC_RUN)
#include <QList>
#include <QString>
#include <QObject>
#include <QHash>
#include <QRegExp>
#include <QPair>
#include <QVector>
#include <QSet>
#include <AzCore/Settings/SettingsRegistry.h>
#include <AzCore/std/string/string.h>
#include <native/utilities/assetUtils.h>
#include <native/AssetManager/assetScanFolderInfo.h>
#include <AssetBuilderSDK/AssetBuilderSDK.h>
#include <AzToolsFramework/Asset/AssetUtils.h>
#endif
namespace AZ
{
class SettingsRegistryInterface;
}
namespace AssetProcessor
{
inline constexpr const char* AssetProcessorSettingsKey{ "/Amazon/AssetProcessor/Settings" };
class PlatformConfiguration;
class ScanFolderInfo;
extern const char AssetConfigPlatformDir[];
extern const char AssetProcessorPlatformConfigFileName[];
//! Information for a given recognizer, on a specific platform
//! essentially a plain data holder, but with helper funcs
class AssetPlatformSpec
{
public:
QString m_extraRCParams;
};
//! The data about a particular recognizer, including all platform specs.
//! essentially a plain data holder, but with helper funcs
struct AssetRecognizer
{
AssetRecognizer() = default;
AssetRecognizer(const QString& name, bool testLockSource, int priority,
bool critical, bool supportsCreateJobs, AssetBuilderSDK::FilePatternMatcher patternMatcher,
const QString& version, const AZ::Data::AssetType& productAssetType, bool outputProductDependencies, bool checkServer = false)
: m_name(name)
, m_testLockSource(testLockSource)
, m_priority(priority)
, m_isCritical(critical)
, m_supportsCreateJobs(supportsCreateJobs)
, m_patternMatcher(patternMatcher)
, m_version(version)
, m_productAssetType(productAssetType) // if specified, it allows you to assign a UUID for the type of products directly.
, m_outputProductDependencies(outputProductDependencies)
, m_checkServer(checkServer)
{}
QString m_name;
AssetBuilderSDK::FilePatternMatcher m_patternMatcher;
QString m_version = QString();
// the QString is the Platform Identifier ("pc")
// the AssetPlatformSpec is the details for processing that asset on that platform.
QHash<QString, AssetPlatformSpec> m_platformSpecs;
// an optional parameter which is a UUID of types to assign to the output asset(s)
// if you don't specify one, then a heuristic will be used
AZ::Uuid m_productAssetType = AZ::Uuid::CreateNull();
int m_priority = 0; // used in order to sort these jobs vs other jobs when no other priority is applied (such as platform connected)
bool m_testLockSource = false;
bool m_isCritical = false;
bool m_checkServer = false;
bool m_supportsCreateJobs = false; // used to indicate a recognizer that can respond to a createJobs request
bool m_outputProductDependencies = false;
};
//! Dictionary of Asset Recognizers based on name
typedef QHash<QString, AssetRecognizer> RecognizerContainer;
typedef QList<const AssetRecognizer*> RecognizerPointerContainer;
//! The structure holds information about a particular exclude recognizer
struct ExcludeAssetRecognizer
{
QString m_name;
AssetBuilderSDK::FilePatternMatcher m_patternMatcher;
};
typedef QHash<QString, ExcludeAssetRecognizer> ExcludeRecognizerContainer;
//! Interface to get constant references to asset and exclude recognizers
struct RecognizerConfiguration
{
virtual const RecognizerContainer& GetAssetRecognizerContainer() const = 0;
virtual const ExcludeRecognizerContainer& GetExcludeAssetRecognizerContainer() const = 0;
};
//! Visitor for reading the "/Amazon/AssetProcessor/Settings/ScanFolder *" entries from the Settings Registry
//! Expects the key to path to the visitor to be "/Amazon/AssetProcessor/Settings"
struct ScanFolderVisitor
: AZ::SettingsRegistryInterface::Visitor
{
AZ::SettingsRegistryInterface::VisitResponse Traverse(AZStd::string_view jsonPath, AZStd::string_view valueName,
AZ::SettingsRegistryInterface::VisitAction action, AZ::SettingsRegistryInterface::Type) override;
void Visit(AZStd::string_view path, AZStd::string_view valueName, AZ::SettingsRegistryInterface::Type, AZ::s64 value) override;
void Visit(AZStd::string_view path, AZStd::string_view valueName, AZ::SettingsRegistryInterface::Type, AZStd::string_view value) override;
struct ScanFolderInfo
{
AZStd::string m_scanFolderIdentifier;
AZStd::string m_scanFolderDisplayName;
AZ::IO::Path m_watchPath{ AZ::IO::PosixPathSeparator };
AZStd::vector<AZStd::string> m_includeIdentifiers;
AZStd::vector<AZStd::string> m_excludeIdentifiers;
int m_scanOrder{};
bool m_isRecursive{};
};
AZStd::vector<ScanFolderInfo> m_scanFolderInfos;
private:
AZStd::stack<AZStd::string> m_scanFolderStack;
};
struct ExcludeVisitor
: AZ::SettingsRegistryInterface::Visitor
{
AZ::SettingsRegistryInterface::VisitResponse Traverse(AZStd::string_view jsonPath, AZStd::string_view valueName,
AZ::SettingsRegistryInterface::VisitAction action, AZ::SettingsRegistryInterface::Type) override;
void Visit(AZStd::string_view path, AZStd::string_view valueName, AZ::SettingsRegistryInterface::Type, AZStd::string_view value) override;
AZStd::vector<ExcludeAssetRecognizer> m_excludeAssetRecognizers;
private:
AZStd::stack<AZStd::string> m_excludeNameStack;
};
struct RCVisitor
: AZ::SettingsRegistryInterface::Visitor
{
RCVisitor(const AZ::SettingsRegistryInterface& settingsRegistry, const AZStd::vector<AssetBuilderSDK::PlatformInfo>& enabledPlatforms)
: m_registry(settingsRegistry)
, m_enabledPlatforms(enabledPlatforms)
{
}
AZ::SettingsRegistryInterface::VisitResponse Traverse(AZStd::string_view jsonPath, AZStd::string_view valueName,
AZ::SettingsRegistryInterface::VisitAction action, AZ::SettingsRegistryInterface::Type) override;
void Visit(AZStd::string_view path, AZStd::string_view valueName, AZ::SettingsRegistryInterface::Type, bool value) override;
void Visit(AZStd::string_view path, AZStd::string_view valueName, AZ::SettingsRegistryInterface::Type, AZ::s64 value) override;
void Visit(AZStd::string_view path, AZStd::string_view valueName, AZ::SettingsRegistryInterface::Type, AZStd::string_view value) override;
struct RCAssetRecognizer
{
AssetRecognizer m_recognizer;
AZStd::string m_defaultParams;
bool m_ignore{};
};
AZStd::vector<RCAssetRecognizer> m_assetRecognizers;
private:
void ApplyParamsOverrides(AZStd::string_view path);
AZStd::stack<AZStd::string> m_rcNameStack;
const AZ::SettingsRegistryInterface& m_registry;
const AZStd::vector<AssetBuilderSDK::PlatformInfo>& m_enabledPlatforms;
};
/** Reads the platform ini configuration file to determine
* platforms for which assets needs to be build
*/
class PlatformConfiguration
: public QObject
, public RecognizerConfiguration
{
Q_OBJECT
public:
typedef QPair<QRegExp, QString> RCSpec;
typedef QVector<RCSpec> RCSpecList;
public:
explicit PlatformConfiguration(QObject* pParent = nullptr);
virtual ~PlatformConfiguration() = default;
/** Use this function to parse the set of config files and the gem file to set up the platform config.
* This should be about the only function that is required to be called in order to end up with
* a full configuration.
* Note that order of the config files is relevant - later files override settings in
* files that are earlier.
**/
bool InitializeFromConfigFiles(const QString& absoluteSystemRoot, const QString& absoluteAssetRoot, const QString& projectPath, bool addPlatformConfigs = true, bool addGemsConfigs = true);
//! Merge an AssetProcessor*Config.ini path to the Settings Registry
//! The settings are anchored underneath the AssetProcessor::AssetProcessorSettingsKey JSON pointer
static bool MergeConfigFileToSettingsRegistry(AZ::SettingsRegistryInterface& settingsRegistry, const AZ::IO::PathView& filePathView);
const AZStd::vector<AssetBuilderSDK::PlatformInfo>& GetEnabledPlatforms() const;
const AssetBuilderSDK::PlatformInfo* const GetPlatformByIdentifier(const char* identifier) const;
//! Add AssetProcessor config files from platform specific folders
bool AddPlatformConfigFilePaths(AZStd::vector<AZ::IO::Path>& configList);
int MetaDataFileTypesCount() const { return m_metaDataFileTypes.count(); }
// Metadata file types are (meta file extension, original file extension - or blank if its tacked on the end instead of replacing).
// so for example if its
// blah.tif + blah.tif.metadata, then its ("metadata", "")
// but if its blah.tif + blah.metadata (replacing tif, data is lost) then its ("metadata", "tif")
QPair<QString, QString> GetMetaDataFileTypeAt(int pos) const;
// Metadata extensions can also be a real file, to create a dependency on file types if a specific file changes
// so for example, a Metadata file type pair ("Animations/SkeletonList.xml", "i_caf")
// would cause all i_caf files to be re-evaluated when Animations/SkeletonList.xml is modified.
bool IsMetaDataTypeRealFile(QString relativeName) const;
void EnablePlatform(const AssetBuilderSDK::PlatformInfo& platform, bool enable = true);
//! Gets the minumum jobs specified in the configuration file
int GetMinJobs() const;
int GetMaxJobs() const;
//! Return how many scan folders there are
int GetScanFolderCount() const;
//! Return the gems info list
AZStd::vector<AzFramework::GemInfo> GetGemsInformation() const;
//! Retrieve the scan folder at a given index.
AssetProcessor::ScanFolderInfo& GetScanFolderAt(int index);
//! Manually add a scan folder. Also used for testing.
void AddScanFolder(const AssetProcessor::ScanFolderInfo& source, bool isUnitTesting = false);
//! Manually add a recognizer. Used for testing.
void AddRecognizer(const AssetRecognizer& source);
//! Manually remove a recognizer. Used for testing.
void RemoveRecognizer(QString name);
//! Manually add an exclude recognizer. Used for testing.
void AddExcludeRecognizer(const ExcludeAssetRecognizer& recogniser);
//! Manually remove an exclude recognizer. Used for testing.
void RemoveExcludeRecognizer(QString name);
//! Manually add a metadata type. Used for testing.
//! The originalextension, if specified, means this metafile type REPLACES the given extension
//! If not specified (blank) it means that the metafile extension is added onto the end instead and does
//! not remove the original file extension
void AddMetaDataType(const QString& type, const QString& originalExtension);
// ------------------- utility functions --------------------
///! Checks to see whether the input file is an excluded file
bool IsFileExcluded(QString fileName) const;
//! Given a file name, return a container that contains all matching recognizers
//!
//! Returns false if there were no matches, otherwise returns true
bool GetMatchingRecognizers(QString fileName, RecognizerPointerContainer& output) const;
//! given a fileName (as a relative and which scan folder it was found in)
//! Return either an empty string, or the canonical path to a file which overrides it
//! because of folder priority.
//! Note that scanFolderName is only used to exit quickly
//! If its found in any scan folder before it arrives at scanFolderName it will be considered a hit
QString GetOverridingFile(QString relativeName, QString scanFolderName) const;
//! given a relative name, loop over folders and resolve it to a full path with the first existing match.
QString FindFirstMatchingFile(QString relativeName) const;
//! given a relative name with wildcard characters (* allowed) find a set of matching files or optionally folders
QStringList FindWildcardMatches(const QString& sourceFolder, QString relativeName, bool includeFolders = false, bool recursiveSearch = true) const;
//! given a fileName (as a full path), return the database source name which includes the output prefix.
//!
//! for example
//! c:/dev/mygame/textures/texture1.tga
//! ----> [textures/texture1.tga] found under [c:/dev/mygame]
//! c:/dev/engine/models/box01.mdl
//! ----> [models/box01.mdl] found under[c:/dev/engine]
//! note that this does return a database source path by default
bool ConvertToRelativePath(QString fullFileName, QString& databaseSourceName, QString& scanFolderName) const;
static bool ConvertToRelativePath(const QString& fullFileName, const ScanFolderInfo* scanFolderInfo, QString& databaseSourceName);
//! given a full file name (assumed already fed through the normalization funciton), return the first matching scan folder
const AssetProcessor::ScanFolderInfo* GetScanFolderForFile(const QString& fullFileName) const;
//! Given a scan folder path, get its complete info
const AssetProcessor::ScanFolderInfo* GetScanFolderByPath(const QString& scanFolderPath) const;
const RecognizerContainer& GetAssetRecognizerContainer() const override;
const ExcludeRecognizerContainer& GetExcludeAssetRecognizerContainer() const override;
/** returns true if the config is valid.
* configs are considered invalid if critical information is missing.
* for example, if no recognizers are given, or no platforms are enabled.
* They can also be considered invalid if a critical parse error occurred during load.
*/
bool IsValid() const;
/** If IsValid is false, this will contain the full error string to show to the user.
* Note that IsValid will automatically write this error string to stderror as part of checking
* So this function is there for those wishing to use a GUI.
*/
const AZStd::string& GetError() const;
void PopulatePlatformsForScanFolder(AZStd::vector<AssetBuilderSDK::PlatformInfo>& platformsList, QStringList includeTagsList = QStringList(), QStringList excludeTagsList = QStringList());
protected:
// call this first, to populate the list of platform informations
void ReadPlatformInfosFromSettingsRegistry();
// call this next, in order to find out what platforms are enabled
void PopulateEnabledPlatforms();
// finally, call this, in order to delete the platforminfos for non-enabled platforms
void FinalizeEnabledPlatforms();
// iterate over all the gems and add their folders to the "scan folders" list as appropriate.
void AddGemScanFolders(const AZStd::vector<AzFramework::GemInfo>& gemInfoList);
void ReadEnabledPlatformsFromSettingsRegistry();
bool ReadRecognizersFromSettingsRegistry(const QString& assetRoot, bool skipScanFolders = false, QStringList scanFolderPatterns = QStringList() );
void ReadMetaDataFromSettingsRegistry();
private:
AZStd::vector<AssetBuilderSDK::PlatformInfo> m_enabledPlatforms;
RecognizerContainer m_assetRecognizers;
ExcludeRecognizerContainer m_excludeAssetRecognizers;
AZStd::vector<AssetProcessor::ScanFolderInfo> m_scanFolders;
QList<QPair<QString, QString> > m_metaDataFileTypes;
QSet<QString> m_metaDataRealFiles;
AZStd::vector<AzFramework::GemInfo> m_gemInfoList;
int m_minJobs = 1;
int m_maxJobs = 3;
// used only during file read, keeps the total running list of all the enabled platforms from all config files and command lines
AZStd::vector<AZStd::string> m_tempEnabledPlatforms;
///! if non-empty, fatalError contains the error that occurred during read.
///! it will be printed out to the log when
mutable AZStd::string m_fatalError;
};
} // end namespace AssetProcessor
#endif // PLATFORMCONFIGURATION_H