Skip to content

Commit 8526c87

Browse files
committed
Enhanced directory structure for generated files.
1 parent ebe6786 commit 8526c87

File tree

4 files changed

+106
-14
lines changed

4 files changed

+106
-14
lines changed

src/codegen/c-main-generator.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ void CiMainGenerator::Gen_ConfigHeader()
393393
fwriter->AppendLine("");
394394
fwriter->AppendLine(StrPrint("/* #define %s */", fdesc->usecsm_def.c_str()), 2);
395395

396-
fwriter->Flush(fdesc->core_c.dir + '/' + fdesc->drvname + "-config.h");
396+
fwriter->Flush(fdesc->confdir + '/' + fdesc->drvname + "-config.h");
397397
}
398398

399399
void CiMainGenerator::Gen_FMonHeader()
@@ -427,7 +427,7 @@ separated .c file. If it won't be done the linkage error will happen\n*/", 2);
427427
for (size_t num = 0; num < sigprt->sigs_expr.size(); num++)
428428
{
429429
auto msg = &(sigprt->sigs_expr[num]->msg);
430-
fwriter->AppendLine(StrPrint("void FMon_%s_%s(FrameMonitor_t* _mon);",
430+
fwriter->AppendLine(StrPrint("void FMon_%s_%s(FrameMonitor_t* _mon, uint32_t msgid);",
431431
msg->Name.c_str(), fdesc->drvname.c_str()));
432432
}
433433

@@ -459,7 +459,8 @@ next generation will completely clear all manually added code (!)\n\
459459
for (size_t num = 0; num < sigprt->sigs_expr.size(); num++)
460460
{
461461
auto msg = &(sigprt->sigs_expr[num]->msg);
462-
fwriter->AppendLine(StrPrint("void FMon_%s_%s(FrameMonitor_t* _mon)\n{\n (void)_mon;\n}\n",
462+
fwriter->AppendLine(
463+
StrPrint("void FMon_%s_%s(FrameMonitor_t* _mon, uint32_t msgid)\n{\n (void)_mon;\n (void)msgid;\n}\n",
463464
msg->Name.c_str(), fdesc->drvname.c_str()));
464465
}
465466

@@ -534,7 +535,7 @@ void CiMainGenerator::Gen_CanMonUtil()
534535
fwriter->AppendLine("#endif");
535536
fwriter->AppendLine("");
536537

537-
fwriter->Flush(fdesc->core_c.dir + '/' + "canmonitorutil.h");
538+
fwriter->Flush(fdesc->incdir + '/' + "canmonitorutil.h");
538539
}
539540

540541
void CiMainGenerator::Gen_DbcCodeConf()
@@ -554,7 +555,7 @@ void CiMainGenerator::Gen_DbcCodeConf()
554555
fwriter->AppendLine("// #define __DEF_{your_driver_name}__");
555556
fwriter->AppendLine("");
556557

557-
fwriter->Flush(fdesc->core_c.dir + '/' + "dbccodeconf.h");
558+
fwriter->Flush(fdesc->confdir + '/' + "dbccodeconf.h");
558559
}
559560

560561
void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bits, size_t padwidth)
@@ -730,7 +731,7 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
730731

731732
auto Fmon_func = "FMon_" + sgs->msg.Name + "_" + fdesc->drvname;
732733

733-
fwriter->AppendLine(StrPrint(" %s(&_m->mon1);", Fmon_func.c_str()));
734+
fwriter->AppendLine(StrPrint(" %s(&_m->mon1, %s_CANID);", Fmon_func.c_str(), sgs->msg.Name.c_str()));
734735

735736
fwriter->AppendLine(StrPrint("#endif // %s", fdesc->usemon_def.c_str()), 2);
736737

src/codegen/fs-creator.cpp

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ static const int32_t kTmpLen = 1024;
77

88
static char _tmpb[kTmpLen];
99

10+
static const char* kLibDir = "/lib";
11+
static const char* kUsrDir = "/usr";
12+
static const char* kIncDir = "/inc";
13+
static const char* kConfDir = "/conf";
14+
static const char* kUtilDir = "/butl";
15+
1016
FsCreator::FsCreator()
1117
{
1218
}
@@ -36,10 +42,12 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
3642
}
3743
else
3844
{
45+
std::string separator = basepath.at(basepath.size() - 1) == '/' ? "" : "/";
46+
3947
for (int32_t dirnum = 0; dirnum < 1000; dirnum++)
4048
{
4149
snprintf(_tmpb, kTmpLen, "%03d", dirnum);
42-
work_dir_path = basepath + "/" + _tmpb;
50+
work_dir_path = basepath + separator + _tmpb;
4351

4452
if (stat(work_dir_path.c_str(), &info) != 0)
4553
{
@@ -63,9 +71,44 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
6371
}
6472
}
6573
}
74+
75+
FS.libdir = work_dir_path + kLibDir;
76+
77+
if (std::filesystem::create_directory(FS.libdir))
78+
{
79+
// ret = false;
80+
}
81+
82+
FS.usrdir = work_dir_path + kUsrDir;
83+
84+
if (std::filesystem::create_directory(FS.usrdir))
85+
{
86+
// ret = false;
87+
}
88+
89+
FS.incdir = work_dir_path + kIncDir;
90+
91+
if (std::filesystem::create_directory(FS.incdir))
92+
{
93+
// ret = false;
94+
}
95+
96+
FS.confdir = work_dir_path + kConfDir;
97+
98+
if (std::filesystem::create_directory(FS.confdir))
99+
{
100+
// ret = false;
101+
}
102+
103+
FS.utildir = work_dir_path + kUtilDir;
104+
105+
if (std::filesystem::create_directory(FS.utildir))
106+
{
107+
// ret = false;
108+
}
66109
}
67110

