-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dependency management functionality and update version to 1.0.5
- Loading branch information
1 parent
9ebb3de
commit 5c24a35
Showing
5 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import Config from "./Config"; | ||
const { execSync } = require("child_process"); | ||
import { targets } from "./Build"; | ||
|
||
const execOptions = { stdio: "pipe", shell: "/bin/bash", env: { ...process.env } }; | ||
const libEcsRepo = "https://github.com/metaverse-systems/libecs-cpp.git"; | ||
const libTheSeedRepo = "https://github.com/metaverse-systems/libthe-seed.git"; | ||
|
||
export const checkLib = (config: Config, library: string, target: string) => { | ||
const targetPrefix = targets[target]; | ||
const prefix = config.config.prefix + "/" + targetPrefix; | ||
const pkgConfigCommand = | ||
"PKG_CONFIG_PATH=" + | ||
prefix + | ||
"/lib/pkgconfig/ " + | ||
"pkg-config --cflags --libs " + | ||
library; | ||
try { | ||
const result = execSync(pkgConfigCommand, execOptions).toString(); | ||
if (result.includes(library)) { | ||
return true; | ||
} | ||
console.error("pkg-config did not find " + library); | ||
} catch (e) { | ||
return false; | ||
} | ||
return false; | ||
}; | ||
|
||
export const checkLibEcs = (config: Config, target: string) => { | ||
return checkLib(config, "ecs-cpp", target); | ||
}; | ||
|
||
export const checkLibTheSeed = (config: Config, target: string) => { | ||
return checkLib(config, "the-seed", target); | ||
}; | ||
|
||
export const installLibEcs = (config: Config, target: string) => { | ||
const targetDir = targets[target]; | ||
const prefix = config.config.prefix + "/" + targetDir; | ||
const cloneCommand = "git clone " + libEcsRepo; | ||
try { | ||
const result = execSync(cloneCommand, execOptions).toString(); | ||
} catch (e) { | ||
console.error("Failed to clone libecs-cpp"); | ||
} | ||
const buildCommand = | ||
"cd ecs-cpp && ./autogen.sh && ./configure --prefix=" + | ||
prefix + | ||
target != "native" ? " --host=" + targetDir : "" + | ||
" && make && make install"; | ||
try { | ||
const result = execSync(buildCommand, execOptions).toString(); | ||
} catch (e) { | ||
console.error("Failed to build libecs-cpp"); | ||
console.error(e); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
export const installLibTheSeed = (config: Config, target: string) => { | ||
const targetDir = targets[target]; | ||
const prefix = config.config.prefix + "/" + targetDir; | ||
const cloneCommand = "git clone " + libTheSeedRepo; | ||
try { | ||
const result = execSync(cloneCommand, execOptions).toString(); | ||
} catch (e) { | ||
console.error("Failed to clone libthe-seed"); | ||
} | ||
const env = { | ||
...process.env, | ||
PKG_CONFIG_PATH: `${prefix}/lib/pkgconfig/` | ||
}; | ||
|
||
let buildCommand = "cd libthe-seed"; | ||
buildCommand += " && ./autogen.sh"; | ||
buildCommand += " && PKG_CONFIG_PATH=" + prefix + "/lib/pkgconfig/"; | ||
buildCommand += " ./configure --prefix=" + prefix; | ||
if(target != "native") { | ||
buildCommand += " --host=" + targetDir; | ||
} | ||
buildCommand += " && make && make install"; | ||
try { | ||
const result = execSync( | ||
buildCommand, | ||
{ stdio: "inherit", env, shell: "/bin/bash" } | ||
); | ||
} catch (e) { | ||
console.error("Failed to build libthe-seed"); | ||
console.error(e); | ||
return false; | ||
} | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { checkLibEcs, checkLibTheSeed, installLibEcs, installLibTheSeed } from "../Dependencies"; | ||
import Config from "../Config"; | ||
import { ScriptArgsType } from "../types"; | ||
|
||
const DependenciesCLI = (scriptConfig: ScriptArgsType) => { | ||
const config = new Config(scriptConfig.configDir); | ||
|
||
const command = scriptConfig.args[3]; | ||
const target = scriptConfig.args[4] ? scriptConfig.args[4] : "native"; | ||
|
||
switch (command) { | ||
case "help": | ||
console.log("\nUsage: the-seed dependencies <command>"); | ||
console.log("\nAvailable commands:"); | ||
console.log(" help - Show this help message"); | ||
console.log(" check - Check if dependencies are installed"); | ||
break; | ||
case "check": | ||
if (checkLibEcs(config, target)) { | ||
console.log("libecs-cpp is installed."); | ||
} else { | ||
console.log("libecs-cpp is not installed."); | ||
} | ||
if (checkLibTheSeed(config, target)) { | ||
console.log("libthe-seed is installed."); | ||
} else { | ||
console.log("libthe-seed is not installed."); | ||
} | ||
break; | ||
case "install": | ||
if (!checkLibEcs(config, target)) { | ||
console.log("Installing libecs-cpp..."); | ||
if (installLibEcs(config, target)) { | ||
console.log("libecs-cpp installed successfully."); | ||
} else { | ||
console.error("Failed to install libecs-cpp."); | ||
} | ||
} | ||
if (!checkLibTheSeed(config, target)) { | ||
console.log("Installing libthe-seed..."); | ||
if (installLibTheSeed(config, target)) { | ||
console.log("libthe-seed installed successfully."); | ||
} else { | ||
console.error("Failed to install libthe-seed."); | ||
} | ||
} | ||
break; | ||
default: | ||
console.log( | ||
"Invalid command. Use 'the-seed dependencies help' for usage information." | ||
); | ||
break; | ||
} | ||
return true; | ||
}; | ||
|
||
export default DependenciesCLI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters