Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit 78704b3

Browse files
committed
Search for XS in the same directory
1 parent 5e32e28 commit 78704b3

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

src-cpp/randomjs/ProgramRunner.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ along with RandomJS. If not, see<http://www.gnu.org/licenses/>.
2020
#include "ProgramRunner.h"
2121
#include "Program.h"
2222
#include <boost/process.hpp>
23+
#include <boost/filesystem.hpp>
2324

2425
constexpr size_t programBufferCapacity = 256 * 1024;
2526

2627
namespace bp = boost::process;
28+
namespace bf = boost::filesystem;
2729

2830
void ProgramRunner::startProcess() {
2931
delete runnerStdout;
@@ -39,7 +41,27 @@ void ProgramRunner::startProcess() {
3941
}
4042
}
4143

42-
ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char* arguments)
44+
ProgramRunner::ProgramRunner(const char* self, const char* xs)
45+
: stream(programBufferCapacity),
46+
arguments(nullptr),
47+
runner(nullptr),
48+
runnerStdout(nullptr),
49+
runnerStdin(nullptr)
50+
{
51+
std::vector<bf::path> searchPaths;
52+
auto basedir = bf::system_complete(self).parent_path();
53+
searchPaths.push_back(basedir);
54+
auto fullPath = bp::search_path(xs, searchPaths);
55+
auto pathString = fullPath.string();
56+
int allocationSize = pathString.length() + 1;
57+
char* pathBuffer = new char[allocationSize];
58+
std::copy(pathString.begin(), pathString.end(), pathBuffer);
59+
pathBuffer[pathString.length()] = '\0';
60+
this->executable = pathBuffer;
61+
startProcess();
62+
}
63+
64+
/*ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char* arguments)
4365
: stream(programBufferCapacity),
4466
arguments(arguments),
4567
runner(nullptr),
@@ -56,7 +78,7 @@ ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char
5678
this->executable = executable;
5779
}
5880
startProcess();
59-
}
81+
}*/
6082

6183
void ProgramRunner::writeProgram(Program* p) {
6284
stream.clear();

src-cpp/randomjs/ProgramRunner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace boost {
4242
class ProgramRunner
4343
{
4444
public:
45-
ProgramRunner(const char* executable, bool searchPath = false, const char* arguments = nullptr);
45+
ProgramRunner(const char* self, const char* xs);
46+
//ProgramRunner(const char* executable, bool searchPath = false, const char* arguments = nullptr);
4647
void writeProgram(Program*);
4748
const char* getProgramBuffer() const {
4849
return stream.data();

src-cpp/randomjs/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char** argv) {
4747
0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca,
4848
0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09
4949
};
50-
ProgramRunner runner("./xst");
50+
ProgramRunner runner(argv[0], "xst");
5151
int* nonce = (int*)(blockTemplate + 39);
5252
RandomGenerator rand;
5353
ProgramFactory pf(rand);

0 commit comments

Comments
 (0)