Skip to content

Commit

Permalink
Merge pull request #7 from eosnewyork/updatecdt
Browse files Browse the repository at this point in the history
update cdt and rearrange cpp/hpp files
  • Loading branch information
WarrickFitz authored Aug 30, 2019
2 parents 4b1151e + 3f98974 commit 13eef87
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
37 changes: 20 additions & 17 deletions EOSCPPManagerLib/EOSCPPManagerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void createNewSmartContract(string folder, string contractName, bool over
{

//logger.Info("Create new smart contract template \"{0}\" in \"{1}\"", contractName, folder);
if(!Directory.Exists(folder))
if (!Directory.Exists(folder))
{
throw new Exception("The folder \"{0}\", does not exist of can not be accessed");
}
Expand All @@ -33,14 +33,14 @@ public void createNewSmartContract(string folder, string contractName, bool over
}
else
{
if(Directory.Exists(fullPath))
if (Directory.Exists(fullPath))
{
if(!String.IsNullOrEmpty(fullPath))
if (!String.IsNullOrEmpty(fullPath))
{
logger.Warn("By request, deleting {1} before creating new template at this path.", overwriteExisting, fullPath);
Directory.Delete(fullPath,true);
Directory.Delete(fullPath, true);
}

}

string baseDir = AppDomain.CurrentDomain.BaseDirectory;
Expand All @@ -50,30 +50,33 @@ public void createNewSmartContract(string folder, string contractName, bool over

// Copy the build and cmakelist
var buildFileDestinationPath = Path.Combine(fullPath, "build.sh");
File.Copy(Path.Combine(baseDir,"templateFiles\\build.sh"), buildFileDestinationPath);
File.Copy(Path.Combine(baseDir, "templateFiles\\build.sh"), buildFileDestinationPath);
var cmakelistFileDestinationPath = Path.Combine(fullPath, "CMakeLists.txt");
File.Copy(Path.Combine(baseDir, "templateFiles\\CMakeLists.txt"), cmakelistFileDestinationPath);
var gitIgnoreDestinationPath = Path.Combine(fullPath, ".gitignore");
File.Copy(Path.Combine(baseDir, "templateFiles\\_gitignore"), gitIgnoreDestinationPath);



// Replace the test references with the name of the template.
string updatedCmakeText = File.ReadAllText(cmakelistFileDestinationPath);
updatedCmakeText = updatedCmakeText.Replace("hello", contractName);
File.WriteAllText(cmakelistFileDestinationPath, updatedCmakeText);

// Copy the cpp and hpp file - the template itself.
var cppFileDestinationPath = Path.Combine(fullPath, contractName+".cpp");
var cppFileDestinationPath = Path.Combine(fullPath, contractName + ".cpp");
File.Copy(Path.Combine(baseDir, "templateFiles\\test.cpp"), cppFileDestinationPath);
string updatedCPPText = File.ReadAllText(cppFileDestinationPath);
updatedCPPText = updatedCPPText.Replace("hello", contractName);
File.WriteAllText(cppFileDestinationPath, updatedCPPText);



var hppFile = Path.Combine(fullPath, contractName+".hpp");
var hppFile = Path.Combine(fullPath, contractName + ".hpp");
File.Copy(Path.Combine(baseDir, "templateFiles\\test.hpp"), hppFile);
string updatedHPPText = File.ReadAllText(hppFile);
updatedHPPText = updatedHPPText.Replace("hello", contractName);
File.WriteAllText(hppFile, updatedHPPText);

// Create the .vscode folder and content so that vscode knows how to handle the contents
String vscodeFolder = Path.Combine(fullPath, ".vscode");
Expand All @@ -84,10 +87,10 @@ public void createNewSmartContract(string folder, string contractName, bool over
String destFilePath = Path.Combine(vscodeFolder, fileInfo.Name);
File.Copy(srcPath, destFilePath, true);

if(destFilePath.Contains("c_cpp_properties.json"))
if (destFilePath.Contains("c_cpp_properties.json"))
{
string updatedPropertiesText = File.ReadAllText(destFilePath);
updatedPropertiesText = updatedPropertiesText.Replace("C:/eosincludes", Util.AppDataFolder().Replace(@"\","/"));
updatedPropertiesText = updatedPropertiesText.Replace("C:/eosincludes", Util.AppDataFolder().Replace(@"\", "/"));
File.WriteAllText(destFilePath, updatedPropertiesText);

}
Expand All @@ -103,14 +106,14 @@ public void initializeWindowEnv()
{
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
logger.Info("Adding {0} to PATH", baseDir);

const string name = "PATH";
string pathvar = System.Environment.GetEnvironmentVariable(name);

logger.Debug("Print path before change");
printPath(pathvar);

if(pathvar.ToUpper().Contains(baseDir.ToUpper()))
if (pathvar.ToUpper().Contains(baseDir.ToUpper()))
{
logger.Warn("Path ENV already contains {0}. Nothing changed.", baseDir);
}
Expand All @@ -132,21 +135,21 @@ public void initializeInclude()
var includeFolder = Util.AppDataFolder();
logger.Info("Include Folder = {0}.", includeFolder);

if(Directory.Exists(includeFolder))
if (Directory.Exists(includeFolder))
{
logger.Info("Deleting existsing folder");
Directory.Delete(includeFolder, true);
}

if(!Directory.Exists(includeFolder))
if (!Directory.Exists(includeFolder))
{
logger.Info("Create folder {0}", includeFolder);
Directory.CreateDirectory(includeFolder);
logger.Info("Pause for 2 seconds before starting the copy.");
Thread.Sleep(2000);
}


Dictionary<String, String> mounts = new Dictionary<string, string>();
mounts.Add(includeFolder, "/host_eosinclude");

Expand Down Expand Up @@ -186,7 +189,7 @@ public void initializeInclude()
mkdir -p /host_eosinclude/usr/global/include; \
cp -v -R /usr/include /host_eosinclude/usr/global;
".Replace("\r","");
".Replace("\r", "");
var asyncResult = DockerHelper.RunCommandAsync(cmd, Util.getContainerName(includeFolder)).Result;

logger.Info("Include File written to {0}. This include path will be referened in any new projects created.", includeFolder);
Expand Down
18 changes: 6 additions & 12 deletions EOSCPPManagerLib/templateFiles/test.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#include <eosiolib/eosio.hpp>
#include "hello.hpp"

using namespace eosio;
ACTION hello::hi(name user)
{
print("Hello, ", name{user});
}

CONTRACT hello : public eosio::contract{
public:
using contract::contract;

ACTION hi(name user) {
print("Hello, ", name{ user });
}
};

EOSIO_DISPATCH(hello, (hi))
// EOSIO_DISPATCH(hello, (hi))
10 changes: 10 additions & 0 deletions EOSCPPManagerLib/templateFiles/test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <eosio/eosio.hpp>

using namespace eosio;

CONTRACT hello : public eosio::contract
{
public:
using contract::contract;
ACTION hi(name user);
};
3 changes: 1 addition & 2 deletions EOSEasyContract/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"eosiocppDockerImage": "binaryfocus/eosio_wasm_1.5.1"
"eosiocppDockerImage": "eosnewyork/eos.cdt:1.6.2_1.8.2_18.04"
}

2 changes: 1 addition & 1 deletion release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ md releases
rmdir /s /q .\EOSEasyContract\bin\release

set winOS=win-x64
# set unixOS=osx-x64 linux-x64
; set unixOS=osx-x64 linux-x64

for %%N in (%winOS%) do (
set rid=%%N
Expand Down

0 comments on commit 13eef87

Please sign in to comment.