Skip to content

Commit

Permalink
Update build process
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Oct 13, 2024
1 parent 41087be commit 8a9bdf9
Show file tree
Hide file tree
Showing 21 changed files with 407 additions and 372 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ setup:
@julia --project=scripts/build -e 'import Pkg; Pkg.develop(path=@__DIR__)'

build:
@julia --project=scripts/build ./scripts/build/build.jl
@julia --project=scripts/build scripts/build/script.jl

test-build:
@julia --project=scripts/build --load scripts/build/runtests.jl --eval 'test_main()'

clear:
@rm -rf ./dist

run: setup
@julia --project=scripts/run/mqlib ./scripts/run/mqlib/run.jl

setup-docs:
@julia --project=docs -e 'import Pkg; Pkg.develop(path=@__DIR__); Pkg.instantiate()'

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ QUBOTools = "0.10"
SQLite = "1"
Pkg = "1"
TOML = "1"
julia = "1.9"
julia = "1.10"
4 changes: 4 additions & 0 deletions docs/src/booklet/1-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ The HDF5 file format is used to store the data. The data is stored in a hierarch

- `instances`: Contains the instances of the data.
- `solutions`: Contains the solutions to the instances.

## Collections

One of the core ideas behind [`QUBOLib`](https://github.com/JuliaQUBO/QUBOLib.jl) is to deploy other QUBO instance libraries in a bundle.
22 changes: 22 additions & 0 deletions docs/src/booklet/2-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build Process

Building QUBOLib from scratch

## Distribution Folder structure

```
dist
├── build
│ ├── Artifact.toml
│ ├── git-tree.hash
│ ├── tar-ball.hash
│ ├── last.tag
│ └── next.tag
└── cache
└── collection...
└── data
qubolib
├── archive.h5
└── index.db
```

41 changes: 19 additions & 22 deletions scripts/build/build.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
using JuliaFormatter
using LaTeXStrings
import Downloads

import QUBOLib
import QUBOTools
import Downloads

include("library/clear.jl")
include("library/deploy.jl")

include("sources/arXiv_1903_10928_3r3x.jl")
include("sources/arXiv_1903_10928_5r5x.jl")
include("sources/hen.jl")
include("sources/qplib.jl")

function build_standard_qubolib(
path::AbstractString = root_path();
clear_build::Bool = false,
path::AbstractString;
clear_cache::Bool = false,
clear_build::Bool = false,
)
@info "Building QUBOLib v$(QUBOLib.__version__())"

if clear_build
QUBOLib.clear_build(path)
end
@info "Building QUBOLib v$(QUBOLib.__version__()) @ $(path)"

if clear_cache
QUBOLib.clear_cache(path)
@info "[Clearing Cache]"

clear_cache!(path)
end

close(QUBOLib.access(; path, create = true))
if clear_build
@info "[Clearing Build]"

QUBOLib.access(; path) do index
build_arXiv_1903_10928_3r3x!(index)
QUBOLib.access(; path, clear = true) |> close
end

# QUBOLib.access(; path) do index
# build_arXiv_1903_10928_5r5x!(index)
# end
QUBOLib.access(; path) do index
build_hen!(index)
end

QUBOLib.access(; path) do index
build_qplib!(index)
Expand All @@ -43,15 +41,14 @@ function build_standard_qubolib(
return nothing
end

function main(args::Vector{String} = ARGS)
QUBOLib.print_logo(stdout)

function main()
build_standard_qubolib(
QUBOLib.root_path();
clear_build = ("--clear-build" ARGS),
clear_cache = ("--clear-cache" ARGS),
clear_cache = ("--clear-cache" args),
clear_build = ("--clear-build" args),
)

return nothing
end

main() # Here we go!
10 changes: 2 additions & 8 deletions scripts/build/library/clear.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
function clear_build(path::AbstractString = QUBOLib.root_path())
rm(build_path(path; ifmissing = identity); force = true, recursive = true)

return nothing
end

function clear_cache(path::AbstractString = QUBOLib.root_path())
rm(cache_path(path; ifmissing = identity); force = true, recursive = true)
function clear_cache!(path::AbstractString = QUBOLib.root_path())
rm(QUBOLib.cache_path(path); force = true, recursive = true)

return nothing
end
105 changes: 61 additions & 44 deletions scripts/build/library/deploy.jl
Original file line number Diff line number Diff line change
@@ -1,77 +1,94 @@
function deploy(path::AbstractString)
function deploy!(path::AbstractString)
@assert Sys.islinux()

# Calculate tree hash
tree_hash = bytes2hex(Pkg.GitTools.tree_hash(build_path(path)))
git_tree_hash = bytes2hex(Pkg.GitTools.tree_hash(QUBOLib.library_path(path)))

# Build tarball
temp_path = abspath(Tar.create(build_path(path)))
temp_path = abspath(Tar.create(QUBOLib.library_path(path)))

# Compress tarball
run(`gzip -9 $temp_path`)

# Move tarball
file_path = mkpath(abspath(dist_path(path), "qubolib.tar.gz"))
tar_ball_path = mkpath(abspath(QUBOLib.dist_path(path), "qubolib.tar.gz"))

rm(file_path; force = true)
rm(tar_ball_path; force = true)

cp("$temp_path.gz", file_path; force = true)
cp("$temp_path.gz", tar_ball_path; force = true)

# Remove temporary files
rm(temp_path; force = true)
rm("$temp_path.gz"; force = true)

# Write hash to file
write(joinpath(dist_path(path), "tree.hash"), tree_hash)
write(joinpath(QUBOLib.build_path(path), "git-tree.hash"), git_tree_hash)

# Also, compute sha256 sum
ball_hash = read(pipeline(`sha256sum -z $file_path`, `cut -d ' ' -f 1`), String)
tar_ball_hash = read(pipeline(`sha256sum -z $tar_ball_path`, `cut -d ' ' -f 1`), String)

write(joinpath(dist_path(path), "ball.hash"), ball_hash)

return nothing
end
write(joinpath(QUBOLib.build_path(path), "tar-ball.hash"), tar_ball_hash)

function next_tag(path::AbstractString)
last_tag = if haskey(ENV, "LAST_QUBOLIB_TAG")
x = tryparse(VersionNumber, ENV["LAST_QUBOLIB_TAG"])
# Retrieve last QUBOLib tag
# last_tag = read(joinpath(QUBOLib.build_path(path), "last.tag"), String)
# next_tag = next_data_tag(last_tag)

if isnothing(x)
@warn("Pushing tag forward")

v"0.1.0"
else
x
end
else
last_tag_path = abspath(path, "last.tag")
# write(joinpath(QUBOLib.build_path(path), "next.tag"), next_tag)

if isfile(last_tag_path)
text = read(last_tag_path, String)
# # Write Artifacts.toml entry
# artifact_entry = """
# [qubolib]
# git-tree-sha1 = "$(git_tree_hash)"
# lazy = true

m = match(r"tag:\s*v(.*)", text)
# [[qubolib.download]]
# url = "https://github.com/JuliaQUBO/QUBOLib.jl/releases/download/$(qubolib_tag)/qubolib.tar.gz"
# sha256 = "$(tar_ball_hash)"
# """

if isnothing(m)
@error("Tag not found in '$last_tag_path'")
# write(joinpath(QUBOLib.build_path(path), "Artifacts.toml"), artifact_entry)

return nothing
end

exit(1)
end
function next_data_tag(last_tag::AbstractString)::String
return next_data_tag(parse(VersionNumber, last_tag))
end

parse(VersionNumber, m[1])
function next_data_tag(last_tag::VersionNumber)::String
next_tag = if isempty(last_tag.prerelease)
@assert isempty(last_tag.build)

VersionNumber(
last_tag.major,
last_tag.minor,
last_tag.patch,
("data",),
(1,),
)
else # !isempty(last_tag.prerelease)
@assert only(last_tag.prerelease) == "data"

if isempty(last_tag.build)
VersionNumber(
last_tag.major,
last_tag.minor,
last_tag.patch,
last_tag.prerelease,
(1,),
)
else
@error("File '$last_tag_path' not found")

exit(1)
@assert only(last_tag.build) isa Integer "last_tag.build = $(last_tag.build)"

VersionNumber(
last_tag.major,
last_tag.minor,
last_tag.patch,
last_tag.prerelease,
(only(last_tag.build) + 1,)
)
end
end

next_tag = VersionNumber(
last_tag.major,
last_tag.minor,
last_tag.patch + 1,
last_tag.prerelease,
last_tag.build,
)

return "v$next_tag"
return "v$(next_tag)"
end
20 changes: 20 additions & 0 deletions scripts/build/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Test

include("build.jl")

function test_tags()
@testset "▶ Tags" begin
@test next_data_tag("v0.1.0") == "v0.1.0-data+1"
@test next_data_tag("v1.2.3-data+2") == "v1.2.3-data+3"
end

return nothing
end

function test_main()
@testset "♦ QUBOLib.jl/scripts/build test suite ♦" verbose = true begin
test_tags()
end

return nothing
end
3 changes: 3 additions & 0 deletions scripts/build/script.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include("build.jl")

main() # Here we go!
77 changes: 0 additions & 77 deletions scripts/build/sources/arXiv_1903_10928_3r3x.jl

This file was deleted.

Loading

0 comments on commit 8a9bdf9

Please sign in to comment.