function postLoadUpdate(lBuildInfo, loadFolder)
%POSTLOADUPDATE - this method updates a buildInfo
% after it has been loaded into memory.
% Ideally, it should be run inside a 'load' of a serialized buildInfo.
% This is currently not possible because the hooks available at 'load' time
% do not provide the path from which the structure is being loaded.
% Once the infrastructure of loading allows the above, consider moving this
% function inside the 'load'.

%   Copyright 2019-2020 The MathWorks, Inc.


% TODO(g2194323): test points with both absolute and relative path for loadFolder
if coder.make.internal.isRelativePath(loadFolder)
    loadFolder = fullfile(pwd, loadFolder);
end
loadFolder = RTW.reduceRelativePath(loadFolder);


% Identify the root folder $(START_DIR) based on loadFolder (obtained 
% from the input argument) and relative path to anchor (serialized in 
% buildInfo)
[~, lRelativePathAnchor] = findBuildArg(lBuildInfo, 'RELATIVE_PATH_TO_ANCHOR');
lRootFolder = fullfile(loadFolder, lRelativePathAnchor);
lRootFolder = RTW.reduceRelativePath(lRootFolder);

% Update buildInfo settings
lBuildInfo.Settings.Matlabroot = matlabroot;
lBuildInfo.Settings.LocalAnchorDir = lRootFolder;

% Update ComponentBuildFolder (relative path from the root folder to the
% folder buildInfo was loaded from)
lComponentBuildFolder = loadFolder(length(lRootFolder)+2:end);
if ~isempty(lComponentBuildFolder)
    lBuildInfo.ComponentBuildFolder = lComponentBuildFolder;
end
