Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for caching multiple workflows #4

Merged
merged 20 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: CI
on: push
on:
push:
pull_request:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

- Bundles all necessary Julia code and artifacts needed to run without internet access.
- Build for platforms other than the host platform.
- Can build multiple packages/projects into a single path.
- Can precompile all dependencies to built path.

## Usage

### Example 1
```julia
using DepotDelivery: build

Expand All @@ -25,6 +28,18 @@ path = build(path_to_project; platform = Base.BinaryPlatforms.HostPlatform())
- The build settings live in `$path/config/depot_build.toml`
- Run this in the production environment to get started: `include("$path/config/depot_startup.jl")`.

### Example 2
This example shows how to build a depo path from different Project.toml files, enabling precompilation as needed.
```julia
using DepotDelivery: build

# We can provide a depot_path to share DEPOT_PATH
depot_path = "path/to/depot/"

# Assumes `path/Project.toml` exists (or `path/JuliaProject.toml`) in each entry of first argument, and force precompilation.
path = build(["path/project-1", "path-2/project-2"]; depot=depot_path, precompiled=true)
```

## Building for Non-Host Platforms

- Use any `Base.BinaryPlatforms.AbstractPlatform` as the `platform` argument.
Expand Down
62 changes: 54 additions & 8 deletions src/DepotDelivery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,53 @@ function sandbox(f::Function)
end
end

#-----------------------------------------------------------------------------# build
function build(path::String; platform = Base.BinaryPlatforms.HostPlatform(), verbose=true)
#-----------------------------------------------------------------------------#
"""
Builds the depot for a specified project.

Arguments:
- `path::String`: The path to the project directory containing `Project.toml` or `JuliaProject.toml`.
- `platform::AbstractPlatform`: The target platform for building (default is the host platform).
- `verbose::Bool`: Whether to display verbose output during the build process (default is `true`).
- `depot::String`: The path to the depot directory (default is a temporary directory).
- `precompiled::Bool`: Whether to enable precompilation of packages (default is `false`).

Returns:
- The path to the built depot.

Example:
```julia
depot_path = build("/path/to/your/project")
"""
function build(path::String; platform = Base.BinaryPlatforms.HostPlatform(), verbose=true, depot = mktempdir(), precompiled=false)
path = abspath(path)
depot = mktempdir()
mkpath(depot)
sandbox() do
proj_file = joinpath(path, "Project.toml")
proj_file = isfile(proj_file) ? proj_file : joinpath(path, "JuliaProject.toml")
isfile(proj_file) || error("No Project.toml or JuliaProject.toml found in `$path`.")
proj = TOML.parsefile(proj_file)
name = proj["name"]
# Defines a project name for Project.toml that don't come from a package
name = haskey(proj, "name") ? proj["name"] : Base.basename(Base.dirname(proj_file))
build_spec = Dict(
:datetime => Dates.now(),
:versioninfo => sprint(InteractiveUtils.versioninfo),
:project_file => proj_file,
:project => proj,
:platform => string(platform)
)
mkdir(joinpath(depot, "config"))
mkdir(joinpath(depot, "dev"))
mkpath(joinpath(depot, "config"))
mkpath(joinpath(depot, "dev", name))
push!(empty!(DEPOT_PATH), depot)
ENV["JULIA_PKG_PRECOMPILE_AUTO"] = "0" # Needed when building for non-host platforms

# Disabling precompile for non-host platforms
precompiled ? delete!(ENV, "JULIA_PKG_PRECOMPILE_AUTO") : ENV["JULIA_PKG_PRECOMPILE_AUTO"] = "0"

cp(path, joinpath(depot, "dev", name)) # Copy project into dev/
for file in filter(f -> endswith(f, ".toml"), readdir(path))
# Copy only .toml files into dev/
cp(joinpath(path, file), joinpath(depot, "dev", name, file), force=true)
end

Pkg.activate(joinpath(depot, "dev", name))
Pkg.instantiate(; platform, verbose)

Expand All @@ -68,6 +92,28 @@ function build(path::String; platform = Base.BinaryPlatforms.HostPlatform(), ver
return depot
end

"""
Builds depots for multiple projects specified by their paths.

Arguments:
- `paths::Vector{String}`: An array of directories of project paths.
- `platform::AbstractPlatform`: The target platform for building (default is the host platform).
- `verbose::Bool`: Whether to display verbose output during the build process (default is `true`).
- `depot::String`: The path to the depot directory (default is a temporary directory).
- `precompiled::Bool`: Whether to enable precompilation (default is `false`).

Example:
```julia
project_paths = ["/path/to/project1", "/path/to/project2"]
build(project_paths)
"""
function build(paths::Vector{String}; platform = Base.BinaryPlatforms.HostPlatform(), verbose=true, depot=mktempdir(), precompiled=false)
for path in paths
build(path; platform=platform, verbose=verbose, depot=depot, precompiled=precompiled)
end
end


#-----------------------------------------------------------------------------# startup_script
startup_script(name) = """
import Pkg
Expand Down
Loading