Skip to content

Commit 527c0d4

Browse files
committed
Attach apps with apps
1 parent 847e733 commit 527c0d4

4 files changed

Lines changed: 109 additions & 24 deletions

File tree

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ authors = ["makano"]
2020
edition = "2024"
2121
license = "MIT"
2222
repository = "https://github.com/kevinj045/rew"
23-
version = "0.0.63"
23+
version = "0.0.65"
2424

2525
[workspace.dependencies]
2626
# Workspace Dependencies
27-
rew-cli = { version = "0.0.63", path = "rew-cli" }
28-
rew-compiler = { version = "0.0.63", path = "rew-compiler" }
29-
rew-core = { version = "0.0.63", path = "rew-core" }
30-
rew-data-manager = { version = "0.0.63", path = "rew-data-manager" }
31-
rew-extensions = { version = "0.0.63", path = "rew-extensions" }
32-
rew-jsx = { version = "0.0.63", path = "rew-jsx" }
33-
rew-permissions = { version = "0.0.63", path = "rew-permissions" }
34-
rew_runtime = { version = "0.0.63", path = "rew-runtime" }
35-
rew-utils = { version = "0.0.63", path = "rew-utils" }
36-
rew-vfile = { version = "0.0.63", path = "rew-vfile" }
37-
rew-brew = { version = "0.0.63", path = "rew-brew" }
38-
rew-ops = { version = "0.0.63", path = "rew-ops" }
27+
rew-cli = { version = "0.0.65", path = "rew-cli" }
28+
rew-compiler = { version = "0.0.65", path = "rew-compiler" }
29+
rew-core = { version = "0.0.65", path = "rew-core" }
30+
rew-data-manager = { version = "0.0.65", path = "rew-data-manager" }
31+
rew-extensions = { version = "0.0.65", path = "rew-extensions" }
32+
rew-jsx = { version = "0.0.65", path = "rew-jsx" }
33+
rew-permissions = { version = "0.0.65", path = "rew-permissions" }
34+
rew_runtime = { version = "0.0.65", path = "rew-runtime" }
35+
rew-utils = { version = "0.0.65", path = "rew-utils" }
36+
rew-vfile = { version = "0.0.65", path = "rew-vfile" }
37+
rew-brew = { version = "0.0.65", path = "rew-brew" }
38+
rew-ops = { version = "0.0.65", path = "rew-ops" }
3939
# Common dependencies
4040
anyhow = "1.0.96"
4141
base64 = "0.21.0"

rew-cli/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ enum Commands {
118118
#[arg(short = 'q', long)]
119119
query: Option<String>,
120120
},
121+
Attach {
122+
#[arg(name = "APP")]
123+
app: String,
124+
125+
#[arg(name = "CURRENT_APP", default_value = ".")]
126+
current_app: PathBuf,
127+
128+
#[arg(short = 'c', long)]
129+
cache: bool,
130+
},
121131
Repo {
122132
#[arg(name = "APP")]
123133
repo: String,
@@ -381,6 +391,18 @@ fn main() -> anyhow::Result<()> {
381391
logger::info("Nothing to do");
382392
}
383393
}
394+
Commands::Attach { app, current_app, cache } => {
395+
rew_pimmy::repo::init();
396+
if let Some(cache_entry) =
397+
rew_pimmy::cache::resolve_cache_entry(app, true, true, false, *cache)
398+
.await
399+
{
400+
rew_pimmy::cache::install_into(current_app.to_path_buf(), cache_entry)
401+
.await;
402+
} else {
403+
rew_core::logger::error(format!("Could not cache app: {}", app).as_str());
404+
}
405+
}
384406
Commands::Build {
385407
app,
386408
safe,

rew-pimmy/src/cache.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ pub struct AppCache {
2929
pub apps: BTreeMap<String, CachedApp>,
3030
}
3131

32+
33+
#[derive(Serialize, Deserialize, Debug, Clone)]
34+
pub struct AppLibIncludeFile {
35+
pub input: String,
36+
pub output: String,
37+
pub dir: Option<String>,
38+
}
39+
40+
3241
fn get_cache_file_path() -> Option<PathBuf> {
3342
let pimmy_data_path = utils::pimmy_data_path()?;
3443
Some(
@@ -791,6 +800,55 @@ pub fn create_bins(bins: HashMap<String, String>, install_path: &PathBuf) -> std
791800
Ok(())
792801
}
793802

803+
pub async fn install_into(app_path: PathBuf, resolve_path: PathBuf){
804+
let app_yaml_path = resolve_path.join("app.yaml");
805+
if !app_yaml_path.exists() {
806+
logger::error("app.yaml not found".into());
807+
return;
808+
}
809+
810+
let content = match fs::read_to_string(&app_yaml_path) {
811+
Ok(s) => s,
812+
Err(e) => {
813+
logger::error(&format!(
814+
"Unable to read app.yaml at {}: {}",
815+
app_yaml_path.display(),
816+
e
817+
));
818+
return;
819+
}
820+
};
821+
let manifest: Value = match serde_yaml::from_str(&content).ok() {
822+
Some(s) => s,
823+
_ => {
824+
logger::error(&format!(
825+
"Unable to read app.yaml at {}",
826+
app_yaml_path.display()
827+
));
828+
return;
829+
}
830+
};
831+
832+
833+
if let Some(libs) = manifest
834+
.get("libattachments")
835+
.and_then(|p| serde_yaml::from_value::<Vec<AppLibIncludeFile>>(p.clone()).ok())
836+
{
837+
for lib in libs {
838+
let inputfile = resolve_path.join(lib.input);
839+
let mut outputfile = app_path.join(lib.output.clone());
840+
841+
if let Some(dir) = lib.dir {
842+
fs::create_dir_all(&app_path.join(dir.clone())).ok();
843+
outputfile = app_path.join(dir).join(lib.output);
844+
}
845+
846+
fs::copy(inputfile, outputfile).ok();
847+
}
848+
}
849+
850+
}
851+
794852
pub async fn install_from(app_path: PathBuf, sync: Option<bool>, ignore_deps: bool) {
795853
let mut cache = load_app_cache();
796854

test/app.yaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ entries:
77
assets:
88
icon: assets/icon.png
99
folder: ./assets
10-
pimmy.install:
11-
dependencies:
12-
- rew.webkitui (1.0.0)
13-
- rew.appguard (1.0.0)
14-
- "@rewpkgs/rew.something"
15-
- github:someone/third.party (1.0.0)
16-
- github:someone/third.party#commit
17-
- github:someone/third.party@branch#commit
18-
- file+unzip:https://example.com/example.zip (1.0.0)
19-
- file+tar(tar -xf \$file -C \$path):https://example.com/example.tar
20-
- file+sha(SHA)+tar(tar -xf \$file -C \$path):https://example.com/example.tar
10+
dependencies:
11+
- rew.webkitui (1.0.0)
12+
- rew.appguard (1.0.0)
13+
- "@rewpkgs/rew.something"
14+
- github:someone/third.party (1.0.0)
15+
- github:someone/third.party#commit
16+
- github:someone/third.party@branch#commit
17+
- file+unzip:https://example.com/example.zip (1.0.0)
18+
- file+tar(tar -xf \$file -C \$path):https://example.com/example.tar
19+
- file+sha(SHA)+tar(tar -xf \$file -C \$path):https://example.com/example.tar
20+
libattachments:
21+
- input: .artifacts/lib.so
22+
output: .artifacts/lib.so
23+
- input: main.qrew
24+
output: libname.qrew
25+
install:
2126
bin:
2227
test: test.qrew
2328
preinstall:

0 commit comments

Comments
 (0)