Commit 3fef78c7 authored by Bat's avatar Bat

Merge branch 'issue-38' into 'develop'

Use TOML for the manifests

Closes #38

See merge request !12
parents 7829f6ea 5bf87bad
Pipeline #12413 failed with stages
in 1 minute and 43 seconds
{
"name": "poulp",
"version": "0.1.0",
"description": "Vala projects and packages manager",
"license": "LGPLv3",
"author": "Baptiste Gelez <baptiste@gelez.xyz>",
"contributors": [
"SkyzohKey <skyzohkey@protonmail.com>"
],
"repository": "https://framagit.org/valse/poulp.git",
"dependencies": {
"gee-0.8": "*",
"gio-2.0": "*",
"json-glib-1.0": "*",
"libsoup-2.4": "*",
"semver": "*"
},
"files": [
"src/*.vala",
"src/commands/*.vala"
],
"compiler-params": [
"-X", "-w", "--enable-deprecated"
],
"scripts": {
"install": [
"install -m 777 build/poulp /usr/bin/"
],
"lib": [
"valac src/logger.vala src/manifest.vala src/repository.vala src/utils.vala --library=build/libpoulp -H build/libpoulp.h -X -fPIC -X -shared -o build/libpoulp.so --pkg semver-0.1.0 --pkg json-glib-1.0 --pkg gee-0.8 --pkg gio-2.0"
]
}
}
name = "poulp"
version = "0.1.0"
description = "Vala projects and packages manager"
license = "LGPLv3"
author = "Baptiste Gelez <baptiste@gelez.xyz>"
contributors = [
"SkyzohKey <skyzohkey@protonmail.com>"
]
repository = "https://framagit.org/valse/poulp.git"
files = [
"src/*.vala",
"src/commands/*.vala"
]
compiler-params = [
"-X", "-w", "--enable-deprecated"
]
[dependencies]
"gee-0.8" = "*"
"gio-2.0" = "*"
"json-glib-1.0" = "*"
"libsoup-2.4" = "*"
semver = "*"
toml-glib = "^0.1.0"
[scripts]
install = [
"install -m 777 build/poulp /usr/bin/"
]
# Multiple targets are not supported yet. :(
lib = [
"valac src/logger.vala src/manifest.vala src/repository.vala src/utils.vala --library=build/libpoulp -H build/libpoulp.h -X -fPIC -X -shared -o build/libpoulp.so --pkg semver-0.1.0 --pkg json-glib-1.0 --pkg gee-0.8 --pkg gio-2.0"
]
......@@ -27,7 +27,7 @@ namespace Poulp {
*/
public override async bool install () {
try {
Manifest man = new Manifest.for_path (Path.build_filename (this.project_path, "poulp.json"));
Manifest man = new Manifest.for_path (Path.build_filename (this.project_path, "poulp.toml"));
if (man.scripts.has_key ("pre-install")) {
return yield new ScriptRunner ().run (man.scripts["pre-install"]);
......
......@@ -34,7 +34,7 @@ namespace Poulp.Commands {
if (is_short) {
return "Builds your project.";
} else {
return "Builds your project, using the informations in poulp.json. Use --release to build your project without packaging dev-dependencies." +
return "Builds your project, using the informations in poulp.toml. Use --release to build your project without packaging dev-dependencies." +
"Use --install to install the generated output on your computer (it may require super-user privileges).";
}
}
......
......@@ -10,14 +10,14 @@ namespace Poulp.Commands {
/**
* Creates a new project template from JSON.
*
* @param json The JSON representation of this template
* @param toml The JSON representation of this template
Please register or sign in to reply
*/
public ProjectTemplate (Json.Object json) {
public ProjectTemplate (Json.Object toml) {
// we get data from the JSON to initialize the instance
Please register or sign in to reply
this.id = json.get_string_member ("id");
this.name = json.get_string_member ("name");
this.description = json.get_string_member ("description");
json.get_array_member ("files").foreach_element ((arr, index, elt) => {
this.id = toml.get_string_member ("id");
this.name = toml.get_string_member ("name");
this.description = toml.get_string_member ("description");
toml.get_array_member ("files").foreach_element ((arr, index, elt) => {
this.files.add (elt.get_string ());
});
}
......@@ -72,9 +72,9 @@ namespace Poulp.Commands {
next_is_tmpl = (arg == "-t" || arg == "--template");
}
// we check if a poulp.json file isn't already here
if (FileUtils.test ("poulp.json", FileTest.EXISTS)) { // If we already have a package file, warn the user.
Logger.logc (LogColor.BOLD_YELLOW, "A poulp.json file already exists for this folder. It will be overriden.");
// we check if a poulp.toml file isn't already here
if (FileUtils.test ("poulp.toml", FileTest.EXISTS)) { // If we already have a package file, warn the user.
Logger.logc (LogColor.BOLD_YELLOW, "A poulp.toml file already exists for this folder. It will be overriden.");
bool proceed = Logger.askyn ("Are you sure you want to proceed anyway?");
if (proceed == false) {
Logger.logc (LogColor.RED, "Project creation aborted.");
......@@ -85,7 +85,7 @@ namespace Poulp.Commands {
Logger.logc (LogColor.BOLD_BLUE, "# Creating a new Vala project");
Manifest man = new Manifest.custom ("my-project"); // the manifest of the new project. It will be writen in `poulp.json` at the end of this method
Manifest man = new Manifest.custom ("my-project"); // the manifest of the new project. It will be writen in `poulp.toml` at the end of this method
ProjectTemplate template = null;
// Ask for project name.
......@@ -124,9 +124,9 @@ namespace Poulp.Commands {
// template
var prjs = new ArrayList<ProjectTemplate> ();
// we read the templates from `projects.json` and we display them
// we read the templates from `projects.toml` and we display them
try {
string projects_path = Path.build_filename (get_poulp_dir (), "projects", "projects.json");
string projects_path = Path.build_filename (get_poulp_dir (), "projects", "projects.toml");
string projects;
FileUtils.get_contents (projects_path, out projects);
Json.Parser parser = new Json.Parser ();
......@@ -194,11 +194,11 @@ namespace Poulp.Commands {
}
}
// we copy data from the `poulp.json` of the template if needed.
// we copy data from the `poulp.toml` of the template if needed.
if (template != null) {
try {
string tmpl_dir = Path.build_filename (get_poulp_dir (), "projects", template.id);
Manifest tmpl_man = new Manifest.for_path (Path.build_filename (tmpl_dir, "poulp.json"));
Manifest tmpl_man = new Manifest.for_path (Path.build_filename (tmpl_dir, "poulp.toml"));
man.dependencies = tmpl_man.dependencies;
man.keywords = tmpl_man.keywords;
} catch (Error err) {
......@@ -209,12 +209,12 @@ namespace Poulp.Commands {
// Check if the project already contains source files, if so add them to man.files
man.add_files (Environment.get_current_dir ());
// Let's generate the project json.
string json = man.to_json_string ();
// Let's generate the project toml.
string toml = man.to_toml_string ();
Logger.logc (LogColor.BOLD_BLUE, "\n# Project overview: ");
Logger.log ("The following poulp.json will be generated: ");
Logger.log (json);
Logger.log ("The following poulp.toml will be generated: ");
Logger.log (toml);
if (man.repository != null) {
Logger.log ("A new Git repository will also be created.");
}
......@@ -235,8 +235,8 @@ namespace Poulp.Commands {
print (" [OK]\n");
}
}
// write `poulp.json`
FileUtils.set_contents (Path.build_filename (Environment.get_current_dir (), "poulp.json"), json);
// write `poulp.toml`
FileUtils.set_contents (Path.build_filename (Environment.get_current_dir (), "poulp.toml"), toml);
yield spawn_async ("git init");
if (man.repository != null) {
......@@ -249,7 +249,7 @@ namespace Poulp.Commands {
LogColor.YELLOW, "poulp build", LogColor.BLUE
);
} catch (Error err) {
Logger.log_error ("Generating poulp.json failed. Error: %s", err.message);
Logger.log_error ("Generating poulp.toml failed. Error: %s", err.message);
}
} else {
Logger.logc (LogColor.BOLD_RED, "Project creation aborted.");
......
......@@ -35,7 +35,7 @@ namespace Poulp.Commands {
pkgs.add (arg);
}
}
if (pkgs.size == 0) { // no packages -> we use those in the `poulp.json`
if (pkgs.size == 0) { // no packages -> we use those in the `poulp.toml`
try {
bool res = true;
foreach (var dep in Manifest.get_for_current_project ().dependencies.entries) {
......@@ -111,95 +111,7 @@ namespace Poulp.Commands {
}
// we install the package
<<<<<<< HEAD
try {
bool installed = false;
foreach (Repository repo in this.repositories) {
foreach (Package package in repo.libs) {
if (pkg == package.name && package.manifest.version in required) { // we try to find the package in the distant repositories
foreach (string file in package.get_files_for_platform (platform)) { // we get files to download
string url = Path.build_path ("/", repo.url, package.name, file);
uint8[] distant = read_distant_file (url);
string dest_file = ".";
// we put each file in the good directory
if (file.has_suffix (".vapi") || file.has_suffix (".deps")) {
dest_file = vapi_dir;
} else if (file.has_suffix (".h")) {
dest_file = include_dir;
} else if (file.has_suffix (".so") || file.has_suffix (".o") || file.has_suffix (".dll")) {
dest_file = lib_dir;
} else if (file.has_suffix (".pc")) {
dest_file = pc_dir;
}
dest_file = Path.build_filename (dest_file, file);
if (verbose) {
print ("Installing %s to %s\n", url, dest_file);
}
FileUtils.set_data (dest_file, distant);
}
if (!no_templates) {
// Project templates
try {
// Open local projects/projects.json file
string projects_json_path = Path.build_filename (get_poulp_dir (), "projects", "projects.json");
string projects_json;
FileUtils.get_contents (projects_json_path, out projects_json);
Json.Parser local_parser = new Json.Parser ();
local_parser.load_from_data (projects_json);
Json.Array local_projects = local_parser.get_root ().get_array ();
// Open distant projects/projects.json file
string projects_json_url = Path.build_path ("/", repo.url, package.name, "projects", "projects.json");
string distant_prjs_list = (string) read_distant_file (projects_json_url);
Json.Parser dist_parser = new Json.Parser ();
dist_parser.load_from_data (distant_prjs_list);
// Copy distants projects templates
dist_parser.get_root ().get_array ().foreach_element ((arr, index, elt) => {
try {
local_projects.add_object_element (elt.get_object ());
// Copy files
string id = elt.get_object ().get_string_member ("id");
// Create the directory where files will be copied
string parent_path = Path.build_filename (get_poulp_dir (), "projects", id);
File dir = File.new_for_path (parent_path);
dir.make_directory ();
elt.get_object ().get_array_member ("files").foreach_element ((array, i, elmt) => {
try {
string url = Path.build_path ("/", repo.url, package.name, "projects", id, elmt.get_string ());
FileUtils.set_data (Path.build_filename (parent_path, elmt.get_string ()), read_distant_file (url));
} catch (Error err) {
Logger.log_error (err.message);
}
});
} catch (Error err) {
Logger.log_error (err.message);
}
});
Json.Generator gen = new Json.Generator ();
Json.Node root = new Json.Node (Json.NodeType.ARRAY);
root.set_array (local_projects);
gen.root = root;
gen.pretty = true;
gen.to_file (projects_json_path);
} catch (Error err) {
if (verbose) {
Logger.log_error (err.message);
}
}
// File templates
try {
// Open local files/files.json file
string files_json_path = Path.build_filename (get_poulp_dir (), "files", "files.json");
string files_json;
FileUtils.get_contents (files_json_path, out files_json);
Json.Parser local_parser = new Json.Parser ();
local_parser.load_from_data (files_json);
Json.Array local_files = local_parser.get_root ().get_array ();
=======
bool success = yield this.installer.install (pkg, required);
>>>>>>> bf1a8d7237ace1276608de026520e52326acf303
if (success) {
Logger.logc (LogColor.BOLD_GREEN, @"✓ Successfuly installed $pkg.");
......
......@@ -32,9 +32,9 @@ namespace Poulp.Commands {
break;
}
FileUtils.set_contents ("poulp.json", man.to_json_string () + "\n");
FileUtils.set_contents ("poulp.toml", man.to_toml_string () + "\n");
yield spawn_async ("git add poulp.json");
yield spawn_async ("git add poulp.toml");
yield spawn_async (@"git commit -m '$(man.version) release' -q");
yield spawn_async (@"git tag -m 'Version $(man.version)' $(man.version)");
yield spawn_async ("git push poulp master --follow-tags");
......
......@@ -2,7 +2,7 @@ using Poulp;
namespace Poulp.Commands {
/**
* A command that runs a script defined in the `poulp.json` file of the project.
* A command that runs a script defined in the `poulp.toml` file of the project.
*/
public class RunCommand : Object, Command {
......
......@@ -35,7 +35,7 @@ namespace Poulp.Commands {
pkgs.add (arg);
}
}
if (pkgs.size == 0) { // no packages -> we use those in the `poulp.json`
if (pkgs.size == 0) { // no packages -> we use those in the `poulp.toml`
try {
bool res = true;
foreach (var dep in Manifest.get_for_current_project ().dependencies.entries) {
......@@ -61,17 +61,6 @@ namespace Poulp.Commands {
}
}
<<<<<<< HEAD
public async bool update (string name, Range required, string[] args) {
var current_ver = this.get_installed_version (name);
SemVer.Version? distant_ver = null;
foreach (var repo in this.repositories) {
foreach (var package in repo.libs) {
if (package.name == name) {
distant_ver = package.manifest.version;
break;
}
=======
/**
* Updates a package
*
......@@ -88,7 +77,6 @@ namespace Poulp.Commands {
if (pkg_exists != 0) {
Logger.log_error (@"The package $pkg isn't installed on your computer.");
return false;
>>>>>>> bf1a8d7237ace1276608de026520e52326acf303
}
if (this.installer.repositories.size == 0) {
......
......@@ -66,7 +66,7 @@ namespace Poulp {
return false;
}
yield spawn_async (@"git checkout $ver -q", clone_dir);
Builder bld = new Builder (new Manifest.for_path (Path.build_filename (clone_dir, "poulp.json")));
Builder bld = new Builder (new Manifest.for_path (Path.build_filename (clone_dir, "poulp.toml")));
BuildOutput build = yield bld.build (clone_dir);
yield build.install ();
} catch (Error err) {
......
This diff is collapsed.
......@@ -77,28 +77,13 @@ namespace Poulp {
Environment.set_variable ("PROJECT_DESCRIPTION", man.description == null ? "" : man.description, true);
Environment.set_variable ("PROJECT_LICENSE", man.license == null ? "" : man.license, true);
Environment.set_variable ("PROJECT_HOMEPAGE", man.homepage == null ? "" : man.homepage, true);
<<<<<<< HEAD
string output = man.name + "-" + man.version.to_string ();
bool opt_arg = false;
foreach (string opt in man.compiler_params) {
if (opt_arg) {
output = opt;
opt_arg = false;
}
if (opt == "-o" || opt == "--output") {
opt_arg = true;
}
}
=======
string output = man.output != null ? man.output : man.name + "-" + man.version.to_string ();
>>>>>>> bf1a8d7237ace1276608de026520e52326acf303
Environment.set_variable ("PROJECT_OUTPUT", output, true);
// use PowerShell/bach to make it possible to use wildcards and Co.
#if WIN32
cmd = "start powershell -NoExit -Command \"" + cmd.replace("\"", "\\\"") + "\"";
cmd = "start powershell -NoExit -Command \"" + cmd.replace ("\"", "\\\"") + "\"";
#else
cmd = "/bin/bash -c \"" + cmd.replace("\"", "\\\"") + "\"";
cmd = "/bin/bash -c \"" + cmd.replace ("\"", "\\\"") + "\"";
#endif
Process.spawn_command_line_sync (cmd, out stdout, out stderr, out exit_code);
// unset the variables
......
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