Skip to content

Commit

Permalink
✨ feat: add project type
Browse files Browse the repository at this point in the history
  • Loading branch information
xqyjlj committed Dec 28, 2023
1 parent 6fa5ee3 commit 2f8a28b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion apps/dev/views/mainwindow_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,5 @@ void mainwindow_view::action_generate_triggered_callback(const bool checked) con
{
Q_UNUSED(checked)

_project_instance->generate_code(project::code_project_type::CODE_PROJECT_TYPE_XMAKE);
_project_instance->generate_code("xmake");
}
3 changes: 2 additions & 1 deletion common/project/inc/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class generator final
/**
* @brief generate xmake code file content from project table
* @param project_table: project table
* @param type: project type
* @return code file
*/
static QString generate(const project_table::project_t &project_table);
static QString generate(const project_table::project_t &project_table, const QString type);

private:
generator();
Expand Down
15 changes: 5 additions & 10 deletions common/project/inc/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <QObject>

#include "generator.h"
#include "ip_table.h"
#include "map_table.h"
#include "project_table.h"
Expand All @@ -41,12 +42,6 @@ class project final : public QObject
Q_OBJECT

public:
typedef enum
{
CODE_PROJECT_TYPE_XMAKE = 0,
CODE_PROJECT_TYPE_MDK_ARM
} code_project_type;

typedef enum
{
CORE_ATTRIBUTE_TYPE_NAME = 0,
Expand Down Expand Up @@ -224,18 +219,18 @@ class project final : public QObject
* @brief save project to file
* @param path: project file path
*/
void save_project(const QString &path) const;
void save_project(const QString &path);

/**
* @brief save project to file
*/
void save_project() const;
void save_project();

/**
* @brief dump project
* @return project string
*/
QString dump_project() const;
QString dump_project();

/**
* @brief clear project
Expand All @@ -246,7 +241,7 @@ class project final : public QObject
* @brief generate_code code
* @param type: code type
*/
void generate_code(int type) const;
void generate_code(const QString type) const;

private:
static project *_instance;
Expand Down
12 changes: 7 additions & 5 deletions common/project/inc/project_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class project_table
typedef QMap<QString, QString> pin_function_property_t;
typedef QMap<QString, pin_function_property_t> pin_function_properties_t;

typedef struct pin_config_struct
typedef struct
{
QString function; // pin selected function
QString comment; // pin comment
bool locked; // pin locked
pin_function_properties_t function_property; // pin function properties
} pin_config_t;

typedef struct core_struct
typedef struct
{
QString name; // name
QString hal; // hal
Expand All @@ -58,10 +58,12 @@ class project_table
QStringList modules; // modules
} core_t;

typedef struct project_struct
typedef struct
{
QMap<QString, pin_config_t> pin_configs; // pin configs
core_t core; // core configs
QString target; // target type: xmake, mdk, cmake
QString version; // csp version
} project_t;

public:
Expand All @@ -78,14 +80,14 @@ class project_table
* @param p: project
* @param path: project file path
*/
static void save_project(const project_t &p, const QString &path);
static void save_project(project_t &p, const QString &path);

/**
* @brief dump project to json string
* @param p: project
* @return yaml string
*/
static QString dump_project(const project_t &p);
static QString dump_project(project_t &p);

private:
explicit project_table();
Expand Down
4 changes: 3 additions & 1 deletion common/project/src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ void generator::add_files(QString &buffer, const QStringList &values)
replace_var(buffer, "files", list, true);
}

QString generator::generate(const project_table::project_t &project_table)
QString generator::generate(const project_table::project_t &project_table, const QString type)
{
Q_UNUSED(type)

const QDateTime date_time = QDateTime::currentDateTime();
const QString date = date_time.toString("yyyy-MM-dd hh:mm:ss");
const QString version = CONFIGURE_PROJECT_VERSION;
Expand Down
23 changes: 6 additions & 17 deletions common/project/src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ void project::load_project(const QString &path)
load_ips(_project.core.hal, _project.core.target);
}

void project::save_project(const QString &path) const
void project::save_project(const QString &path)
{
project_table::save_project(_project, path);
}

void project::save_project() const
void project::save_project()
{
Q_ASSERT(!_path.isEmpty());

Expand All @@ -292,7 +292,7 @@ void project::save_project() const
project_table::save_project(_project, _path);
}

QString project::dump_project() const
QString project::dump_project()
{
return project_table::dump_project(_project);
}
Expand All @@ -303,19 +303,8 @@ void project::clear_project()
emit signals_project_clear();
}

void project::generate_code(const int type) const
void project::generate_code(const QString type) const
{
switch (type)
{
case CODE_PROJECT_TYPE_XMAKE: {
const QString rtn = xmake::lua(QString("%1/scripts/coder/coder.lua").arg(config::repodir()), {"-p", _path});
generator::generate(_project);
break;
}
case CODE_PROJECT_TYPE_MDK_ARM: {
break;
}
default:
return;
}
const QString rtn = xmake::lua(QString("%1/scripts/coder/coder.lua").arg(config::repodir()), {"-p", _path});
generator::generate(_project, type);
}
8 changes: 5 additions & 3 deletions common/project/src/project_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QDebug>
#include <QFile>

#include "configure.h"
#include "os.h"
#include "project_table.h"
#include "qtjson.h"
Expand All @@ -39,7 +40,7 @@ namespace nlohmann
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(project_table::pin_config_t, function, comment, locked, function_property)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(project_table::core_t, name, hal, target, package, company, type, toolchains,
modules)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(project_table::project_t, core, pin_configs)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(project_table::project_t, core, pin_configs, target, version)
} // namespace nlohmann

#include <QDebug>
Expand Down Expand Up @@ -71,7 +72,7 @@ void project_table::load_project(project_t *project, const QString &path)
}
}

void project_table::save_project(const project_table::project_t &p, const QString &path)
void project_table::save_project(project_table::project_t &p, const QString &path)
{
Q_ASSERT(!path.isEmpty());

Expand All @@ -82,8 +83,9 @@ void project_table::save_project(const project_table::project_t &p, const QStrin
file.close();
}

QString project_table::dump_project(const project_table::project_t &p)
QString project_table::dump_project(project_table::project_t &p)
{
p.version = QString("v%1").arg(CONFIGURE_PROJECT_VERSION);
const nlohmann::json j = p;
return QString::fromStdString(j.dump(2));
}
4 changes: 3 additions & 1 deletion common/project/test/res/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"modules": [],
"toolchains": "arm-none-eabi"
},
"target": "xmake",
"version": "v0.0.0.1",
"pin_configs": {
"pa1": {
"function": "",
Expand All @@ -17,4 +19,4 @@
"function_property": {}
}
}
}
}
2 changes: 1 addition & 1 deletion common/project/test/testcase_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class testcase_generator final : public QObject
project_table::load_project(&p, ":/project.json");
QVERIFY(!p.core.name.isEmpty());

const QString data = generator::generate(p);
const QString data = generator::generate(p, "xmake");
QVERIFY(!data.isEmpty());
QVERIFY(!data.contains("${{"));

Expand Down

0 comments on commit 2f8a28b

Please sign in to comment.