Skip to content

Commit

Permalink
Allow the "RTE" folder name to be configurable (#65)
Browse files Browse the repository at this point in the history
Adds optional rtedir attribute to /cprj/target/output element

Modified RteTestM3 project to use rtedir="CONFIG_FOLDER".
Renamed RTE to CONFIG_FOLDER in the test structure to reflect this

Contributed by STMicroelectronics

Signed-off-by: Samuel HULTGREN <[email protected]>
  • Loading branch information
slhultgren authored Jan 18, 2022
1 parent 8af1dcd commit 6dcf591
Show file tree
Hide file tree
Showing 35 changed files with 118 additions and 73 deletions.
2 changes: 2 additions & 0 deletions libs/rtemodel/include/CprjFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
/******************************************************************************/
#include <optional>
#include "RteGenerator.h"

#include "RtePackage.h"
Expand Down Expand Up @@ -319,6 +320,7 @@ class CprjFile : public RtePackage
*/
RteItem* GetProjectInfo() const;

const std::optional<std::string> GetRteFolder() const;
/**
* @brief getter for list of components specified for the project
* @return list of RteItem pointer
Expand Down
3 changes: 2 additions & 1 deletion libs/rtemodel/include/RteFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ class RteFile : public RteItem
* @param instanceIndex file index for components with multiple instantiation.
* Gets appended as a string to the base filename before extension it its value >=0.
* Value of < 0 indicates that parent component can have only one instance
* @param rteFolder the "RTE" folder path used for placing files
* @return full project-relative path including filename and extension
*/
std::string GetInstancePathName(const std::string& deviceName, int instanceIndex) const;
std::string GetInstancePathName(const std::string& deviceName, int instanceIndex, const std::string& rteFolder) const;

/**
* @brief construct absolute include path string that can be used in'-I' compiler option.
Expand Down
12 changes: 8 additions & 4 deletions libs/rtemodel/include/RteInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,9 @@ class RteFileInstance : public RteItemInstance
* @param f pointer to the original RteFile
* @param deviceName device name used in the target
* @param instanceIndex instance index, can be > 0 for multi-instance components
* @param rteFolder the "RTE" folder path used for placing files
*/
void Init(RteFile* f, const std::string& deviceName, int instanceIndex);
void Init(RteFile* f, const std::string& deviceName, int instanceIndex, const std::string& rteFolder);

/**
* @brief update file instance
Expand All @@ -1387,15 +1388,17 @@ class RteFileInstance : public RteItemInstance
/**
* @brief check if a new version of a config file is available (for specified target)
* @param targetName target name
* @param rteFolder the "RTE" folder path used for placing files
* @return true if newer version of config file is available
*/
int HasNewVersion(const std::string& targetName) const;
int HasNewVersion(const std::string& targetName, const std::string& rteFolder) const;

/**
* @brief check if a new version of a config file is available (for any target)
* @param rteFolder the "RTE" folder path used for placing files
* @return true if newer version of config file is available
*/
int HasNewVersion() const;
int HasNewVersion(const std::string& rteFolder) const;

/**
* @brief get file category
Expand Down Expand Up @@ -1472,9 +1475,10 @@ class RteFileInstance : public RteItemInstance
/**
* @brief get the original file resolved to this instance for specified target
* @param targetName target name to resolve file
* @param rteFolder the "RTE" folder path used for placing files
* @return pointer to RteFile if resolved, nullptr otherwise
*/
RteFile* GetFile(const std::string& targetName) const;
RteFile* GetFile(const std::string& targetName, const std::string& rteFolder) const;

/**
* @brief copy a config file from pack location to the designated project directory
Expand Down
12 changes: 10 additions & 2 deletions libs/rtemodel/include/RteProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "RteInstance.h"
#include "RteModel.h"

#include <optional>
#include <stdio.h>

class RteModel;
Expand Down Expand Up @@ -149,6 +150,10 @@ class RteProject : public RteItem
*/
void SetName(const std::string& name) { m_ID = name; }


void SetRteFolder(std::optional<std::string> rteFolder) { m_rteFolder = rteFolder; }
const std::string& GetRteFolder() const;

/**
* @brief get RteCallback object
* @return RteCallback pointer
Expand Down Expand Up @@ -685,18 +690,20 @@ class RteProject : public RteItem
* @brief get file name and path of "RTE_Components.h" determined by the specified target and prefix
* @param targetName given target name
* @param prefix given prefix to be added at beginning of the file path
* @param rteFolder the "RTE" folder path used for placing files
* @return string containing file name and path
*/
static std::string GetRteComponentsH(const std::string& targetName, const std::string& prefix);
static std::string GetRteComponentsH(const std::string& targetName, const std::string& prefix, const std::string& rteFolder);

/**
* @brief get file name and path locating in folder "RTE" determined by the specified name, target and prefix
* @param name given file name
* @param targetName given target name
* @param prefix given prefix to be added at beginning of the file path
* @param rteFolder the "RTE" folder path used for placing files
* @return string containing file name and path
*/
static std::string GetRteHeader(const std::string& name, const std::string & targetName, const std::string& prefix);
static std::string GetRteHeader(const std::string& name, const std::string & targetName, const std::string& prefix, const std::string& rteFolder);

protected:
virtual RteTarget* CreateTarget(RteModel* filteredModel, const std::string& name, const std::map<std::string, std::string>& attributes);
Expand Down Expand Up @@ -760,6 +767,7 @@ class RteProject : public RteItem
std::map<std::string, RteModel*> m_targetModels; // filtered models for each target
std::map<int, std::string> m_targetIDs;
std::string m_sActiveTarget;
std::optional<std::string> m_rteFolder;
};

#endif // RteProject_H
12 changes: 8 additions & 4 deletions libs/rtemodel/include/RteTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ struct RteFileInfo
/**
* @brief compare file version of the given target and the instance
* @param targetName target name
* @param rteFolder the "RTE" folder path used for placing files
* @return 0 if both file versions are same, > 0 if file version of the given target is newer, otherwise < 0
*/
int HasNewVersion(const std::string& targetName) const;
int HasNewVersion(const std::string& targetName, const std::string& rteFolder) const;

/**
* @brief compare file version of this instance with the ones of other targets
* @param rteFolder the "RTE" folder path used for placing files
* @return 0 if equal to all others target, > 0 if file version of any other target is newer, otherwise < 0
*/
int HasNewVersion() const;
int HasNewVersion(const std::string& rteFolder) const;

RteFile::Category m_cat; //file category
RteComponentInstance* m_ci; // pointer to an object of type RteComponentInstance
Expand Down Expand Up @@ -219,9 +221,10 @@ class RteTarget : public RteItem
* @brief determine file given by instances of type RteFileInstance and RteComponent
* @param fi given pointer of type RteFileInstance
* @param c given pointer of type RteComponent
* @param rteFolder the "RTE" folder path used for placing files
* @return pointer of type RteFile
*/
RteFile* GetFile(const RteFileInstance* fi, RteComponent* c) const;
RteFile* GetFile(const RteFileInstance* fi, RteComponent* c, const std::string& rteFolder) const;

/**
* @brief evaluate dependencies of selected components of the target
Expand Down Expand Up @@ -540,9 +543,10 @@ class RteTarget : public RteItem

/**
* @brief collect settings of given component instance
* @param rteFolder the "RTE" folder path used for placing files
* @param ci pointer to RteComponentInstance object
*/
void CollectComponentSettings(RteComponentInstance* ci);
void CollectComponentSettings(RteComponentInstance* ci, const std::string& rteFolder);