68-
if (ret)
111+
if (true)
69112
{
70113
// directory valid and exists, set all the values
71114
FS.DrvName_orig = drvname;
@@ -74,11 +117,11 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
74117

75118
FS.core_h.dir = work_dir_path;
76119
FS.core_h.fname = FS.drvname + ".h";
77-
FS.core_h.fpath = work_dir_path + "/" + FS.core_h.fname;
120+
FS.core_h.fpath = FS.libdir + "/" + FS.core_h.fname;
78121

79122
FS.core_c.dir = work_dir_path;
80123
FS.core_c.fname = FS.drvname + ".c";
81-
FS.core_c.fpath = work_dir_path + "/" + FS.core_c.fname;
124+
FS.core_c.fpath = FS.libdir + "/" + FS.core_c.fname;
82125

83126
FS.util_h.dir = work_dir_path;
84127
FS.util_h.fname = FS.drvname + "-binutil" + ".h";
@@ -90,11 +133,11 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
90133

91134
FS.fmon_h.dir = work_dir_path;
92135
FS.fmon_h.fname = FS.drvname + "-fmon.h";
93-
FS.fmon_h.fpath = work_dir_path + "/" + FS.fmon_h.fname;
136+
FS.fmon_h.fpath = FS.libdir + "/" + FS.fmon_h.fname;
94137

95138
FS.fmon_c.dir = work_dir_path;
96139
FS.fmon_c.fname = FS.drvname + "-fmon.c";
97-
FS.fmon_c.fpath = work_dir_path + "/" + FS.fmon_c.fname;
140+
FS.fmon_c.fpath = FS.usrdir + "/" + FS.fmon_c.fname;
98141

99142
snprintf(_tmpb, kTmpLen, "%s_USE_BITS_SIGNAL", FS.DRVNAME.c_str());
100143
FS.usebits_def = _tmpb;
@@ -131,3 +174,42 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
131174

132175
return ret;
133176
}
177+
178+
std::string FsCreator::CreateSubDir(std::string basepath, std::string sub, bool rw)
179+
{
180+
std::string ret = basepath;
181+
struct stat info;
182+
183+
if (basepath.size() == 0 || sub.size() == 0)
184+
{
185+
return "";
186+
}
187+
188+
if (basepath.at(basepath.size() - 1) != '/')
189+
{
190+
basepath.append("/");
191+
}
192+
193+
basepath.append(sub);
194+
195+
bool ok = true;
196+
197+
if (stat(basepath.c_str(), &info) != 0 && rw)
198+
{
199+
// directory already exists and rewrite option is requested
200+
ok = std::filesystem::remove(basepath);
201+
}
202+
203+
if (!ok)
204+
{
205+
// error on removing directory
206+
return "";
207+
}
208+
209+
if (std::filesystem::create_directory(basepath) != 0)
210+
{
211+
ret = "";
212+
}
213+
214+
return basepath;
215+
}

src/codegen/fs-creator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ typedef struct
1313
// up case driver name
1414
std::string DRVNAME;
1515

16+
std::string libdir;
17+
std::string usrdir;
18+
std::string incdir;
19+
std::string confdir;
20+
std::string utildir;
21+
1622
OutFileDescriptor_t core_h;
1723
OutFileDescriptor_t core_c;
1824

@@ -49,6 +55,8 @@ class FsCreator {
4955

5056
bool PrepareDirectory(std::string drvname, std::string basepath, bool rw, std::string& info);
5157

58+
std::string CreateSubDir(std::string basepath, std::string subdir, bool rm = true);
59+
5260
FsDescriptor_t FS;
5361

5462
};

src/maincli.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ int main(int argc, char* argv[])
7272

7373
std::string info("");
7474

75-
auto ret = fscreator->PrepareDirectory(dbc_driver_name.c_str(), source_files_out_path.c_str(), true, info);
75+
// create main destination directory
76+
auto ret = fscreator->PrepareDirectory(dbc_driver_name.c_str(), source_files_out_path.c_str(), false, info);
7677

7778
if (ret)
7879
{
@@ -127,7 +128,7 @@ int main(int argc, char* argv[])
127128
{
128129
std::string util_name = nodes[node] + "_" + dbc_driver_name;
129130

130-
ret = fscreator->PrepareDirectory(util_name.c_str(), source_files_out_path.c_str(), true, info);
131+
ret = fscreator->PrepareDirectory(util_name.c_str(), fscreator->FS.utildir.c_str(), true, info);
131132

132133
MsgsClassification groups;
133134

0 commit comments

Comments
 (0)