Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/add-platforms-templates' in…
Browse files Browse the repository at this point in the history
…to feat/android-web-auth
  • Loading branch information
kuruk-mm committed Nov 1, 2024
2 parents 36f960a + 1fd5632 commit 6c0f5b9
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

# Build section
- name: Cargo install
run: cargo run -- install
run: cargo run -- install --platforms linux

- name: Build
working-directory: lib
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

# Build section
- name: Cargo install
run: cargo run -- install
run: cargo run -- install --platforms macos

- name: Build
working-directory: lib
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

# Build section
- name: Cargo install
run: cargo run -- install
run: cargo run -- install --platforms windows

- name: Build
working-directory: lib
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- add `ffmpeg\bin` to your `PATH`
- the `.github/workflows/ci.yml` file can be useful to guide you

4. Run `cargo run -- install` in the repo root folder.
4. Run `cargo run -- install --platforms linux` in the repo root folder (change linux to your target platform).

## Running and editing the project

Expand All @@ -43,7 +43,7 @@ cd lib
cd ../../ # return

# Compile for Linux
cargo run -- install
cargo run -- install --platforms android
cargo run -- run --only-build
cd ../../ # return

Expand Down
2 changes: 1 addition & 1 deletion build-android-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

echo "Build for Linux x86_64"
cd ${EXPLORER_PATH}
cargo run -- install
cargo run -- install --platforms android
cargo run -- run --only-build

echo "Link export templates"
Expand Down
12 changes: 10 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ pub const PROTOC_BASE_URL: &str =
pub const GODOT4_BIN_BASE_URL: &str =
"https://github.com/godotengine/godot/releases/download/4.2.1-stable/Godot_v4.2.1-stable_";

pub const GODOT_CURRENT_VERSION: &str = "4.2.1";

pub const GODOT4_EXPORT_TEMPLATES_BASE_URL: &str =
"https://github.com/godotengine/godot/releases/download/4.2.1-stable/Godot_v4.2.1-stable_export_templates.tpz";
"https://github.com/decentraland/godotengine/releases/download/4.2.1-stable/";

pub const GODOT_CURRENT_VERSION: &str = "4.2.1";
pub const GODOT_PLATFORM_FILES: &[(&str, &[&str])] = &[
("ios", &["ios.zip"]),
("android", &["android_debug.apk", "android_release.apk", "android_source.zip"]),
("linux", &["linux_debug.x86_64", "linux_release.x86_64"]),
("macos", &["macos.zip"]),
("windows", &["windows_debug_x86_64.exe", "windows_release_x86_64.exe"]),
];
45 changes: 36 additions & 9 deletions src/export.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{fs, io, path::Path, process::ExitStatus};
use std::{collections::HashMap, fs, io, path::Path, process::ExitStatus};

