Commit 1ac6ff2f authored by Bat's avatar Bat

Reimplemented the 'library' property.

I don't what you have done Git, but I don't like it.
parent d8b70511
......@@ -79,6 +79,10 @@ The path to a directory containing personal VAPIs.
Where to put the result of the compilation. Defaults to `build/name-version` (where `name` is the name of the project and `version` the version).
### library
A boolean that tells us if this project is a library or not. If it is, it will be compiled in a special way, to make it reusable by everyone.
### scripts
Some custom scripts, that can be run whit `poulp run`. It's an object containing the fields you want (their name will be used as the argument of `poulp run`). Each of those fields are arrays with the list of the command to run.
......
......@@ -21,16 +21,29 @@ namespace Poulp.Commands {
string build_dir = "build/";
// gettin the output file
string output;
string output, output_name;
if (man.output != null) { // if the output is specified in the manifest, we use it
output = man.output;
output = output_name = man.output;
} else {
output = Path.build_filename (build_dir , (man.name + "-" + ((man.version != null) ? man.version : "0.1.0"))); // else, we use build/name-version
output = output_name = Path.build_filename (build_dir , (man.name + "-" + ((man.version != null) ? man.version : "0.1.0"))); // else, we use build/name-version
}
// We add .so or .dll to the output if we compile a library.
string ext = "";
if (man.library) {
#if WIN32
ext = ".dll";
#else
ext = ".so";
#endif
}
output += ext;
// we add some flags and extensions that are platform specifics
#if WIN32
output += ".exe";
if (!man.library) {
output += ".exe";
}
valac_args += "-D WIN32";
#elif BSD
valac_args += "-D BSD";
......@@ -87,6 +100,17 @@ namespace Poulp.Commands {
}
}
if (man.library) {
valac_args += "--library";
valac_args += output_name;
valac_args += "-H";
valac_args += output_name + ".h";
valac_args += "-X";
valac_args += "-fPIC";
valac_args += "-X";
valac_args += "-shared";
}
// TODO: check Vala version
foreach (string param in man.compiler_params) {
......@@ -103,10 +127,12 @@ namespace Poulp.Commands {
spawn (valac_cmd, out valac_stdout, out valac_stderr, out valac_status);
if (valac_status == 0) {
Logger.logc (LogColor.BOLD_GREEN, "Successfully built project `%s`.", man.name);
Logger.logc (
LogColor.BOLD_BLUE, "Run %s./%s%s to launch your project.",
LogColor.BOLD_YELLOW, output, LogColor.BOLD_BLUE
);
if (!man.library) {
Logger.logc (
LogColor.BOLD_BLUE, "Run %s./%s%s to launch your project.",
LogColor.BOLD_YELLOW, output, LogColor.BOLD_BLUE
);
}
if (valac_stdout != "") {
Logger.log (valac_stdout);
......@@ -114,6 +140,44 @@ namespace Poulp.Commands {
if (valac_stderr != "") {
Logger.log (valac_stderr);
}
// write .deps and .pc file if compilation succeeds, and if we are building a lib
if (man.library) {
string deps = "";
foreach (string dep in man.libs) {
deps += dep + "\n";
}
FileUtils.set_contents (output_name + ".deps", deps);
string pc = "includedir=" + Environment.get_variable ("POULP_HEADERS_DIR") + "\n";
pc += "libdir=" + Environment.get_variable ("POULP_LIB_DIR") + "\n\n";
pc += "Name: " + man.name + "\n";
if (man.description != null) {
pc += "Description: " + man.description + "\n";
}
pc += "Version: " + man.version + "\n";
pc += "Cflags: -I${includedir}/" + man.name + "\n";
pc += "Libs: -L${libdir} -l" + output_name + "\n";
if (man.libs.size > 0) {
pc += "Requires:";
foreach (string lib in man.libs) {
pc += " " + lib;
}
pc += "\n";
}
FileUtils.set_contents (output_name + ".pc", pc);
Logger.logc (LogColor.GREEN, """To install your library:
- Copy %s and %s to %s ;
- Copy %s to %s ;
- Copy %s to %s ;
- Copy %s to %s ;
And then you can run valac with `--pkg %s` !""", output_name + ".vapi", output_name + ".deps", Environment.get_variable ("POULP_VAPI_DIR"),
output_name + ".h", Path.build_filename (Environment.get_variable ("POULP_HEADERS_DIR"), man.name),
output_name + ".pc", Environment.get_variable ("POULP_PKG_DIR"),
output_name + ext, Environment.get_variable ("POULP_LIB_DIR"),
output_name);
}
} else {
Logger.log_error (valac_stdout);
Logger.log (valac_stderr);
......
......@@ -142,6 +142,7 @@ namespace Poulp {
this.scripts[member] = cmds;
});
}
this.library = root.has_member ("library") ? root.get_boolean_member ("library") : false;
if (root.has_member ("libs")) {
root.get_array_member ("libs").foreach_element ((arr, index, elt) => {
if (elt.get_node_type () != Json.NodeType.VALUE || elt.get_string () == null) {
......@@ -287,6 +288,11 @@ namespace Poulp {
builder.end_object ();
}
if (this.library) {
builder.set_member_name ("library");
builder.add_boolean_value (this.library);
}
if (this.libs.size > 0) {
builder.set_member_name ("libs");
builder.begin_array ();
......@@ -433,6 +439,11 @@ namespace Poulp {
**/
public string output { get; set; }
/**
* A boolean to say if the project is a library.
*/
public bool library { get; set; default = false; }
/**
* The librairies to --pkg with this project.
*/
......
......@@ -27,7 +27,7 @@ namespace Poulp {
* Load the repository at a given URL.
*
* @param url The URL of the distant repository.
* @throws Throws an error if the URL is invalid.
* @throws GLib.Error Throws an error if the URL is invalid.
*/
public Repository (string url) throws Error {
try {
......
......@@ -107,7 +107,6 @@ namespace Poulp {
public async int spawn_async (string cmd) {
try {
string cmd = _cmd;
Manifest man = Manifest.get_for_current_project ();
// wet some useful environment variables before running anything
Environment.set_variable ("PROJECT_NAME", man.name, true);
......@@ -116,7 +115,7 @@ namespace Poulp {
Environment.set_variable ("PROJECT_LICENSE", man.license == null ? "" : man.license, true);
Environment.set_variable ("PROJECT_HOMEPAGE", man.homepage == null ? "" : man.homepage, true);
Environment.set_variable ("PROJECT_OUTPUT", man.output == null ? man.name + "-" + man.version : man.output, true);
// use PowerShell/bach to make it possible to use wildcards and Co.
#if WIN32
string[] shell = { "start", "powershell", "-NoExit", "-Command", cmd };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment