Skip to content

Commit

Permalink
fix: added xdebug + linux support - fixes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Jan 14, 2020
1 parent 12dde8c commit a756ff8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wf2_core/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::os::OsInfo;
use crate::php::PHP;
use crate::recipes::recipe_kinds::RecipeKinds;
use crate::scripts::scripts::Scripts;
Expand Down Expand Up @@ -97,6 +98,9 @@ pub struct Context {

#[serde(default)]
pub origin: Option<String>,

#[serde(skip, default)]
pub os: OsInfo,
}

///
Expand Down Expand Up @@ -135,6 +139,7 @@ impl Default for Context {
env: None,
scripts: None,
origin: None,
os: OsInfo::new(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions wf2_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod dc_tasks;
pub mod dc_volume;
pub mod file;
pub mod file_op;
pub mod os;
pub mod output;
pub mod php;
pub mod recipes;
Expand Down
40 changes: 40 additions & 0 deletions wf2_core/src/os.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
///
/// Relevant OS information that commands
/// may/may-not care about
///
#[derive(Debug, PartialEq, Default, Clone)]
pub struct OsInfo {
pub os_type: OsType,
}

impl OsInfo {
pub fn new() -> OsInfo {
OsInfo {
#[cfg(target_os = "macos")]
os_type: OsType::Mac,

#[cfg(target_os = "windows")]
os_type: OsType::Windows,

// this wont take effect if either of the above apply
..Default::default()
}
}
}

///
/// Deliberately not an exhaustive list.
/// If it's not window or mac, assume linux
///
#[derive(Debug, PartialEq, Clone)]
pub enum OsType {
Mac,
Windows,
Linux,
}

impl Default for OsType {
fn default() -> Self {
OsType::Linux
}
}
13 changes: 13 additions & 0 deletions wf2_core/src/recipes/m2/m2_runtime_env_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::context::Context;
use crate::file::File;
use crate::os::{OsInfo, OsType};
use env_proc::env_vars;
use snailquote::escape;
use std::collections::HashMap;
Expand Down Expand Up @@ -106,6 +107,7 @@ pub fn create_runtime_env(
merged.insert(EnvVarKeys::HostGid, ctx.gid.to_string());
merged.insert(EnvVarKeys::MageHost, format!("https://{}", domain));
merged.insert(EnvVarKeys::PhpIdeConfig, format!("serverName={}", domain));
merged.insert(EnvVarKeys::XdebugConfig, docker_host(&ctx.os));

Ok(print(merged))
}
Expand All @@ -126,6 +128,16 @@ fn print(store: HashMap<EnvVarKeys, String>) -> Vec<u8> {
buffer
}

fn docker_host(os_info: &OsInfo) -> String {
use OsType::*;
match os_info.os_type {
Mac => "docker.for.mac.host.internal",
Windows => "docker.for.windows.host.internal",
_ => "host.docker.internal",
}
.to_string()
}

#[derive(Deserialize, Default, Debug, Clone)]
pub struct M2EnvVars(HmEnv);

Expand All @@ -151,4 +163,5 @@ fn test_env_hash_without_overrides() {
let as_str = std::str::from_utf8(&env).expect("test");
assert!(as_str.contains("PHP_IDE_CONFIG=serverName=local.m2"));
assert!(as_str.contains(r#"MAGE_ROOT_DIR=/var/www"#));
assert!(as_str.contains(r#"XDEBUG_CONFIG=docker.for.mac.host.internal"#));
}

0 comments on commit a756ff8

Please sign in to comment.