Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Prototype of a template project generator #8

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

jolly-fellow
Copy link
Contributor

Includes two simple templates described in the Aproj user's guide to show that the idea works.

Copy link
Contributor

@mikelik mikelik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea looks good!
We need to make it compilable before merging.


- How to Build -
- cd to 'build' directory
- run the command 'cmake ..'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my case it gives error:

mikel@msi:~/repo/antler-proj/templates/mikel/build$ cmake ..
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present. 

but the same command is in cdt, so I guess the issue should be created in cdt

- cd to 'build' directory
- run the command 'cmake ..'
- run the command 'make'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case cmake doesn't work, so I would add similar options as in original README.txt in cdt/examples:

Suggested change
-- How to build with cdt-cpp --
- cd into the 'build' directory
- run the command 'cdt-cpp -abigen ../src/{{APROJ_PROJECT_NAME}}.cpp -o {{APROJ_PROJECT_NAME}}.wasm -I ../include/'

#include <eosio/eosio.hpp>
using namespace eosio;

CONTRACT {{APROJ_PROJECT_NAME}} : public contract {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CONTRACT is an old macro / old way of creating contracts.
The new way is attribute [[eosio::contract]].
This PR is basing on cdt-init which generates old project.
I think it should base on newer example: https://github.com/AntelopeIO/cdt/tree/main/examples/hello

public:
using contract::contract;

ACTION hi( name nm );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ACTION hi( name nm );
[[eosio::action]]
hi( name nm );

@@ -0,0 +1,5 @@
#include <{{APROJ_PROJECT_NAME}}.hpp>
ACTION {{APROJ_PROJECT_NAME}}::hi( name nm ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ACTION {{APROJ_PROJECT_NAME}}::hi( name nm ) {
[[eosio::action]]
{{APROJ_PROJECT_NAME}}::hi( name nm ) {

- cd to 'build' directory
- run the command 'cmake ..'
- run the command 'make'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- How to build with cdt-cpp --
- cd into the 'build' directory
- run the command 'cdt-cpp -abigen ../src/{{APROJ_PROJECT_NAME}}.cpp -o {{APROJ_PROJECT_NAME}}.wasm -I ../include/'

};

// declaration of a type of a table which will contain our data
using table_t = eosio::multi_index<"my_table"_n, data_t>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to compile example project abc generated using this template with command:
cdt-cpp -abigen ../src/abc.cpp -o abc.wasm -I ../include/

I get an error:

mikel@msi:~/repo/antler-proj/templates/abc/build$ cdt-cpp -abigen ../src/abc.cpp  -o abc.wasm -I ../include/
In file included from /home/mikel/repo/antler-proj/templates/abc/build/../src/abc.cpp:1:
In file included from /usr/opt/cdt/3.1.0/bin/../include/eosiolib/contracts/eosio/eosio.hpp:6:
In file included from /usr/opt/cdt/3.1.0/bin/../include/eosiolib/contracts/eosio/../../contracts/eosio/action.hpp:10:
/usr/opt/cdt/3.1.0/bin/../include/eosiolib/contracts/eosio/../../core/eosio/name.hpp:324:19: error: constexpr variable 'x' must be initialized by a constant expression
   constexpr auto x = eosio::name{std::string_view{eosio::detail::to_const_char_arr<Str...>::value, sizeof...(Str)}};
                  ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mikel/repo/antler-proj/templates/abc/build/../src/abc.cpp:21:48: note: in instantiation of function template specialization 'operator""_n<char, 'm', 'y', '_', 't', 'a', 'b', 'l', 'e'>' requested here
  using table_t = eosio::multi_index<"my_table"_n, data_t>;
                                               ^
/usr/opt/cdt/3.1.0/bin/../include/eosiolib/contracts/eosio/../../core/eosio/name.hpp:116:13: note: non-constexpr function 'check' cannot be used in a constant expression
            eosio::check( false, "character is not in allowed character set for names" );
            ^
/usr/opt/cdt/3.1.0/bin/../include/eosiolib/contracts/eosio/../../core/eosio/name.hpp:90:22: note: in call to 'char_to_value(95)'
            value |= char_to_value( str[i] );
                     ^
/usr/opt/cdt/3.1.0/bin/../include/eosiolib/contracts/eosio/../../core/eosio/name.hpp:324:23: note: in call to 'name({&value[0], 8})'
   constexpr auto x = eosio::name{std::string_view{eosio::detail::to_const_char_arr<Str...>::value, sizeof...(Str)}};
                      ^
/usr/opt/cdt/3.1.0/bin/../include/eosiolib/core/eosio/check.hpp:57:16: note: declared here
   inline void check(bool pred, const char* msg) {
               ^
/home/mikel/repo/antler-proj/templates/abc/build/../src/abc.cpp:21:38: error: non-type template argument is not a constant expression
  using table_t = eosio::multi_index<"my_table"_n, data_t>;
                                     ^~~~~~~~~~~~

full_project_path = Path(project_path).absolute() / project_name

if not os.path.isdir(full_template_path):
raise Exception("Can't find template: " + template_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of warning:
generator.py:15:8: W0719: Raising too general exception: Exception (broad-exception-raised)

Suggested change
raise Exception("Can't find template: " + template_name)
raise ValueError("Can't find template: " + template_name)

@ScottBailey
Copy link
Contributor

Holding off on this PR until this release is completed.

@ScottBailey ScottBailey marked this pull request as draft March 14, 2023 21:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Extend the project init tool with a library of project templates
3 participants