~unity-team/unity-scopes-api/vivid+overlay

« back to all changes in this revision

Viewing changes to scoperegistry/scoperegistry.cpp

  • Committer: CI Train Bot
  • Author(s): Pawel Stolowski
  • Date: 2015-09-21 13:32:10 UTC
  • mfrom: (261.1.44 staging)
  • Revision ID: ci-train-bot@canonical.com-20150921133210-53i4a31z2kkik91u
Merged devel.
Approved by: Marcus Tomlinson

Show diffs side-by-side

added added

removed removed

Lines of Context:
259
259
    }
260
260
}
261
261
 
262
 
string get_first_component(string const& id, string const& custom_exec)
263
 
{
264
 
    if (custom_exec.empty())
265
 
    {
266
 
        throw unity::InvalidArgumentException("Invalid scope runner executable for scope: " + id);
267
 
    }
268
 
 
269
 
    wordexp_t exp;
270
 
    string result;
271
 
 
272
 
    // Split command into program and args
273
 
    if (wordexp(custom_exec.c_str(), &exp, WRDE_NOCMD) == 0)
274
 
    {
275
 
        util::ResourcePtr<wordexp_t*, decltype(&wordfree)> free_guard(&exp, wordfree);
276
 
        result = exp.we_wordv[0];
277
 
    }
278
 
    else
279
 
    {
280
 
        throw unity::InvalidArgumentException("Invalid scope runner executable for scope: " + id);
281
 
    }
282
 
 
283
 
    return result;
284
 
}
285
 
 
286
262
// For each scope, open the config file for the scope, create the metadata info from the config,
287
263
// and add an entry to the RegistryObject.
288
264
// If the scope uses settings, also parse the settings file and add the settings to the metadata.
435
411
 
436
412
    try
437
413
    {
438
 
        auto custom_exec = sc.scope_runner();
439
 
        filesystem::path program(get_first_component( scope.first, custom_exec));
440
 
        if (program.is_relative())
441
 
        {
442
 
            // First look inside the arch-specific directory
443
 
            if (filesystem::exists(scope_dir / DEB_HOST_MULTIARCH / program))
444
 
            {
445
 
                // Join the full command, not just the program path
446
 
                exec_data.custom_exec = (scope_dir / DEB_HOST_MULTIARCH / custom_exec).native();
447
 
            }
448
 
            // Next try in the non arch-aware directory
449
 
            else if (filesystem::exists(scope_dir / program))
450
 
            {
451
 
                // Join the full command, not just the program path
452
 
                exec_data.custom_exec = (scope_dir / custom_exec).native();
453
 
            }
454
 
            else
455
 
            {
456
 
                throw unity::InvalidArgumentException(
457
 
                        "Nonexistent scope runner '" + custom_exec
458
 
                                + "' executable for scope: " + scope.first);
459
 
            }
460
 
        }
461
 
        else
462
 
        {
463
 
            exec_data.custom_exec = custom_exec;
464
 
        }
 
414
        exec_data.custom_exec = convert_exec_rel_to_abs(scope.first, scope_dir, sc.scope_runner());
465
415
    }
466
416
    catch (NotFoundException const&)
467
417
    {