Skip to content

Commit

Permalink
Merge pull request #275 from kinode-dao/hf/build-rewrite-before-build
Browse files Browse the repository at this point in the history
build: improve devex by rewriting before build
  • Loading branch information
nick1udwig authored Nov 23, 2024
2 parents 885a96a + cfc7b50 commit ed4b903
Show file tree
Hide file tree
Showing 8 changed files with 1,021 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ fs-err = "2.11"
hex = "0.4"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib.git", rev = "9ac9e51" }
nix = { version = "0.27", features = ["process", "signal", "term"] }
proc-macro2 = "1.0"
regex = "1"
reqwest = { version = "0.12", features = ["json"] }
rpassword = "7"
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10.8"
syn = { version = "2.0", features = ["full", "visit", "extra-traits"] }
#syn = { version = "2.0", features = ["full", "visit"] }
thiserror = "1.0"
tokio = { version = "1.28", features = [
"macros",
"process",
Expand All @@ -55,6 +59,7 @@ tokio = { version = "1.28", features = [
"time",
] }
toml = "0.8"
toml_edit = "0.22"
tracing = "0.1"
tracing-appender = "0.2"
tracing-error = "0.2"
Expand Down
30 changes: 28 additions & 2 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ use crate::setup::{
use crate::view_api;
use crate::KIT_CACHE;

mod rewrite;
use rewrite::copy_and_rewrite_package;

const PY_VENV_NAME: &str = "process_env";
const JAVASCRIPT_SRC_PATH: &str = "src/lib.js";
const PYTHON_SRC_PATH: &str = "src/lib.py";
Expand Down Expand Up @@ -1155,6 +1158,7 @@ async fn fetch_dependencies(
default_world: Option<&str>,
include: &HashSet<PathBuf>,
exclude: &HashSet<PathBuf>,
rewrite: bool,
force: bool,
verbose: bool,
) -> Result<()> {
Expand All @@ -1171,6 +1175,7 @@ async fn fetch_dependencies(
default_world,
vec![], // TODO: what about deps-of-deps?
vec![],
rewrite,
false,
force,
verbose,
Expand Down Expand Up @@ -1207,6 +1212,7 @@ async fn fetch_dependencies(
default_world,
local_dep_deps,
vec![],
rewrite,
false,
force,
verbose,
Expand Down Expand Up @@ -1522,6 +1528,7 @@ async fn compile_package(
add_paths_to_api: &Vec<PathBuf>,
include: &HashSet<PathBuf>,
exclude: &HashSet<PathBuf>,
rewrite: bool,
force: bool,
verbose: bool,
ignore_deps: bool, // for internal use; may cause problems when adding recursive deps
Expand All @@ -1544,6 +1551,7 @@ async fn compile_package(
default_world,
include,
exclude,
rewrite,
force,
verbose,
)
Expand Down Expand Up @@ -1651,6 +1659,7 @@ pub async fn execute(
default_world: Option<&str>,
local_dependencies: Vec<PathBuf>,
add_paths_to_api: Vec<PathBuf>,
rewrite: bool,
reproducible: bool,
force: bool,
verbose: bool,
Expand Down Expand Up @@ -1734,7 +1743,16 @@ pub async fn execute(

check_process_lib_version(&package_dir.join("Cargo.toml"))?;

let ui_dirs = get_ui_dirs(package_dir, &include, &exclude)?;
// live_dir is the "dir that is being built" or is "live";
// if `!rewrite`, that is just `package_dir`;
// else, it is the modified copy that is in `target/rewrite/`
let live_dir = if !rewrite {
PathBuf::from(package_dir)
} else {
copy_and_rewrite_package(package_dir)?
};

let ui_dirs = get_ui_dirs(&live_dir, &include, &exclude)?;
if !no_ui && !ui_dirs.is_empty() {
if !skip_deps_check {
let mut recv_kill = make_fake_kill_chan();
Expand All @@ -1749,7 +1767,7 @@ pub async fn execute(

if !ui_only {
compile_package(
package_dir,
&live_dir,
skip_deps_check,
features,
url,
Expand All @@ -1759,13 +1777,21 @@ pub async fn execute(
&add_paths_to_api,
&include,
&exclude,
rewrite,
force,
verbose,
ignore_deps,
)
.await?;
}

if rewrite {
if package_dir.join("pkg").exists() {
fs::remove_dir_all(package_dir.join("pkg"))?;
}
copy_dir(live_dir.join("pkg"), package_dir.join("pkg"))?;
}

let metadata = read_metadata(package_dir)?;
let pkg_publisher = make_pkg_publisher(&metadata);
let (_zip_filename, hash_string) = zip_pkg(package_dir, &pkg_publisher)?;
Expand Down
Loading

0 comments on commit ed4b903

Please sign in to comment.