/**
* @brief collect documentation files from component groups
Expand Down
14 changes: 14 additions & 0 deletions libs/rtemodel/src/CprjFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,20 @@ RteItem* CprjFile::GetProjectInfo() const
return GetItemByTag("info");
}

const std::optional<std::string> CprjFile::GetRteFolder() const
{
if (m_cprjTargetElement) {
const auto buildOption = m_cprjTargetElement->GetBuildOption();
if (buildOption) {
const auto folder = buildOption->GetAttribute("rtedir");
if (!folder.empty()) {
return folder;
}
}
}
return {};
}

const list<RteItem*>& CprjFile::GetProjectComponents() const
{
return GetGrandChildren("components");
Expand Down
1 change: 1 addition & 0 deletions libs/rtemodel/src/RteCprjProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RteCprjProject::RteCprjProject(RteCprjModel* cprjModel) :
// set project name based on filename
SetName(RteUtils::ExtractFileBaseName(GetCprjFile()->GetPackageFileName()));
SetProjectPath(RteUtils::ExtractFilePath(GetCprjFile()->GetPackageFileName(), true));
SetRteFolder(GetCprjFile()->GetRteFolder());
}

RteCprjProject::~RteCprjProject()
Expand Down
4 changes: 2 additions & 2 deletions libs/rtemodel/src/RteFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void RteFile::GetAbsoluteSourcePaths(set<string>& paths) const
}


string RteFile::GetInstancePathName(const string& deviceName, int instanceIndex) const
string RteFile::GetInstancePathName(const string& deviceName, int instanceIndex, const string& rteFolder) const
{
string pathName;
RteComponent* c = GetComponent();
Expand All @@ -200,7 +200,7 @@ string RteFile::GetInstancePathName(const string& deviceName, int instanceIndex)
bool bForcedCopy = IsForcedCopy();
if (bConfig || bTemplate || bForcedCopy) {
if (bConfig || bForcedCopy) {
pathName = "RTE/";
pathName = rteFolder + "/";
const string& className = c->GetCclassName();
pathName += className;
pathName += "/";
Expand Down
16 changes: 8 additions & 8 deletions libs/rtemodel/src/RteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ RteFileInstance::RteFileInstance(RteItem* parent) :
m_tag = "file";
}

void RteFileInstance::Init(RteFile* f, const string& deviceName, int instanceIndex)
void RteFileInstance::Init(RteFile* f, const string& deviceName, int instanceIndex, const string& rteFolder)
{
m_instanceName = f->GetInstancePathName(deviceName, instanceIndex);
m_instanceName = f->GetInstancePathName(deviceName, instanceIndex, rteFolder);
m_instanceIndex = instanceIndex;
m_fileName = RteUtils::ExtractFileName(m_instanceName);
m_bRemoved = false;
Expand Down Expand Up @@ -719,20 +719,20 @@ RteFile::Category RteFileInstance::GetCategory() const
return RteFile::CategoryFromString(GetAttribute("category"));
}

int RteFileInstance::HasNewVersion(const string& targetName) const
int RteFileInstance::HasNewVersion(const string& targetName, const string& rteFolder) const
{
RteFile* f = GetFile(targetName);
RteFile* f = GetFile(targetName, rteFolder);
if (!f)
return 0;
int res = VersionCmp::Compare(f->GetVersionString(), GetVersionString());
return res;
}

int RteFileInstance::HasNewVersion() const
int RteFileInstance::HasNewVersion(const string& rteFolder) const
{
int newVersion = 0;
for (auto it = m_targetInfos.begin(); it != m_targetInfos.end(); it++) {
int newVer = HasNewVersion(it->first);
int newVer = HasNewVersion(it->first, rteFolder);
if (newVer > newVersion) {
newVersion = newVer;
if (newVersion > 2)
Expand Down Expand Up @@ -838,12 +838,12 @@ string RteFileInstance::GetAbsolutePath() const
return s;
}

RteFile* RteFileInstance::GetFile(const string& targetName) const
RteFile* RteFileInstance::GetFile(const string& targetName, const string& rteFolder) const
{
RteTarget* t = GetTarget(targetName);
if (t) {
RteComponent* c = GetComponent(targetName);
return t->GetFile(this, c);
return t->GetFile(this, c, rteFolder);
}
return NULL;
}
Expand Down
31 changes: 20 additions & 11 deletions libs/rtemodel/src/RteProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "RteProject.h"

#include "RteComponent.h"
#include "RteFile.h"
#include "RteGenerator.h"
#include "RteModel.h"
#include "CprjFile.h"
Expand All @@ -24,6 +25,8 @@

using namespace std;

const std::string DEFAULT_RTE_FOLDER = "RTE";

////////////////////////////
RteProject::RteProject() :
RteItem(NULL),
Expand Down Expand Up @@ -103,6 +106,13 @@ RteProject* RteProject::GetProject() const
return const_cast<RteProject*>(this);
}

const std::string& RteProject::GetRteFolder() const {
if (m_rteFolder.has_value()) {
return m_rteFolder.value();
}
return DEFAULT_RTE_FOLDER;
}

void RteProject::ClearClasses()
{
delete m_classes;
Expand Down Expand Up @@ -398,7 +408,7 @@ RteFileInstance* RteProject::AddFileInstance(RteComponentInstance* ci, RteFile*
return NULL;

string deviceName = target->GetFullDeviceName();
string id = f->GetInstancePathName(deviceName, index);
string id = f->GetInstancePathName(deviceName, index, GetRteFolder());
string absPath = GetProjectPath() + id;
target->AddComponentInstanceForFile(id, ci);

Expand All @@ -425,13 +435,12 @@ bool RteProject::UpdateFileToNewVersion(RteFileInstance* fi, RteFile* f, bool bM
return UpdateFileInstance(fi, f, bMerge, true);
}


void RteProject::InitFileInstance(RteFileInstance* fi, RteFile* f, int index, RteTarget* target, const string& oldVersion, bool bCopy)
{
string deviceName = target->GetFullDeviceName();
const string& targetName = target->GetName();

fi->Init(f, deviceName, index);
fi->Init(f, deviceName, index, GetRteFolder());
fi->Update(f, false);
fi->AddTargetInfo(targetName); // set/update supported targets
fi->SetRemoved(false);
Expand Down Expand Up @@ -791,7 +800,7 @@ void RteProject::Update()
continue; // leave available until missing is resolved

// check if component has the file for given target (resolved component can have another set of files, even config ones)
RteFile *f = target->GetFile(fi, c);
RteFile *f = target->GetFile(fi, c, GetRteFolder());
if (f) {
continue;
}
Expand Down Expand Up @@ -822,7 +831,7 @@ void RteProject::Update()
// add forced copy files
for (auto itf = forcedFiles.begin(); itf != forcedFiles.end(); itf++) {
RteFile* f = *itf;
string dst = GetProjectPath() + f->GetInstancePathName(EMPTY_STRING, 0);
string dst = GetProjectPath() + f->GetInstancePathName(EMPTY_STRING, 0, GetRteFolder());

error_code ec;
if (fs::exists(dst, ec))
Expand Down Expand Up @@ -1081,15 +1090,15 @@ void RteProject::CollectSettings()
}


string RteProject::GetRteComponentsH(const string & targetName, const string & prefix)
string RteProject::GetRteComponentsH(const string & targetName, const string & prefix, const string& rteFolder)
{
return GetRteHeader(string("/RTE_Components.h"), targetName, prefix);
return GetRteHeader(string("/RTE_Components.h"), targetName, prefix, rteFolder);
}

string RteProject::GetRteHeader(const string& name, const string & targetName, const string & prefix)
string RteProject::GetRteHeader(const string& name, const string & targetName, const string & prefix, const string& rteFolder)
{
string rteHeader = prefix;
rteHeader += "RTE/_";
rteHeader += rteFolder + "/_";
rteHeader += WildCards::ToX(targetName);
rteHeader += "/";
rteHeader += name;
Expand All @@ -1107,7 +1116,7 @@ void RteProject::CollectSettings(const string& targetName)
// collect includes, libs and RTE_Components_h defines for active target
for (auto itc = m_components.begin(); itc != m_components.end(); itc++) {
RteComponentInstance* ci = itc->second;
t->CollectComponentSettings(ci);
t->CollectComponentSettings(ci, GetRteFolder());
}
t->CollectClassDocs();

Expand Down Expand Up @@ -1155,7 +1164,7 @@ void RteProject::CollectSettings(const string& targetName)
// check if RTE components are used before setting RTE_Components.h include path and adding to target as well as setting -D_RTE_ at the command line.
// add .\RTE\_TargetName\RTE_Components.h filePath
if (GetComponentCount() > 0) {
string rteComponentsH = GetRteComponentsH(targetName, "./");
string rteComponentsH = GetRteComponentsH(targetName, "./", GetRteFolder());
t->AddIncludePath(RteUtils::ExtractFilePath(rteComponentsH, false));
t->AddFile("RTE_Components.h", RteFile::HEADER, "Component selection"); // add ".\RTE\_TargetName\RTE_Components.h" folder to all target includes
t->InsertDefine("_RTE_");
Expand Down
Loading

0 comments on commit 6dcf591

Please sign in to comment.