Skip to content

Commit

Permalink
Merge pull request #39 from psrenergy/pr/update-compile
Browse files Browse the repository at this point in the history
Update compile and add test
  • Loading branch information
raphasampaio authored Aug 26, 2024
2 parents f6eea2e + 132b9fe commit 7b30e7e
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .github/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: test
on:
push:
branches: [master, develop]
pull_request:
types: [opened, synchronize, reopened]
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test-windows:
name: Test Windows
runs-on: self-hosted
steps:
- name: Initialize instance
run: |
Remove-Item -Path '${{ github.workspace }}\*' -Force -Recurse
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Test
run: |
.\test\test.bat
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ docs/site/
# environment.
Manifest.toml
format/Manifest.toml
revise/Manifest.toml
revise/Manifest.toml

test/Example.jl/compile/build/
test/Example.jl/compile/Example.log
test/Example.jl/compile/build.ok
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PSRContinuousDeployment"
uuid = "f0087d4c-ff99-426e-93c9-09c1a88911f9"
version = "0.7.2"
version = "0.8.0"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
Expand Down
77 changes: 45 additions & 32 deletions src/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function compile(
filter_stdlibs::Bool = true,
include_lazy_artifacts::Bool = true,
include_transitive_dependencies::Bool = true,
skip_version_jl::Bool = false,
kwargs...,
)
target = configuration.target
Expand All @@ -36,39 +37,44 @@ function compile(
Log.info("COMPILE: Creating build directory")
mkdir(build_path)

Log.info("COMPILE: Creating version.jl")
sha1 = read_git_sha1(package_path)
date = read_git_date(package_path)
build_date = Dates.format(Dates.now(Dates.UTC), dateformat"yyyy-mm-dd HH:MM:SS -0000")
write_version_jl(src_path, sha1, date, version, build_date)

free_memory = round(Int, Sys.free_memory() / 2^20)
total_memory = round(Int, Sys.total_memory() / 2^20)
Log.info("COMPILE: memory free $free_memory MB")
Log.info("COMPILE: memory total $total_memory MB")

PackageCompiler.create_app(
package_path,
build_path,
executables = executables,
precompile_execution_file = precompile_path,
incremental = false,
filter_stdlibs = filter_stdlibs,
force = true,
include_lazy_artifacts = include_lazy_artifacts,
include_transitive_dependencies = include_transitive_dependencies,
kwargs...,
)

Log.info("COMPILE: Cleaning version.jl")
clean_version_jl(src_path)

Log.info("COMPILE: Creating $target.ver")
open(joinpath(bin_path, "$target.ver"), "w") do io
writeln(io, sha1)
return nothing
if !skip_version_jl
Log.info("COMPILE: Creating version.jl")
sha1 = read_git_sha1(package_path)
date = read_git_date(package_path)
build_date = Dates.format(Dates.now(Dates.UTC), dateformat"yyyy-mm-dd HH:MM:SS -0000")
write_version_jl(src_path, sha1, date, version, build_date)

free_memory = round(Int, Sys.free_memory() / 2^20)
total_memory = round(Int, Sys.total_memory() / 2^20)
Log.info("COMPILE: memory free $free_memory MB")
Log.info("COMPILE: memory total $total_memory MB")
end

PackageCompiler.create_app(
package_path,
build_path,
executables = executables,
precompile_execution_file = precompile_path,
incremental = false,
filter_stdlibs = filter_stdlibs,
force = true,
include_lazy_artifacts = include_lazy_artifacts,
include_transitive_dependencies = include_transitive_dependencies,
sysimage_build_args = `--strip-metadata --strip-ir`,
kwargs...,
)
if !skip_version_jl

Log.info("COMPILE: Cleaning version.jl")
clean_version_jl(src_path)

Log.info("COMPILE: Creating $target.ver")
open(joinpath(bin_path, "$target.ver"), "w") do io
writeln(io, sha1)
return nothing
end
end

Log.info("COMPILE: Copying additional files")
for file_path in additional_files_path
copy(dirname(file_path), bin_path, basename(file_path))
Expand All @@ -87,7 +93,14 @@ function compile(
end

Log.info("COMPILE: Copying Project.toml")
copy(configuration.package_path, bin_path, "Project.toml")

open(joinpath(bin_path, "Project.toml"), "w") do io
writeln(io, "name = \"$target\"")
writeln(io, "version = \"$version\"")
end

Log.info("COMPILE: Removing julia.exe")
rm(joinpath(bin_path, "julia.exe"), force = true)

Log.info("COMPILE: Success")
touch(joinpath(compile_path, "build.ok"))
Expand Down
5 changes: 5 additions & 0 deletions test/Example.jl/Example.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off

SET BASEPATH=%~dp0

CALL "%JULIA_194%" --project=%BASEPATH% %BASEPATH%\main.jl %*
11 changes: 11 additions & 0 deletions test/Example.jl/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "Example"
uuid = "28d347f4-7536-4c5e-b41f-4013aab74eac"
version = "0.1.0"

[deps]

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
5 changes: 5 additions & 0 deletions test/Example.jl/compile/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()

using Example
1 change: 1 addition & 0 deletions test/Example.jl/database/migrations/1/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRAGMA user_version = 0;
2 changes: 2 additions & 0 deletions test/Example.jl/database/migrations/1/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRAGMA foreign_keys = ON;
PRAGMA user_version = 1;
4 changes: 4 additions & 0 deletions test/Example.jl/database/ui/main.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
model = "Example"
extension = "example"
executable = "Example.bat"
collections = []
6 changes: 6 additions & 0 deletions test/Example.jl/main.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Pkg
Pkg.instantiate()

using Example

Example.main(ARGS);
5 changes: 5 additions & 0 deletions test/Example.jl/src/Example.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Example

include("main.jl")

end
11 changes: 11 additions & 0 deletions test/Example.jl/src/main.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function main(args::Vector{String})

println("Example.jl")

return nothing
end

function julia_main()::Cint
main(ARGS)
return 0
end
4 changes: 4 additions & 0 deletions test/Example.jl/src/version.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const GIT_SHA1 = "xxxxxxx"
const GIT_DATE = "xxxx-xx-xx xx:xx:xx -xxxx"
const PKG_VERSION = "x.x.x"
const PKG_BUILD_DATE = "xxxx-xx-xx xx:xx:xx -xxxx"
1 change: 1 addition & 0 deletions test/Example.jl/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using Test
24 changes: 18 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ using Test
const ID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

function testall()
package_path = raw"D:\development\psrnetwork\PSRNetworkReport.jl"
package_path = joinpath(@__DIR__, "Example.jl")
database_path = joinpath(package_path, "database")

configuration = PSRContinuousDeployment.Configuration(package_path)
configuration = PSRContinuousDeployment.Configuration(
package_path,
development_stage = PSRContinuousDeployment.DevelopmentStage.Alpha,
)

# PSRContinuousDeployment.compile(configuration)
PSRContinuousDeployment.create_setup(configuration, ID, sign = false)
PSRContinuousDeployment.compile(
configuration,
additional_files_path = [
database_path,
],
windows_additional_files_path = [
joinpath(package_path, "Example.bat"),
],
skip_version_jl = true,
)

return nothing
return 0
end

testall()
testall()

0 comments on commit 7b30e7e

Please sign in to comment.