Skip to content

Commit

Permalink
Integrate Initial Package Manager Publish/Install/Build (#30)
Browse files Browse the repository at this point in the history
* Add new cpp http lib dependency and hook in a stub for an Opal Network Manager interface

* Start conversion for c# soup api to c++

* Hook up simple api tests

* Hook in json parse for package model

* Hook up basic package manager install method and tests

* Most of the way through install package manager

* Hook up basic install command

* Add staging cleanup on error

* Add another test

* Add 7zip

* Start a developer setup doc

* Start to hook up LZMA compression and the publish command

* Hook up basic package using 7z

* Hook up publish command

* Hook up basic install command support in the package manager

* Hook up file system to allow for easy testing of package manager

* Hook up test for package manager install

* Fix file issue

* Hook up reference builds

* Hook up to live service

* Fix tests

Co-authored-by: Matthew Asplund <[email protected]>
  • Loading branch information
mwasplund and Matthew Asplund authored Mar 15, 2020
1 parent a0a0f78 commit 2d6224e
Show file tree
Hide file tree
Showing 84 changed files with 2,994 additions and 905 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
[submodule "Dependencies/cpptoml"]
path = Dependencies/cpptoml
url = https://github.com/mwasplund/cpptoml.git
[submodule "Dependencies/cpp-httplib"]
path = Dependencies/cpp-httplib
url = https://github.com/mwasplund/cpp-httplib.git
[submodule "Dependencies/LzmaSdk"]
path = Dependencies/LzmaSdk
url = https://github.com/mwasplund/LzmaSdk.git
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
"cstdarg": "cpp",
"*.rh": "cpp",
"concepts": "cpp",
"clocale": "cpp"
"clocale": "cpp",
"csignal": "cpp",
"resumable": "cpp",
"future": "cpp",
"random": "cpp",
"regex": "cpp",
"string_view": "cpp",
"complex": "cpp"
}
}
1 change: 1 addition & 0 deletions Dependencies/LzmaSdk
Submodule LzmaSdk added at 8a7346
1 change: 1 addition & 0 deletions Dependencies/cpp-httplib
Submodule cpp-httplib added at 71a451
23 changes: 23 additions & 0 deletions Docs/DeveloperSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Developer Setup

## Requirements
* Windows 10
* Build Tools
* [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) with "Desktop development with c++" workload.
* OR
* [Build Tools For Visual Studio 2019](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019) with "c++ build tools" workload.
* [Latest Release](https://github.com/mwasplund/Soup/releases)

## Setup
Clone the repository and all submodules recursively.

```
git clone --recursive https://github.com/mwasplund/Soup.git
```

## Build the client

```
cd Source/Client
soup build
```
2 changes: 1 addition & 1 deletion Managed/Client/Commands/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private async Task<Recipe> UnpackArchiveAsync(string tempPath, Stream packageFil
}

/// <summary>
/// Recusively install all dependencies and trasient dependecies
/// Recursively install all dependencies and transitive dependencies
/// </summary>
private async Task InstallRecursiveDependencies(string tempPath, Recipe recipe)
{
Expand Down
12 changes: 6 additions & 6 deletions Source/Client/Commands/BuildCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ namespace Soup::Client
workingDirectory = System::IFileSystem::Current().GetCurrentDirectory2() + workingDirectory;
}
}

auto recipePath =
workingDirectory +
Path(Constants::RecipeFileName);
Build::Recipe recipe = {};
if (!Build::RecipeExtensions::TryLoadFromFile(recipePath, recipe))
Recipe recipe = {};
if (!RecipeExtensions::TryLoadFromFile(recipePath, recipe))
{
Log::Error("Could not load the recipe file.");
return;
Expand Down Expand Up @@ -112,14 +112,14 @@ namespace Soup::Client
// }

// arguments.PlatformLibraries.push_back(Path("kernel32.lib"));
// arguments.PlatformLibraries.push_back(Path("user32.lib"));
arguments.PlatformLibraries.push_back("user32.lib");
// arguments.PlatformLibraries.push_back(Path("gdi32.lib"));
// arguments.PlatformLibraries.push_back(Path("winspool.lib"));
// arguments.PlatformLibraries.push_back(Path("comdlg32.lib"));
// arguments.PlatformLibraries.push_back(Path("advapi32.lib"));
arguments.PlatformLibraries.push_back("advapi32.lib");
// arguments.PlatformLibraries.push_back(Path("shell32.lib"));
// arguments.PlatformLibraries.push_back(Path("ole32.lib"));
// arguments.PlatformLibraries.push_back(Path("oleaut32.lib"));
arguments.PlatformLibraries.push_back("oleaut32.lib");
// arguments.PlatformLibraries.push_back(Path("uuid.lib"));
// arguments.PlatformLibraries.push_back(Path("odbc32.lib"));
// arguments.PlatformLibraries.push_back(Path("odbccp32.lib"));
Expand Down
11 changes: 6 additions & 5 deletions Source/Client/Commands/InitializeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Soup::Client
workingDirectory +
Path(Constants::RecipeFileName);

auto recipe = Build::Recipe(
auto recipe = Recipe(
workingDirectory.GetFileName(),
SemanticVersion(1, 0, 0));

Expand All @@ -48,7 +48,7 @@ namespace Soup::Client
UpdateDefaultValues(recipe);

// Save the state of the recipe if it has changed
Build::RecipeExtensions::SaveToFile(recipePath, recipe);
RecipeExtensions::SaveToFile(recipePath, recipe);

// Save a simple main method
auto mainFileContent =
Expand All @@ -60,12 +60,13 @@ int main()
})";