use crate::{
consts::{
BIN_FOLDER, EXPORTS_FOLDER, GODOT4_EXPORT_TEMPLATES_BASE_URL, GODOT_CURRENT_VERSION,
GODOT_PROJECT_FOLDER,
BIN_FOLDER, EXPORTS_FOLDER, GODOT4_EXPORT_TEMPLATES_BASE_URL, GODOT_CURRENT_VERSION, GODOT_PLATFORM_FILES, GODOT_PROJECT_FOLDER
},
copy_files::copy_ffmpeg_libraries,
install_dependency::{download_and_extract_zip, set_executable_permission},
Expand Down Expand Up @@ -131,13 +130,41 @@ pub fn export() -> Result<(), anyhow::Error> {
Ok(())
}

pub fn prepare_templates() -> Result<(), anyhow::Error> {
pub fn prepare_templates(platforms: &[String]) -> Result<(), anyhow::Error> {
// Convert GODOT_PLATFORM_FILES into a HashMap
let file_map: HashMap<&str, Vec<&str>> = GODOT_PLATFORM_FILES
.iter()
.map(|(platform, files)| (*platform, files.to_vec()))
.collect();

// If no specific templates are provided, default to all templates
let templates = if platforms.is_empty() {
println!("No specific templates provided, downloading all templates.");
println!("For downloading for a specific platform use: `cargo run -- install --platform linux`");
file_map.keys().map(|&k| k.to_string()).collect::<Vec<String>>()
} else {
platforms.to_vec()
};

// Process each template and download the associated files
let dest_path = format!("{BIN_FOLDER}godot/templates");
download_and_extract_zip(
GODOT4_EXPORT_TEMPLATES_BASE_URL,
dest_path.as_str(),
Some(format!("{GODOT_CURRENT_VERSION}.export-templates.zip")),
)?;

for template in templates {
if let Some(files) = file_map.get(template.as_str()) {
for file in files {
println!("Downloading file for {}: {}", template, file);

let url = format!("{}{}.zip", GODOT4_EXPORT_TEMPLATES_BASE_URL.to_string(), file);
download_and_extract_zip(
url.as_str(),
dest_path.as_str(),
Some(format!("{GODOT_CURRENT_VERSION}.{file}.export-templates.zip")),
)?;
}
} else {
println!("No files mapped for template: {}", template);
}
}

Ok(())
}
6 changes: 3 additions & 3 deletions src/install_dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn download_and_extract_zip(

// If the cached file exist, use it
if let Some(already_existing_file) = get_existing_cached_file(persistent_cache.clone()) {
println!("Getting cached file of {url:?}");
println!("Getting cached file of {url:?} (local path: {already_existing_file}");
fs::copy(already_existing_file, "./tmp-file.zip")?;
} else {
println!("Downloading {url:?}");
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn get_godot_executable_path() -> Option<String> {
Some(os_url)
}

pub fn install(skip_download_templates: bool) -> Result<(), anyhow::Error> {
pub fn install(skip_download_templates: bool, platforms: &[String]) -> Result<(), anyhow::Error> {
let persistent_path = get_persistent_path(Some("test.zip".into())).unwrap();
println!("Using persistent path: {persistent_path:?}");

Expand Down Expand Up @@ -243,7 +243,7 @@ pub fn install(skip_download_templates: bool) -> Result<(), anyhow::Error> {
fs::copy(program_path, dest_program_path.as_str())?;

if !skip_download_templates {
prepare_templates()?;
prepare_templates(platforms)?;
}

Ok(())
Expand Down
31 changes: 24 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ fn main() -> Result<(), anyhow::Error> {
)
.subcommand(Command::new("docs"))
.subcommand(
Command::new("install").arg(
Arg::new("no-templates")
.long("no-templates")
.help("skip download templates")
.takes_value(false),
),
Command::new("install")
.arg(
Arg::new("no-templates")
.long("no-templates")
.help("skip download templates")
.takes_value(false),
)
.arg(
Arg::new("platforms")
.long("platforms")
.help("download platform, can use multiple platforms, use like `--platforms linux android`")
.takes_value(true)
.multiple_values(true),
),
)
.subcommand(Command::new("update-protocol"))
.subcommand(
Expand Down Expand Up @@ -152,7 +160,16 @@ fn main() -> Result<(), anyhow::Error> {
let root = xtaskops::ops::root_dir();

let res = match subcommand {
("install", sm) => install_dependency::install(sm.is_present("no-templates")),
("install", sm) => {
let no_templates = sm.is_present("no-templates");
let platforms: Vec<String> = sm
.values_of("platforms")
.map(|vals| vals.map(String::from).collect())
.unwrap_or_default();

// Call your install function and pass the templates
install_dependency::install(no_templates, &platforms)
},
("update-protocol", _) => install_dependency::install_dcl_protocol(),
("compare-image-folders", sm) => {
let snapshot_folder = Path::new(sm.value_of("snapshots").unwrap());
Expand Down

0 comments on commit 6c0f5b9

Please sign in to comment.