-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from Deltares/merge_cli
- Loading branch information
Showing
46 changed files
with
2,217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM julia:1.9.2 | ||
LABEL maintainer="Maarten Pronk <maarten.pronk@deltares.nl>" | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
g++ gcc \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ADD . /app | ||
WORKDIR /app/build/create_binaries/ | ||
RUN julia --project -e "using Pkg; Pkg.instantiate()" | ||
RUN julia --project create_app.jl | ||
|
||
ENTRYPOINT [ "/app/build/create_binaries/wflow_bundle/bin/wflow_cli" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Build overview | ||
|
||
## Directory tree | ||
- `create_binaries`: folder containing code to compile the Wflow code | ||
- `create_binaries/create_app.jl`: run PackageCompiler | ||
- `create_binaries/precompile.jl`: run models to compile code, making wflow_cli startup faster | ||
- `create_binaries/Project.toml`: project used to build wflow_cli | ||
- `wflow_cli`: folder containing the code for the wflow_cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[deps] | ||
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" | ||
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" | ||
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" | ||
|
||
[compat] | ||
PackageCompiler = "2" | ||
julia = "1.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Create Binaries | ||
|
||
|
||
Build the app with the following line. The environment variable `WFLOW_REV` can be set to build | ||
the binaries for a specific git revision. | ||
|
||
``` | ||
julia --project create_app.jl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Add the following metadata files to the newly created build: | ||
- Build.toml | ||
- Project.toml | ||
- Manifest.toml | ||
- README.md | ||
- LICENSE | ||
""" | ||
function add_metadata(project_dir, license_file, output_dir, git_repo) | ||
# save some environment variables in a Build.toml file for debugging purposes | ||
vars = ["BUILD_NUMBER", "BUILD_VCS_NUMBER"] | ||
dict = Dict(var => ENV[var] for var in vars if haskey(ENV, var)) | ||
open(normpath(output_dir, "share/julia/Build.toml"), "w") do io | ||
TOML.print(io, dict) | ||
end | ||
|
||
# a stripped Project.toml is already added in the same location by PackageCompiler | ||
# however it is better to copy the original, since it includes the version and compat | ||
cp( | ||
normpath(project_dir, "Project.toml"), | ||
normpath(output_dir, "share/julia/Project.toml"); | ||
force=true | ||
) | ||
# the Manifest.toml always gives the exact version of Wflow that was built | ||
cp( | ||
normpath(project_dir, "Manifest.toml"), | ||
normpath(output_dir, "share/julia/Manifest.toml"); | ||
force=true | ||
) | ||
|
||
# put the LICENSE in the top level directory | ||
cp(license_file, normpath(output_dir, "LICENSE"); force=true) | ||
cp(normpath(project_dir, "README.md"), normpath(output_dir, "README.md"); force=true) | ||
open(normpath(output_dir, "README.md"), "a") do io | ||
# since the exact Wflow version may be hard to find in the Manifest.toml file | ||
# we can also extract that information, and add it to the README.md | ||
manifest = TOML.parsefile(normpath(project_dir, "Manifest.toml")) | ||
if !haskey(manifest, "manifest_format") | ||
error("Manifest.toml is in the old format, run Pkg.upgrade_manifest()") | ||
end | ||
julia_version = manifest["julia_version"] | ||
wflow_entry = only(manifest["deps"]["Wflow"]) | ||
tree = wflow_entry["git-tree-sha1"] | ||
version = wflow_entry["version"] | ||
repo = GitRepo(git_repo) | ||
branch = LibGit2.head(repo) | ||
commit = LibGit2.peel(LibGit2.GitCommit, branch) | ||
short_name = LibGit2.shortname(branch) | ||
short_commit = string(LibGit2.GitShortHash(LibGit2.GitHash(commit), 10)) | ||
url = "/~https://github.com/Deltares/Wflow.jl/tree" | ||
version_info = """ | ||
## Version | ||
This build uses the Wflow.jl version mentioned below. | ||
```toml | ||
version = "$version" | ||
git-tree-sha1 = "$tree" | ||
commit = "$url/$short_commit" | ||
branch = "$url/$short_name" | ||
julia_version = "$julia_version" | ||
```""" | ||
println(io, version_info) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using PackageCompiler | ||
using TOML | ||
using LibGit2 | ||
using Pkg | ||
|
||
# change directory to this script's location | ||
cd(@__DIR__) | ||
|
||
project_dir = "../wflow_cli" | ||
license_file = "../../LICENSE" | ||
output_dir = "wflow_bundle" | ||
git_repo = "../.." | ||
|
||
create_app( | ||
project_dir, | ||
output_dir; | ||
# map from binary name to julia function name | ||
executables=["wflow_cli" => "julia_main"], | ||
precompile_execution_file="precompile.jl", | ||
filter_stdlibs=false, | ||
force=true | ||
) | ||
|
||
include("add_metadata.jl") | ||
add_metadata(project_dir, license_file, output_dir, git_repo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# this script is run during app creation to precompile the code executed in this script | ||
# that way the app will have less latency | ||
|
||
using Wflow | ||
using Downloads | ||
|
||
# this assumes that the Wflow tests have already been run, so the data has been downloaded | ||
testdir = abspath(dirname(pathof(Wflow)), "..", "test") | ||
|
||
# ensure test data is present | ||
# this code is copied from runtests.jl, and is a temporary solution to get the data in place | ||
datadir = joinpath(testdir, "data") | ||
inputdir = joinpath(datadir, "input") | ||
isdir(inputdir) || mkpath(inputdir) | ||
|
||
"Download a test data file if it does not already exist" | ||
function testdata(version, source_filename, target_filename) | ||
target_path = joinpath(inputdir, target_filename) | ||
base_url = "/~https://github.com/visr/wflow-artifacts/releases/download" | ||
url = string(base_url, '/', string('v', version), '/', source_filename) | ||
isfile(target_path) || Downloads.download(url, target_path) | ||
return target_path | ||
end | ||
|
||
staticmaps_rhine_path = testdata(v"0.1", "staticmaps.nc", "staticmaps-rhine.nc") | ||
staticmaps_moselle_path = | ||
testdata(v"0.2.8", "staticmaps-moselle.nc", "staticmaps-moselle.nc") | ||
staticmaps_lahn_path = testdata(v"0.2.1", "staticmaps-lahn.nc", "staticmaps-lahn.nc") | ||
staticmaps_meuse_path = | ||
testdata(v"0.2.8", "staticmaps_flex_meuse.nc", "staticmaps_flex_meuse.nc") | ||
forcing_moselle_path = testdata(v"0.2.6", "forcing-moselle.nc", "forcing-moselle.nc") | ||
forcing_lahn_path = testdata(v"0.2", "forcing-lahn.nc", "forcing-lahn.nc") | ||
forcing_moselle_sed_path = | ||
testdata(v"0.2.3", "forcing-moselle-sed.nc", "forcing-moselle-sed.nc") | ||
staticmaps_moselle_sed_path = | ||
testdata(v"0.2.3", "staticmaps-moselle-sed.nc", "staticmaps-moselle-sed.nc") | ||
instates_moselle_sed_path = | ||
testdata(v"0.2", "instates-moselle-sed.nc", "instates-moselle-sed.nc") | ||
instates_moselle_path = testdata(v"0.2.6", "instates-moselle.nc", "instates-moselle.nc") | ||
forcing_sbm_gw_path = testdata( | ||
v"0.2.1", | ||
"forcing-sbm-groundwater-part1.nc", | ||
"forcing-sbm-groundwater-part1.nc", | ||
) | ||
forcing_sbm_gw_path = testdata( | ||
v"0.2.1", | ||
"forcing-sbm-groundwater-part2.nc", | ||
"forcing-sbm-groundwater-part2.nc", | ||
) | ||
forcing_meuse_path = testdata(v"0.2.8", "forcing_meuse.nc", "forcing_meuse.nc") | ||
staticmaps_sbm_gw_path = | ||
testdata(v"0.2.2", "staticmaps-sbm-groundwater.nc", "staticmaps-sbm-groundwater.nc") | ||
lake_sh_1_path = testdata(v"0.2.1", "lake_sh_1.csv", "lake_sh_1.csv") | ||
lake_sh_2_path = testdata(v"0.2.1", "lake_sh_2.csv", "lake_sh_2.csv") | ||
lake_hq_2_path = testdata(v"0.2.1", "lake_hq_2.csv", "lake_hq_2.csv") | ||
|
||
Wflow.run(joinpath(testdir, "sbm_config.toml")) | ||
Wflow.run(joinpath(testdir, "sbm_gwf_config.toml")) | ||
Wflow.run(joinpath(testdir, "hbv_config.toml")) | ||
Wflow.run(joinpath(testdir, "sediment_config.toml")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Deltares and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name = "wflow_cli" | ||
uuid = "a79039df-c2cc-429a-a63c-52bf37dce6b3" | ||
authors = ["Deltares"] | ||
version = "0.1" | ||
|
||
[deps] | ||
Wflow = "d48b7d99-76e7-47ae-b1d5-ff0c1cf9a818" | ||
|
||
[compat] | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# wflow_cli | ||
|
||
This is a [Julia](https://julialang.org/) project that uses the | ||
[Wflow.jl](/~https://github.com/Deltares/Wflow.jl) Julia package, puts a simple command line | ||
interface (cli) on top, and packages this into a standalone application using | ||
[PackageCompiler.jl](/~https://github.com/JuliaLang/PackageCompiler.jl). | ||
|
||
This enables using Wflow.jl without having to install Julia, and thus makes it more | ||
convenient to use in certain settings where installation must be simple and no interactive | ||
Julia session is needed. | ||
|
||
If you have installed Julia and Wflow.jl, a simulation can also be started from the command | ||
line as follows: | ||
|
||
``` | ||
julia -e 'using Wflow; Wflow.run()' path/to/config.toml | ||
``` | ||
|
||
With a wflow_cli build this becomes: | ||
|
||
``` | ||
wflow_cli path/to/config.toml | ||
``` | ||
|
||
## Directory tree | ||
- `Setup/`: used to create MSI installers for Windows | ||
- `src/`: source code of the wflow_cli app, that wraps `Wflow.run` function | ||
- `Project.toml`: Project for the wflow_cli app that needs to be built |
108 changes: 108 additions & 0 deletions
108
build/wflow_cli/Setup/Installer/Application.Setup.wixproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x64</Platform> | ||
<ProductVersion>3.10</ProductVersion> | ||
<ProjectGuid>{39da8083-e405-42e6-850c-d25685e91f81}</ProjectGuid> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ReleaseVersion>0.7.1</ReleaseVersion> | ||
<OutputType>Package</OutputType> | ||
<DefineSolutionProperties>false</DefineSolutionProperties> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> | ||
<OutputName>wflow Setup %28$(ReleaseVersion)%29</OutputName> | ||
<OutputPath>bin\$(Configuration)\</OutputPath> | ||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> | ||
<DefineConstants>$(DefineConstants);ReleaseVersion=$(ReleaseVersion);ApplicationBinFolder=..\..\create_app\wflow_bundle</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> | ||
<OutputName>wflow Setup %28$(ReleaseVersion)%29</OutputName> | ||
<OutputPath>bin\$(Configuration)\</OutputPath> | ||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> | ||
<DefineConstants>$(DefineConstants);ReleaseVersion=$(ReleaseVersion);ApplicationBinFolder=..\..\create_app\wflow_bundle</DefineConstants> | ||
<SuppressAllWarnings>True</SuppressAllWarnings> | ||
<Pedantic>False</Pedantic> | ||
<Cultures>en-US</Cultures> | ||
<SuppressPdbOutput>True</SuppressPdbOutput> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<OutputName>wflow Setup %28$(ReleaseVersion)%29</OutputName> | ||
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath> | ||
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath> | ||
<DefineConstants>$(DefineConstants);ReleaseVersion=$(ReleaseVersion);ApplicationBinFolder=..\..\create_app\wflow_bundle</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<OutputName>wflow Setup %28$(ReleaseVersion)%29</OutputName> | ||
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath> | ||
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath> | ||
<DefineConstants>$(DefineConstants);ReleaseVersion=$(ReleaseVersion);ApplicationBinFolder=..\..\create_app\wflow_bundle</DefineConstants> | ||
<SuppressAllWarnings>True</SuppressAllWarnings> | ||
<Pedantic>False</Pedantic> | ||
<Cultures>en-US</Cultures> | ||
<SuppressPdbOutput>True</SuppressPdbOutput> | ||
</PropertyGroup> | ||
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " /> | ||
<ItemGroup> | ||
<Compile Include="ApplicationPayload.wxs" /> | ||
<Compile Include="Installer UI\BrowseDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\CancelDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\DiskCostDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\ErrorDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\ExitDialogDeltares.wxs" /> | ||
<Compile Include="Installer UI\FatalErrorDeltares.wxs" /> | ||
<Compile Include="Installer UI\FilesInUseDeltares.wxs" /> | ||
<Compile Include="Installer UI\InstallDirDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\InvalidDirDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\LicenseAgreementDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\MaintenanceTypeDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\MaintenanceWelcomeDlg.wxs" /> | ||
<Compile Include="Installer UI\MsiRMFilesInUseDeltares.wxs" /> | ||
<Compile Include="Installer UI\OutOfDiskDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\OutOfRbDiskDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\PrepareDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\ProgressDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\ResumeDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\UserExitDeltares.wxs" /> | ||
<Compile Include="Installer UI\VerifyReadyDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\WelcomeDlgDeltares.wxs" /> | ||
<Compile Include="Installer UI\wixUI_Deltares.wxs" /> | ||
<Compile Include="Product.wxs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="ExcludeFilesFromPayload.xslt" /> | ||
<Content Include="program.ico" /> | ||
<Content Include="Variables.wxi" /> | ||
<Content Include="wflow_installer-banner.bmp" /> | ||
<Content Include="wflow_installer-dialog.bmp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Installer UI\WixUIVariables_en-US.wxl" /> | ||
<EmbeddedResource Include="Localization_en-US.wxl" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Folder Include="Installer UI\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<WixExtension Include="WixNetFxExtension"> | ||
<HintPath>$(WixExtDir)\WixNetFxExtension.dll</HintPath> | ||
<Name>WixNetFxExtension</Name> | ||
</WixExtension> | ||
<WixExtension Include="WixUIExtension"> | ||
<HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath> | ||
<Name>WixUIExtension</Name> | ||
</WixExtension> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<PreBuildEvent>"$(WIX)bin\heat.exe" dir "$(ProjectDir)..\..\create_app\wflow_bundle" -cg ApplicationComponents -gg -dr INSTALLDIR -var var.ApplicationBinFolder -sfrag -sreg -srd -o "$(ProjectDir)ApplicationPayload.wxs" -t "$(ProjectDir)ExcludeFilesFromPayload.xslt"</PreBuildEvent> | ||
</PropertyGroup> | ||
<!-- | ||
To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Wix.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.