Skip to content

Commit

Permalink
nuget swhere (#207)
Browse files Browse the repository at this point in the history
* Parse nuget packages

* Generate Nuget SDK

* Move local user config load into generate
  • Loading branch information
mwasplund authored Jul 6, 2023
1 parent 8b16b6f commit cec699e
Show file tree
Hide file tree
Showing 22 changed files with 655 additions and 141 deletions.
73 changes: 11 additions & 62 deletions Source/Client/Core/Source/Build/BuildEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,16 @@ namespace Soup::Core
{
auto startTime = std::chrono::high_resolution_clock::now();

// Load the local user config and any sdk content
auto sdkParameters = ValueList();
auto sdkReadAccess = std::vector<Path>();
LoadLocalUserConfig(sdkParameters, sdkReadAccess);

auto endTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(endTime - startTime);

// std::cout << "LoadLocalUserConfig: " << std::to_string(duration.count()) << " seconds." << std::endl;

startTime = std::chrono::high_resolution_clock::now();
// Load user config state
auto userDataPath = GetSoupUserDataPath();

// Load the system specific state
auto hostBuildGlobalParameters = ValueTable();
auto systemReadAccess = std::vector<Path>();
LoadHostSystemState(hostBuildGlobalParameters, systemReadAccess);

endTime = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::duration<double>>(endTime - startTime);
auto endTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(endTime - startTime);

// std::cout << "LoadSystemState: " << std::to_string(duration.count()) << " seconds." << std::endl;

Expand All @@ -119,6 +110,7 @@ namespace Soup::Core
builtInPackages,
arguments,
hostBuildGlobalParameters,
userDataPath,
recipeCache);
auto packageProvider = loadEngine.Load();

Expand All @@ -144,8 +136,7 @@ namespace Soup::Core
// for each individual package
auto buildRunner = BuildRunner(
arguments,
sdkParameters,
sdkReadAccess,
userDataPath,
systemReadAccess,
recipeCache,
packageProvider,
Expand All @@ -161,61 +152,19 @@ namespace Soup::Core
}

private:
/// <summary>
/// Load Local User Config and process any known state
/// </summary>
static void LoadLocalUserConfig(
ValueList& sdkParameters,
std::vector<Path>& sdkReadAccess)
static Path GetSoupUserDataPath()
{
// Load the local user config
auto localUserConfigPath = System::IFileSystem::Current().GetUserProfileDirectory() +
BuildConstants::SoupLocalStoreDirectory() +
BuildConstants::LocalUserConfigFileName();
LocalUserConfig localUserConfig = {};
if (!LocalUserConfigExtensions::TryLoadLocalUserConfigFromFile(localUserConfigPath, localUserConfig))
{
Log::Warning("Local User Config invalid");
}

// Process the SDKs
if (localUserConfig.HasSDKs())
{
Log::Info("Checking SDKs for read access");
auto sdks = localUserConfig.GetSDKs();
for (auto& sdk : sdks)
{
auto sdkName = sdk.GetName();
Log::Info("Found SDK: " + sdkName);
if (sdk.HasSourceDirectories())
{
for (auto& sourceDirectory : sdk.GetSourceDirectories())
{
Log::Info(" Read Access: " + sourceDirectory.ToString());
sdkReadAccess.push_back(sourceDirectory);
}
}

auto sdkParameter = ValueTable();
sdkParameter.emplace("Name", Value(sdkName));
if (sdk.HasProperties())
{
sdkParameter.emplace(
"Properties",
RecipeBuildStateConverter::ConvertToBuildState(sdk.GetProperties()));
}

sdkParameters.push_back(std::move(sdkParameter));
}
}
auto result = System::IFileSystem::Current().GetUserProfileDirectory() +
BuildConstants::SoupLocalStoreDirectory();
return result;
}

static void LoadHostSystemState(
ValueTable& hostBuildGlobalParameters,
std::vector<Path>& systemReadAccess)
{
auto system = std::string("Windows");
hostBuildGlobalParameters.emplace("System", Value(std::string(system)));
hostBuildGlobalParameters.emplace("System", Value(system));

// Allow read access from system directories
systemReadAccess.push_back(
Expand Down
14 changes: 5 additions & 9 deletions Source/Client/Core/Source/Build/BuildLoadEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Soup::Core
const RecipeBuildArguments& _arguments;

// System Parameters
Path _userDataPath;
const ValueTable& _hostBuildGlobalParameters;

// Shared Runtime State
Expand All @@ -72,11 +73,13 @@ namespace Soup::Core
const std::map<std::string, std::map<std::string, SemanticVersion>>& builtInPackageLookup,
const RecipeBuildArguments& arguments,
const ValueTable& hostBuildGlobalParameters,
Path userDataPath,
RecipeCache& recipeCache) :
_knownLanguageLookup(knownLanguageLookup),
_builtInPackageLookup(builtInPackageLookup),
_arguments(arguments),
_hostBuildGlobalParameters(hostBuildGlobalParameters),
_userDataPath(std::move(userDataPath)),
_recipeCache(recipeCache),
_packageGraphLookup(),
_packageLookup(),
Expand Down Expand Up @@ -228,7 +231,7 @@ namespace Soup::Core
else
{
// Build the global store location path
auto packageStore = GetSoupUserDataPath() + Path("packages/");
auto packageStore = _userDataPath + Path("packages/");
auto& languageSafeName = GetLanguageSafeName(activeReference.GetLanguage());
auto activeVersionString = activeReference.GetVersion().ToString();
packagePath = packageStore +
Expand Down Expand Up @@ -271,7 +274,7 @@ namespace Soup::Core
else
{
// Build the global store location path
auto packageStore = GetSoupUserDataPath() + Path("locks/");
auto packageStore = _userDataPath + Path("locks/");
auto& languageSafeName = GetLanguageSafeName(activeReference.GetLanguage());
packagePath = packageStore +
Path(languageSafeName) +
Expand Down Expand Up @@ -934,12 +937,5 @@ namespace Soup::Core

return knownLanguageResult->second.LanguageSafeName;
}

Path GetSoupUserDataPath() const
{
auto result = System::IFileSystem::Current().GetUserProfileDirectory() +
BuildConstants::SoupLocalStoreDirectory();
return result;
}
};
}
33 changes: 10 additions & 23 deletions Source/Client/Core/Source/Build/BuildRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ namespace Soup::Core
// Root arguments
const RecipeBuildArguments& _arguments;

// SDK Parameters
const ValueList& _sdkParameters;
const std::vector<Path>& _sdkReadAccess;

// System Parameters
Path _userDataPath;
const std::vector<Path>& _systemReadAccess;

// Shared Runtime
Expand All @@ -60,17 +57,15 @@ namespace Soup::Core
/// </summary>
BuildRunner(
const RecipeBuildArguments& arguments,
const ValueList& sdkParameters,
const std::vector<Path>& sdkReadAccess,
Path userDataPath,
const std::vector<Path>& systemReadAccess,
RecipeCache& recipeCache,
PackageProvider& packageProvider,
IEvaluateEngine& evaluateEngine,
FileSystemState& fileSystemState,
RecipeBuildLocationManager& locationManager) :
_arguments(arguments),
_sdkParameters(sdkParameters),
_sdkReadAccess(sdkReadAccess),
_userDataPath(std::move(userDataPath)),
_systemReadAccess(systemReadAccess),
_recipeCache(recipeCache),
_packageProvider(packageProvider),
Expand Down Expand Up @@ -358,9 +353,6 @@ namespace Soup::Core
// Generate the dependencies input state
globalState.emplace("Dependencies", GenerateParametersDependenciesValueTable(packageInfo));

// Pass along the sdks
globalState.emplace("SDKs", _sdkParameters);

inputTable.emplace("GlobalState", std::move(globalState));

// Build up the input state for the generate call
Expand All @@ -374,14 +366,10 @@ namespace Soup::Core
for (auto& [key, value] : packageAccessSet.GenerateCurrentMacros)
generateMacros.emplace(key, value);

// Make subgraph macros are unique
// Make subgraph macros unique
for (auto& [key, value] : packageAccessSet.GenerateSubGraphMacros)
generateSubGraphMacros.emplace(key, value);

// Allow read access for all sdk directories
for (auto& value : _sdkReadAccess)
evaluateAllowedReadAccess.push_back(value.ToString());

// Pass along the read access set
for (auto& value : packageAccessSet.EvaluateCurrentReadDirectories)
evaluateAllowedReadAccess.push_back(value.ToString());
Expand All @@ -399,6 +387,7 @@ namespace Soup::Core
evaluateMacros.emplace(key, value);

inputTable.emplace("PackageRoot", packageInfo.PackageRoot.ToString());
inputTable.emplace("UserDataPath", _userDataPath.ToString());
inputTable.emplace("GenerateMacros", std::move(generateMacros));
inputTable.emplace("GenerateSubGraphMacros", std::move(generateSubGraphMacros));
inputTable.emplace("EvaluateReadAccess", std::move(evaluateAllowedReadAccess));
Expand Down Expand Up @@ -454,9 +443,13 @@ namespace Soup::Core
auto generateAllowedReadAccess = std::vector<Path>();
auto generateAllowedWriteAccess = std::vector<Path>();

// Allow read access to the generate executable folder, Windows and the DotNet install
// Allow read access to the generate executable folder
generateAllowedReadAccess.push_back(generateFolder);

// Allow read access to the local user config
auto localUserConfigPath = _userDataPath + BuildConstants::LocalUserConfigFileName();
generateAllowedReadAccess.push_back(std::move(localUserConfigPath));

// TODO: Windows specific
generateAllowedReadAccess.push_back(Path("C:/Windows/"));
generateAllowedReadAccess.push_back(Path("C:/Program Files/dotnet/"));
Expand Down Expand Up @@ -553,12 +546,6 @@ namespace Soup::Core
allowedReadAccess.push_back(temporaryDirectory);
allowedWriteAccess.push_back(temporaryDirectory);

// TODO: REMOVE - Allow read access from SDKs
std::copy(
_sdkReadAccess.begin(),
_sdkReadAccess.end(),
std::back_inserter(allowedReadAccess));

// Ensure the temporary directories exists
if (!System::IFileSystem::Current().Exists(temporaryDirectory))
{
Expand Down
Loading

0 comments on commit cec699e

Please sign in to comment.