auto mainFilePath = Path("Main.cpp");
auto mainFile = System::IFileSystem::Current().OpenWrite(mainFilePath);
*mainFile << mainFileContent;
auto mainFile = System::IFileSystem::Current().OpenWrite(mainFilePath, false);
mainFile->GetOutStream() << mainFileContent;
mainFile->Close();
}

private:
void UpdateDefaultValues(Build::Recipe& recipe)
void UpdateDefaultValues(Recipe& recipe)
{
Log::HighPriority("Name: (" + std::string(recipe.GetName()) + ")");
auto newName = std::string();
Expand Down
171 changes: 3 additions & 168 deletions Source/Client/Commands/InstallCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ namespace Soup::Client
/// </summary>
InstallCommand(InstallOptions options) :
_options(std::move(options))
// LocalUserConfig config,
// ISoupApi soupApi)
{
// _config = config;
// _soupApi = soupApi;
}

/// <summary>
Expand All @@ -32,173 +28,12 @@ namespace Soup::Client
virtual void Run() override final
{
Log::Diag("InstallCommand::Run");
// var workingDirectory = @"./";
// Recipe recipe = null;
// try
// {
// recipe = await RecipeManager.LoadFromFileAsync(workingDirectory);
// }
// catch (FileNotFoundException)
// {
// Log.Error("The recipe file is required to install.");
// return;
// }

// var stagingPath = PackageManager.EnsureStagingDirectoryExists(_config.PackageStore);

// // Ensure that the staging directory exists
// var tempStagingPath = Path.Combine(stagingPath, "temp");

// var package = options.Package;
// if (string.IsNullOrEmpty(package))
// {
// Log.Info("Install All");

// await InstallRecursiveDependencies(tempStagingPath, recipe);
// }
// else if (!Path.HasExtension(package))
// {
// Log.Info($"Install Package: {package}");

// // Check if the package is already installed
// if (recipe.Dependencies.Any(dependency => dependency.Name == package))
// {
// Log.Warning("Packge already installed.");
// return;
// }

// // Get the latest version
// var latestVersion = await GetLatestAsync(package);

// // Download the archive
// using (var archiveStream = await DownloadPackageAsync(package, latestVersion))
// {
// // Install the package
// var installedRecipe = await InstallPackageAsync(tempStagingPath, archiveStream);
// var installedPackageRef = new PackageReference(installedRecipe.Name, installedRecipe.Version);

// // Register the package in the recipe
// recipe.Dependencies.Add(installedPackageRef);
// }
// }
// else if (Path.GetExtension(package) == Constants.ArchiveFileExtension)
// {
// Log.Info($"Installing Local Package: {package}");

// if (!File.Exists(package))
// {
// throw ArgumentException("The specified file does not exist.");
// }

// // Install the package
// using (var archiveStream = File.OpenRead(package))
// {
// var installedRecipe = await InstallPackageAsync(tempStagingPath, archiveStream);
// var installedPackageRef = new PackageReference(installedRecipe.Name, installedRecipe.Version);

// // Register the package in the recipe if it does not exist
// if (!recipe.Dependencies.Any(dependency => dependency == installedPackageRef))
// {
// recipe.Dependencies.Add(installedPackageRef);
// }
// }
// }
// else
// {
// Log.Error("Unknown install source type.");
// Directory.Delete(tempStagingPath, true);
// return;
// }

// // Cleanup the working directory
// if (Directory.Exists(tempStagingPath))
// {
// Directory.Delete(tempStagingPath, true);
// }

// // Save the state of the recipe if it has changed
// if (recipe.IsDirty)
// {
// await RecipeManager.SaveToFileAsync(recipe);
// }

auto packageStore = Path("C:/users/mwasp/.soup/packages/");
PackageManager::InstallPackage(_options.Package, packageStore);
}

private:
// SemanticVersion GetLatestAsync(string name)
// {
// var package = await _soupApi.GetPackageAsync(name);
// return package.Latest;
// }

// Stream DownloadPackageAsync(string name, SemanticVersion version)
// {
// var stream = await _soupApi.DownloadPackageAsync(name, version);
// return stream;
// }

// Recipe InstallPackageAsync(string tempPath, Stream packageFile)
// {
// var recipe = await UnpackArchiveAsync(tempPath, packageFile);
// return recipe;
// }

// Recipe UnpackArchiveAsync(string tempPath, Stream packageFile)
// {
// // Unpack the zip file into the package directory
// var tempPackagePath = Path.Combine(tempPath, Constants.StorePackageFolderName);
// Directory.CreateDirectory(tempPackagePath);
// await PackageManager.ExtractAsync(packageFile, tempPackagePath);

// // Load the packages recipe file
// var recipe = await RecipeManager.LoadFromFileAsync(tempPackagePath);
// var packagePath = PackageManager.BuildKitchenPackagePath(_config, recipe);

// // TODO : Perform some verification that the package is valid

// // TODO : Should not hit this when, verify the package exists before download
// // For now delete and recreate it
// if (Directory.Exists(packagePath))
// {
// Directory.Delete(packagePath, true);
// }

// // Ensure the parent directory exists
// var packageParentDirectory = Directory.GetParent(packagePath);
// if (!packageParentDirectory.Exists)
// {
// packageParentDirectory.Create();
// }

// // Move the results out of the staging directory
// Directory.Move(tempPackagePath, packagePath);

// return recipe;
// }

// /// <summary>
// /// Recusively install all dependencies and trasient dependecies
// /// </summary>
// void InstallRecursiveDependencies(string tempPath, Recipe recipe)
// {
// foreach (var dep in recipe.Dependencies)
// {
// Log.Info($"{dep}");

// // Download the archive
// using (var archiveStream = await DownloadPackageAsync(dep.Name, dep.Version))
// {
// // Install the package
// var installedRecipe = await InstallPackageAsync(tempPath, archiveStream);

// // Install dependecies recursively
// await InstallRecursiveDependencies(tempPath, installedRecipe);
// }
// }
// }

private:
InstallOptions _options;
// LocalUserConfig _config;
// ISoupApi _soupApi;
};
}
37 changes: 3 additions & 34 deletions Source/Client/Commands/PublishCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ namespace Soup::Client
/// </summary>
PublishCommand(PublishOptions options) :
_options(std::move(options))
// ISoupIdentity soupIdentity,
// ISoupApi soupApi)
{
// _soupIdentity = soupIdentity;
// _soupApi = soupApi;
}

/// <summary>
Expand All @@ -32,39 +28,12 @@ namespace Soup::Client
virtual void Run() override final
{
Log::Diag("PublishCommand::Run");
// var projectDirectory = Directory.GetCurrentDirectory();
// var recipe = await RecipeManager.LoadFromFileAsync(projectDirectory);
// Log.Info($"Publish Project: {recipe.Name}@{recipe.Version}");

// var result = await _soupIdentity.AuthenticateUserAsync();

// using (var stream = new MemoryStream())
// {
// // Pack the project into a memory stream
// await PackageManager.PackAsync(recipe, projectDirectory, stream);

// // Reset the stream so we can read from it
// stream.Seek(0, SeekOrigin.Begin);

// // Publish the package to the service
// try
// {
// bool created = await _soupApi.PublishPackageAsync(recipe.Name, stream);
// if (!created)
// {
// Log.Warning("The package version already existed! No change was made.");
// }
// }
// catch (HttpRequestException ex)
// {
// Log.Error($"Failed request: {ex.ToString()}");
// }
// }

auto packageStore = Path("C:/users/mwasp/.soup/packages/");
PackageManager::PublishPackage(packageStore);
}

private:
PublishOptions _options;
// ISoupIdentity _soupIdentity;
// ISoupApi _soupApi;
};
}
6 changes: 3 additions & 3 deletions Source/Client/Commands/RunCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace Soup::Client
auto recipePath =
workingDirectory +
Path(Constants::RecipeFileName);
Build::Recipe recipe = {};
if (!Build::RecipeExtensions::TryLoadFromFile(recipePath, recipe))
Recipe recipe = {};
if (!RecipeExtensions::TryLoadFromFile(recipePath, recipe))
{
Log::Error("Could not load the recipe file");
return;
Expand All @@ -53,7 +53,7 @@ namespace Soup::Client
// Ensure the executable exists
auto configuration = "release";
auto compilerName = config.GetRuntimeCompiler();
auto binaryDirectory = Build::RecipeExtensions::GetBinaryDirectory(compilerName, configuration);
auto binaryDirectory = RecipeExtensions::GetBinaryDirectory(compilerName, configuration);
auto executablePath = workingDirectory + binaryDirectory + Path(std::string(recipe.GetName()) + ".exe");
Log::Info(executablePath.ToString());
if (!System::IFileSystem::Current().Exists(executablePath))
Expand Down
Loading

0 comments on commit 2d6224e

Please sign in to comment.