Skip to content

Discussing -resource-dir flag while creating interpreter #279

@anutosh491

Description

@anutosh491
  1. Native case
  • We always will be providing it from kernel.jsoN. So this block looks redundant

    if (std::find_if(ExtraArgs.begin(), ExtraArgs.end(), [](const std::string& s) {
    return s == "-resource-dir";}) == ExtraArgs.end()) {
    std::string resource_dir = Cpp::DetectResourceDir();
    if (resource_dir.empty())
    std::cerr << "Failed to detect the resource-dir\n";
    ClangArgs.push_back("-resource-dir");
    ClangArgs.push_back(resource_dir.c_str());
    }

  • Even if it is not redundant, it would fail (cause there's an implementation logical error I think)

std::string resource_dir = Cpp::DetectResourceDir();  // we don't pass anything here 

// function from cppinterop is framed like this 

  std::string DetectResourceDir(const char* ClangBinaryName /* = clang */) {
    std::string cmd = std::string(ClangBinaryName) + " -print-resource-dir";
    std::vector<std::string> outs;
    exec(cmd.c_str(), outs);
    if (outs.empty() || outs.size() > 1)
      return "";
    
   ......

Here ClangBinaryName would end up being empty as we're not passing anything (probably should pass "clang") and hence this would return an empty string resulting in std::cerr << "Failed to detect the resource-dir\n"; this error being executed.

I see

  TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/,
                              const std::vector<const char*>& GpuArgs /*={}*/) {
    std::string MainExecutableName =
      sys::fs::getMainExecutable(nullptr, nullptr);
    std::string ResourceDir = MakeResourcesPath();
    std::vector<const char *> ClingArgv = {"-resource-dir", ResourceDir.c_str(),
                                           "-std=c++14"};
    ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
........
    ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
......

Shouldn't we prefer having (possibly also checking if the -std=... flag is also covered already)

std::vector<const char *> ClingArgv = {"-std=c++14"};

if (std::find_if(Args.begin(), Args.end(), [](const char* s) {
      return std::string(s) == "-resource-dir";}) == Args.end()) {
    std::string ResourceDir = MakeResourcesPath();
    ClingArgv.insert(ClingArgv.begin(), "-resource-dir");
    ClingArgv.insert(ClingArgv.begin() + 1, ResourceDir.c_str());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions