function toolchainInfo = getToolchainInfoFromRegistry(toolchainName)
%GETTOOLCHAININFOFROMREGISTRY(toolchainName) Get a copy of the
% coder.make.ToolchainInfo object or target.Toolchain associated with a 
% certain toolchain.

% Copyright 2016-2022 The MathWorks, Inc.

% Get the toolchain by name, but if the toolchain cannot be identified by 
% name, also check toolchainName matches any aliases registered in the
% toolchain registry.

adapter = coder.make.internal.getToolchainInfoCopyFromRegistry(toolchainName);

if coder.make.internal.featureOn('UseAdapterForClassicToolchain')
    unwrapped = adapter.getWrappedObject;
else
    unwrapped = adapter;
end

if isa(unwrapped, 'target.internal.Data')
    % For Target Framework toolchains, re-wrap the target.internal.* object
    % with the target.* wrapper.
    toolchainInfo = targetframework.internal.user.commandline.matlab.Helpers.wrapValues(unwrapped);
else
    % Otherwise return the raw coder.make.ToolchainInfo object.
    toolchainInfo = unwrapped;
end

