function removeBuildInfoRootFolders(tokens)
%REMOVEBUILDINFOROOTFOLDERS removes BuildInfo root folders.
%
% REMOVEBUILDINFOROOTFOLDERS(TOKEN) removes the BuildInfo root folder
% associated with the token.
%
% REMOVEBUILDINFOROOTFOLDERS({TOKEN1,TOKEN2,...TOKENn}) removes the BuildInfo
% root folders associated with each token.
%
% REMOVEBUILDINFOROOTFOLDERS(ROOTFOLDERS) removes the BuildInfo root folders
% ROOTFOLDERS, an array of objects returned by getBuildInfoRootFolders.
%
% REMOVEBUILDINFOROOTFOLDERS() removes all BuildInfo root folders from the build
% information.
%
% Example:
% setBuildInfoRootFolders('$(MY_TOKEN)','/path')
% removeBuildInfoRootFolders('$(MY_TOKEN)')
%
% See also SETBUILDINFOROOTFOLDERS, GETBUILDINFOROOTFOLDERS

% Copyright 2021-2022 The MathWorks, Inc.
arguments
tokens (1,:) = {}
end

if isempty(tokens)
% remove all the entries
rootFolders = coder.make.RootFolder.empty;
else
if isa(tokens, 'coder.make.RootFolder')
tokens = {tokens.Token};
else
tokens = convertStringsToChars(tokens);
if ischar(tokens)
tokens = {tokens};
end
mustBeText(tokens);
end
if ispref('BuildInfo', 'BuildInfoRootFolders')
rootFolders = getpref('BuildInfo', 'BuildInfoRootFolders');
idx = ismember({rootFolders.Token}, tokens);
rootFolders = rootFolders(~idx);
end
end
setpref('BuildInfo', 'BuildInfoRootFolders', rootFolders);
end