function setCoverageToolPath(toolClass, toolPath, options)
%setCoverageToolPath returns install path for the coverage tool class

% Copyright 2020-2021 The MathWorks, Inc.

arguments
    toolClass (1,:) char
    toolPath (1,:) char
    options.SkipValidate (1,1) logical = false;
end

% Simulink Coverage uses a fixed location
if toolClass=="SlCov.coder.EmbeddedCoder"
    return
end

skipValidate = options.SkipValidate;

toolName = eval([toolClass '.ToolNameForPreferences']);
markerFile = eval([toolClass '.ValidateToolInstallationFile']);

% If a non-empty path is specified then validate it
prefGroup = ['CodeCoverage_' toolName];
prefName = 'Path';
if ~isempty(toolPath)
    if ~skipValidate
        isValid = coder.coverage.validateToolPath(toolPath, markerFile);
        if ~isValid
            DAStudio.error('CoderCoverage:AllTools:toolPathSetInvalid',...
                           toolPath, toolName);
        end
    end
    setpref(prefGroup, prefName, toolPath);
else
    if ispref(prefGroup, prefName)
        rmpref(prefGroup, prefName);
    end
end
