From d057a68a837d278f5dfe55a5dc3c4998e4f126f5 Mon Sep 17 00:00:00 2001 From: dacctal Date: Thu, 11 Jun 2026 20:07:13 +0000 Subject: cpdir checkpoint --- LICENSE | 186 ++++++++++----------- README.md | 106 ++++++------ include/create_pkg.h | 2 +- include/files.h | 1 + include/lua_state.h | 12 +- include/vars.h | 1 + src/build.c | 9 +- src/cla_parse.c | 50 +++--- src/copy_install.c | 124 -------------- src/create_pkg.c | 30 +++- src/declare.c | 2 +- src/fetch_git.c | 2 +- src/fetch_src.c | 25 ++- src/files.c | 83 ++++++++++ src/install_pkg.c | 83 +++++++--- src/is_updated.c | 2 +- src/link_install.c | 76 --------- src/list_pkgs.c | 11 +- src/lua_build.c | 29 +++- src/lua_state.c | 460 +++++++++++++++++++++++---------------------------- src/remove.c | 32 ---- src/remove_pkg.c | 47 +++--- src/update_all.c | 4 +- src/update_pkg.c | 4 +- src/vars.c | 13 +- 25 files changed, 649 insertions(+), 745 deletions(-) delete mode 100644 src/copy_install.c delete mode 100644 src/link_install.c delete mode 100644 src/remove.c diff --git a/LICENSE b/LICENSE index b35d535..c1538d5 100644 --- a/LICENSE +++ b/LICENSE @@ -38,96 +38,96 @@ You may charge a fee for the physical act of transferring a copy, and you may at 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. - b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. - c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - - These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. - - Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. - - In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, - b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, - c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) - - The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. - - If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. - - 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. - - 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. - - If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. - - It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. - - This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. - - 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - - one line to give the program's name and an idea of what it does. - Copyright (C) yyyy name of author - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see - . - - Also add information on how to contact you by electronic and paper mail. - - If the program is interactive, make it output a short notice like this when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details - type `show w'. This is free software, and you are welcome - to redistribute it under certain conditions; type `show c' - for details. - - The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. - - You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright - interest in the program `Gnomovision' - (which makes passes at compilers) written - by James Hacker. - - signature of Moe Ghoul, 1 April 1989 - Moe Ghoul, President of Vice - - This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + + In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + + The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + + If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + + 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + + 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + + If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + + It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + + This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + + 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + END OF TERMS AND CONDITIONS + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + one line to give the program's name and an idea of what it does. + Copyright (C) yyyy name of author + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see + . + + Also add information on how to contact you by electronic and paper mail. + + If the program is interactive, make it output a short notice like this when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details + type `show w'. This is free software, and you are welcome + to redistribute it under certain conditions; type `show c' + for details. + + The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. + + You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright + interest in the program `Gnomovision' + (which makes passes at compilers) written + by James Hacker. + + signature of Moe Ghoul, 1 April 1989 + Moe Ghoul, President of Vice + + This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. diff --git a/README.md b/README.md index 011efa2..a837135 100644 --- a/README.md +++ b/README.md @@ -140,22 +140,22 @@ This means that you can require any sub-file/directory, without wrestling with ` The overall structure of the configuration file looks like this: ```lua --[[ - - install directories - - this is where every package you - get with pkgit is installed, - with respect to each of it's - files' types: - - install_directories = { - bin = "...", - include = "...", - lib = "...", - src = "...", - } +- install directories - +this is where every package you +get with pkgit is installed, +with respect to each of it's +files' types: - it is recommended that you create - a prefix variable to prepend to - these directories, like so: +install_directories = { + bin = "...", + include = "...", + lib = "...", + src = "...", +} + +it is recommended that you create +a prefix variable to prepend to +these directories, like so: ]] local prefix = os.getenv("HOME").."/.local" -- for user-level installs install_directories = { @@ -166,11 +166,11 @@ install_directories = { } --[[ - - your repositories - - this is where you store your - own custom urls, dependencies, - and functions to install - whatever programs you desire. +- your repositories - +this is where you store your +own custom urls, dependencies, +and functions to install +whatever programs you desire. ]] repositories = { example_name = { @@ -187,18 +187,18 @@ repositories = { } } --[[ - pkgit also creates a 'repos.lua' file in - your config directory, which you can - require here to automatically add repos - that you install from. +pkgit also creates a 'repos.lua' file in +your config directory, which you can +require here to automatically add repos +that you install from. ]] require('repos') --[[ - - standard build systems - - will be auto-detected if required - functions aren't in 'repositories' - or a repo's 'bldit.lua' +- standard build systems - +will be auto-detected if required +functions aren't in 'repositories' +or a repo's 'bldit.lua' ]] build_systems = { ["filename.extension"] = { @@ -223,9 +223,9 @@ repositories = { ["yt-dlp"] = { url = "https://github.com/yt-dlp/yt-dlp" }, --[[ - for dependencies with names that contain illegal - characters in lua, you'll want to wrap them in - [""] to avoid problems. + for dependencies with names that contain illegal + characters in lua, you'll want to wrap them in + [""] to avoid problems. ]] ffmpeg = { url = "https://github.com/FFmpeg/FFmpeg" }, @@ -255,34 +255,34 @@ Example `bldit.lua` that works for pkgit: bldit_version = "0.0.0" package_version = "0.0.0" --[[ - versions have to be strings, - because some devs like to - have fun and whimsical - version numbers :D +versions have to be strings, +because some devs like to +have fun and whimsical +version numbers :D ]] global_dependencies = {} -- dependencies for all targets targets = { - default = { - dependencies = {}, - -- target-specific dependencies - build = function(name) - os.execute("make") - end, - pre_install = function() end, - install = function(prefix) - os.execute("make install") - end, - post_install = function() end, - uninstall = function() end, - } - --[[ - could also have targets for 'client' - or 'server.' useful for monorepos - and related use-cases. - ]] + default = { + dependencies = {}, + -- target-specific dependencies + build = function(name) + os.execute("make") + end, + pre_install = function() end, + install = function(prefix) + os.execute("make install") + end, + post_install = function() end, + uninstall = function() end, + } + --[[ + could also have targets for 'client' + or 'server.' useful for monorepos + and related use-cases. + ]] } ``` diff --git a/include/create_pkg.h b/include/create_pkg.h index dbd5bec..ed6da14 100644 --- a/include/create_pkg.h +++ b/include/create_pkg.h @@ -3,6 +3,6 @@ #include "vars.h" -Pkg create_pkg(const char *arg, const char *target); +Pkg create_pkg(const char *arg); #endif \ No newline at end of file diff --git a/include/files.h b/include/files.h index af00cbb..fac3a1e 100644 --- a/include/files.h +++ b/include/files.h @@ -1,4 +1,5 @@ #ifndef FILES #define FILES const char *get_filename_ext(const char *filename); +void cpdir(const char *path, const char *dest); #endif diff --git a/include/lua_state.h b/include/lua_state.h index b882cd7..f8af0a2 100644 --- a/include/lua_state.h +++ b/include/lua_state.h @@ -20,14 +20,14 @@ lua_State* get_lua_state(void); void cache_repos(void); void cache_build_systems(void); void cache_install_directories(void); -bool repo_build(const char *repository); -bool repo_install(const char *repository); -bool repo_uninstall(const char *repository); +bool repo_build(const char *repository, const char *target); +bool repo_install(const char *repository, const char *target); +bool repo_uninstall(const char *repository, const char *target); bool bldit(const char *target); bool bldit_install(const char *target); bool bldit_uninstall(const char *target); -bool config_build(const char *path); -bool config_install(const char *path); -bool config_uninstall(const char *path); +bool config_build(const char *path, const char *target); +bool config_install(const char *path, const char *target); +bool config_uninstall(const char *path, const char *target); #endif \ No newline at end of file diff --git a/include/vars.h b/include/vars.h index 3a56ef3..98cd829 100644 --- a/include/vars.h +++ b/include/vars.h @@ -53,6 +53,7 @@ typedef struct { extern bool is_symlink_install; extern bool is_verbose; extern bool is_auto_installed; +extern bool is_forced; extern bool config_exists; extern char home_dir[MAX_PATH_LEN]; diff --git a/src/build.c b/src/build.c index 02bbef4..549fe64 100644 --- a/src/build.c +++ b/src/build.c @@ -11,13 +11,8 @@ void build(Pkg pkg) { char original_dir[MAX_PATH_LEN]; getcwd(original_dir, MAX_PATH_LEN); - if (strcmp(pkg.src, original_dir) != 0) { - chdir(pkg.src); - } - - if (lua_build(pkg.name, pkg.target, pkg.src)) { - return; - } + if (strcmp(pkg.src, original_dir) != 0) chdir(pkg.src); + if (lua_build(pkg.name, pkg.target, pkg.src)) return; printf("%s no usable build system was found\n", print_error); exit(EXIT_FAILURE); diff --git a/src/cla_parse.c b/src/cla_parse.c index 9c62e07..4eae6f6 100644 --- a/src/cla_parse.c +++ b/src/cla_parse.c @@ -24,7 +24,7 @@ code #define NOT_ENOUGH_ARGS(arg, next) \ - printf("%sNot enough arguments! Try: `pkgit %s [%s]`\n", print_error, arg, \ + printf("%s Not enough arguments! Try: `pkgit %s [%s]`\n", print_error, arg, \ next) void cla_parse(int argc, char **argv) { @@ -38,6 +38,7 @@ void cla_parse(int argc, char **argv) { for (int i = 1; i < argc; i++) { COMMAND("--link", "-l", { is_symlink_install = true; }); COMMAND("--quiet", "-q", { is_verbose = false; }); + COMMAND("--force", "-f", { is_forced = true; }); } for (int i = 1; i < argc; i++) { @@ -50,32 +51,38 @@ void cla_parse(int argc, char **argv) { }); COMMAND("build", "b", { if (argv[i + 1]) { - if (argv[i + 2]) { - pkg = create_pkg(argv[i + 1], argv[i + 2]); - build(pkg); - } else if (!is_verbose) { - pkg = create_pkg(argv[i + 1], "quiet"); - build(pkg); + if (!is_verbose) { + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') continue; + pkg = create_pkg(argv[j]); + build(pkg); + } } else { - pkg = create_pkg(argv[i + 1], "default"); - build(pkg); + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') continue; + pkg = create_pkg(argv[j]); + build(pkg); + } } } else { - pkg = create_pkg(".", "default"); + pkg = create_pkg("."); build(pkg); } }); COMMAND("install", "i", { if (argv[i + 1]) { - if (argv[i + 2]) { - pkg = create_pkg(argv[i + 1], argv[i + 2]); - install_pkg(pkg); - } else if (!is_verbose) { - pkg = create_pkg(argv[i + 1], "quiet"); - install_pkg(pkg); + if (!is_verbose) { + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') continue; + pkg = create_pkg(argv[j]); + install_pkg(pkg); + } } else { - pkg = create_pkg(argv[i + 1], "default"); - install_pkg(pkg); + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') continue; + pkg = create_pkg(argv[j]); + install_pkg(pkg); + } } } else { NOT_ENOUGH_ARGS(argv[i], "url/pkg"); @@ -83,8 +90,11 @@ void cla_parse(int argc, char **argv) { }); COMMAND("remove", "r", { if (argv[i + 1]) { - pkg = create_pkg(argv[i + 1], "default"); - remove_pkg(pkg); + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') continue; + pkg = create_pkg(argv[j]); + remove_pkg(pkg); + } } else { NOT_ENOUGH_ARGS(argv[i], "url/pkg"); } diff --git a/src/copy_install.c b/src/copy_install.c deleted file mode 100644 index b1b56ff..0000000 --- a/src/copy_install.c +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "copy_install.h" -#include "vars.h" - -static int is_executable(const char *path) { return (access(path, X_OK) == 0); } - -static int is_dir(const char *path) { - struct stat st; - if (stat(path, &st) == 0) { - return S_ISDIR(st.st_mode); - } - return 0; -} - -static const char *get_extension(const char *path) { - const char *dot = strrchr(path, '.'); - return dot ? dot : ""; -} - -static int copy_file(const char *src, const char *dst) { - struct stat st; - if (stat(src, &st) != 0) - return -1; - - int src_fd = open(src, O_RDONLY); - if (src_fd < 0) - return -1; - - int dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode & 07777); - if (dst_fd < 0) { - close(src_fd); - return -1; - } - - char buf[8192]; - ssize_t n; - while ((n = read(src_fd, buf, sizeof(buf))) > 0) { - ssize_t written = 0; - while (written < n) { - ssize_t ret = write(dst_fd, buf + written, n - written); - if (ret < 0) { - close(src_fd); - close(dst_fd); - return -1; - } - written += ret; - } - } - - close(src_fd); - close(dst_fd); - return n == 0 ? 0 : -1; -} - -static void copy_install_recursive(const char *dir_path) { - DIR *dir = opendir(dir_path); - if (!dir) - return; - - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { - continue; - } - - char src_path[MAX_PATH_LEN]; - snprintf(src_path, sizeof(src_path), "%s/%s", dir_path, entry->d_name); - - if (is_dir(src_path)) { - if (strcmp(entry->d_name, ".git") != 0) { - copy_install_recursive(src_path); - } - continue; - } - - const char *ext = get_extension(entry->d_name); - - if (strncmp(ext, ".so", 3) == 0) { - char dest_path[MAX_PATH_LEN]; - snprintf(dest_path, sizeof(dest_path), "%s/%s", lib, entry->d_name); - if (!file_exists(dest_path)) { - copy_file(src_path, dest_path); - if (is_verbose) { - printf("%scopied library: %s\n", print_pkgit, src_path); - } - } - } else if (is_executable(src_path)) { - if (strcmp(ext, ".sample") != 0 && strcmp(entry->d_name, "bldit") != 0 && - strcmp(entry->d_name, "build.sh") != 0 && - strcmp(entry->d_name, "compile.sh") != 0) { - char dest_path[MAX_PATH_LEN]; - snprintf(dest_path, sizeof(dest_path), "%s/%s", bin, entry->d_name); - if (!file_exists(dest_path)) { - copy_file(src_path, dest_path); - if (is_verbose) { - printf("%scopied executable: %s\n", print_pkgit, src_path); - } - } - } - } else if (strcmp(ext, ".h") == 0) { - char dest_path[MAX_PATH_LEN]; - snprintf(dest_path, sizeof(dest_path), "%s/%s", inc, entry->d_name); - if (!file_exists(dest_path)) { - copy_file(src_path, dest_path); - if (is_verbose) { - printf("%scopied include: %s\n", print_pkgit, src_path); - } - } - } - } - - closedir(dir); -} - -void copy_install(const char *build_dir) { - copy_install_recursive(build_dir); -} diff --git a/src/create_pkg.c b/src/create_pkg.c index 36e9d10..cf92f75 100644 --- a/src/create_pkg.c +++ b/src/create_pkg.c @@ -4,13 +4,13 @@ #include #include "create_pkg.h" +#include "files.h" #include "lua_state.h" #include "name_from_url.h" #include "vars.h" -Pkg create_pkg(const char *arg, const char *target) { +Pkg create_pkg(const char *arg) { Pkg pkg = {0}; - pkg.target = target; pkg.ver = "HEAD"; pkg.is_local = false; @@ -23,10 +23,17 @@ Pkg create_pkg(const char *arg, const char *target) { char *new_arg = strdup(arg); if (!new_arg) exit(EXIT_FAILURE); char *argver = strchr(new_arg, '@'); + char *argtrg = strchr(new_arg, ','); if (argver) { pkg.ver = argver + 1; *argver = '\0'; } + if (argtrg) { + pkg.target = argtrg + 1; + *argtrg = '\0'; + } else { + pkg.target = "default"; + } bool is_in_repos = false; for (size_t i = 0; i < cached_repos_count; i++) { @@ -42,7 +49,7 @@ Pkg create_pkg(const char *arg, const char *target) { } else if (strcmp(new_arg, ".") == 0) { pkg.url = ""; getcwd(pkg.src, MAX_PATH_LEN); - pkg.name = name_from_url(pkg.url); + pkg.name = name_from_url(pkg.src); pkg.is_local = true; } else if (is_in_repos) { for (size_t i = 0; i < cached_repos_count; i++) { @@ -53,20 +60,27 @@ Pkg create_pkg(const char *arg, const char *target) { } pkg.name = strdup(new_arg); } else { - printf("%s'%s' is not a valid package\n", print_error, new_arg); + printf("%s '%s' is not a valid package\n", print_error, new_arg); exit(EXIT_FAILURE); } - if (strlen(pkg.name) > 4 && strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0) { + if (strlen(pkg.name) > 4 && + strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0) pkg.name[strlen(pkg.name) - 4] = '\0'; - } cache_install_directories(); if (!pkg.is_local) { char src_dir[MAX_PATH_LEN]; - snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", get_install_dir("src"), - pkg.name, pkg.ver); + snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", + get_install_dir("src"), pkg.name, pkg.ver); snprintf(pkg.src, MAX_PATH_LEN, "%s", src_dir); + } else { + const char *destination = strcat( + strdup(get_install_dir("src")), + strcat(strdup("/"), pkg.name) + ); + printf("%s\n", destination); + cpdir(pkg.src, destination); } return pkg; diff --git a/src/declare.c b/src/declare.c index 2ba42fb..d01468a 100644 --- a/src/declare.c +++ b/src/declare.c @@ -11,7 +11,7 @@ void declare() { init_lua_state(); cache_repos(); for (size_t i = 0; i < cached_repos_count; i++) { - Pkg pkg = create_pkg(cached_repos[i].source_value, "default"); + Pkg pkg = create_pkg(cached_repos[i].source_value); update_pkg(pkg); } } diff --git a/src/fetch_git.c b/src/fetch_git.c index 6353678..2d9e9a2 100644 --- a/src/fetch_git.c +++ b/src/fetch_git.c @@ -41,7 +41,7 @@ int fetch_git(Pkg pkg) { waitpid(pid, &status, 0); int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1; if (result != 0) { - printf("clone failed\n"); + printf("%s git clone failed\n", print_warning); } return result; diff --git a/src/fetch_src.c b/src/fetch_src.c index f03ae5d..8ad1ff5 100644 --- a/src/fetch_src.c +++ b/src/fetch_src.c @@ -9,7 +9,10 @@ #include "fetch_git.h" #include "vars.h" -static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { +static int remove_tree( + const char *fpath, const struct stat *sb, + int typeflag, struct FTW *ftwbuf +) { (void)sb; (void)ftwbuf; if (typeflag == FTW_F || typeflag == FTW_SL) { @@ -21,18 +24,30 @@ static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, s } void fetch_src(Pkg pkg) { - if (is_verbose) printf("%starget source directory: %s\n", print_pkgit, pkg.src); + if (is_verbose) printf( + "%s target source directory: %s\n", + print_pkgit, pkg.src + ); if (file_exists(pkg.src)) { - if (is_verbose) printf("%s%s already exists. deleting...\n", print_pkgit, pkg.src); + if (is_verbose) printf( + "%s %s already exists. deleting...\n", + print_pkgit, pkg.src + ); nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS); } if (strcmp(pkg.url, "") == 0) { - if (is_verbose) printf("%screating directory %s...\n", print_pkgit, pkg.src); + if (is_verbose) printf( + "%s creating directory %s...\n", + print_pkgit, pkg.src + ); mkdir_p(pkg.src); return; } if (fetch_git(pkg) == 0) { - if (is_verbose) printf("%scloned into %s...\n", print_pkgit, pkg.src); + if (is_verbose) printf( + "%s cloned into %s\n", + print_pkgit, pkg.src + ); return; } printf("%s no fetch methods worked.\n", print_error); diff --git a/src/files.c b/src/files.c index 86d9be4..5805d22 100644 --- a/src/files.c +++ b/src/files.c @@ -1,7 +1,90 @@ +#include +#include +#include #include +#include const char *get_filename_ext(const char *filename) { const char *dot = strrchr(filename, '.'); if(!dot || dot == filename) return ""; return dot + 1; } + +void cpdir(const char *path, const char *dest) { + DIR *dirp = opendir(path); + struct dirent *dirp_ent; + + struct stat dest_st; + stat(dest, &dest_st); + if (dest_st.st_mode && dest_st.st_mode == S_IFDIR) { + mkdir(dest, dest_st.st_mode); + } + + while ((dirp_ent = readdir(dirp))) { + if (dirp_ent->d_name[0] == '.' && + (strlen(dirp_ent->d_name) == 1 || + (strlen(dirp_ent->d_name) == 2 && + dirp_ent->d_name[1] == '.')) + ) continue; + char rfile_line[1024]; + struct stat st; + char *filename = malloc(sizeof(path)+sizeof(dirp_ent->d_name)+2); + snprintf( + filename, + sizeof(path)+sizeof(dirp_ent->d_name)+2, + "%s/%s", + path, dirp_ent->d_name + ); + printf("FILENAME: %s\n", filename); + stat(filename, &st); + if (st.st_mode) { + char *newfile = malloc(sizeof(dest)+sizeof(dirp_ent->d_name)+2); + snprintf( + newfile, + sizeof(dest)+sizeof(dirp_ent->d_name)+2, + "%s/%s", + dest, dirp_ent->d_name + ); + if (st.st_mode == S_IFDIR) { + printf("DIRECTORY\n"); + printf("NEWDIR: %s\n", newfile); + mkdir(newfile, st.st_mode); + cpdir(filename, newfile); + continue; + } + FILE *rfile = fopen(dirp_ent->d_name, "r"); + FILE *wfile = fopen(newfile, "w+"); + if (!rfile || !wfile) { continue; } + size_t ret = fread( + rfile_line, + //sizeof(*rfile_line), + //sizeof(rfile_line)/sizeof(rfile_line[0]), + 1, + 1024, + rfile + ); + if (ret != sizeof(rfile_line)/sizeof(rfile_line[0]) && ferror(rfile)) { + fprintf(stderr, "file read failed: %zu\n", ret); + continue; + } + size_t write = fwrite( + rfile_line, + //sizeof(rfile_line[0]), + 1, + ret, + wfile + ); + if (write != sizeof(rfile_line)/sizeof(rfile_line[0])) { + fprintf(stderr, "file write failed: %zu\n", ret); + continue; + } + if (feof(rfile)) { + fclose(rfile); + fclose(wfile); + continue; + } + free(newfile); + } + free(filename); + } +} diff --git a/src/install_pkg.c b/src/install_pkg.c index 8831499..c0809e8 100644 --- a/src/install_pkg.c +++ b/src/install_pkg.c @@ -7,65 +7,94 @@ #include "build.h" #include "fetch_src.h" #include "install_pkg.h" -// #include "copy_install.h" -// #include "link_install.h" #include "lua_state.h" #include "name_from_url.h" #include "vars.h" void install_pkg(Pkg pkg) { + if (is_directory(pkg.src)) { + if (!is_forced) { + if (is_verbose) printf( + "%s %s is already installed.\n", + print_skipped, pkg.name + ); + return; + } else { + if (is_verbose) printf( + "%s %s is already installed.\n", + print_warning, pkg.name + ); + } + } + if (!pkg.is_local) { - printf("%sfetching %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s fetching %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); fetch_src(pkg); if (is_verbose) - printf("%sfetched %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s fetched %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); } - printf("%sbuilding %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s building %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); build(pkg); if (is_verbose) - printf("%sbuilt %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s built %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); - printf("%sinstalling %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s installing %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); bool install_success = false; - if (!install_success && repo_install(pkg.name)) + if (!install_success && repo_install(pkg.name, pkg.target)) install_success = true; if (!install_success && bldit_install(pkg.target)) install_success = true; - if (!install_success && config_install(pkg.src)) + if (!install_success && config_install(pkg.src, pkg.target)) install_success = true; if (!install_success) { - printf("%sno install function availible for package: %s\n", print_error, - pkg.name); + printf( + "%s no install function availible for package: %s\n", + print_error, pkg.name + ); return; } - // is_auto_installed = true; - // if (is_auto_installed) { - // if (is_symlink_install) { - // link_install(pkg.src); - // } else { - // copy_install(pkg.src); - // } - // } - printf("%sinstalled %s%s%s\n", print_success, green, pkg.name, color_reset); + printf( + "%s installed %s%s%s\n", + print_success, green, pkg.name, color_reset + ); bool repo_exists = false; for (size_t i = 0; i < cached_repos_count; i++) { - char *repo_name = name_from_url(cached_repos[i].source_value); - if (strcmp(repo_name, pkg.name) == 0) { - repo_exists = true; - } + char *repo_name = name_from_url(cached_repos[i].source_key); + if (strcmp(repo_name, pkg.name) == 0) { repo_exists = true; } free(repo_name); } if (!repo_exists) { - printf("%sadding %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s adding %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); if (pkg.url && strlen(pkg.url) > 0) { add_repo(pkg.url, pkg.name); } - printf("%sadded %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf( + "%s added %s%s%s\n", + print_pkgit, green, pkg.name, color_reset + ); } else { if (is_verbose) - printf("%srepo already exists, done\n", print_pkgit); + printf("%s repo already exists, done\n", print_pkgit); } } \ No newline at end of file diff --git a/src/is_updated.c b/src/is_updated.c index 29b482d..5fce96b 100644 --- a/src/is_updated.c +++ b/src/is_updated.c @@ -10,7 +10,7 @@ bool is_updated(const char *src) { if (src && strlen(src) > 0 && chdir(src) != 0) { - return false; + return false; } char *output = cmd_out("git pull"); diff --git a/src/link_install.c b/src/link_install.c deleted file mode 100644 index 9f658d4..0000000 --- a/src/link_install.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "link_install.h" -#include "vars.h" - -static int is_executable(const char *path) { - return (access(path, X_OK) == 0); -} - -static int is_dir(const char *path) { - struct stat st; - if (stat(path, &st) == 0) { - return S_ISDIR(st.st_mode); - } - return 0; -} - -static const char* get_extension(const char *path) { - const char *dot = strrchr(path, '.'); - return dot ? dot : ""; -} - -void link_install(const char *build_dir) { - DIR *dir = opendir(build_dir); - if (!dir) return; - - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { - continue; - } - - char src_path[MAX_PATH_LEN]; - char link_path[MAX_PATH_LEN]; - snprintf(src_path, sizeof(src_path), "%s/%s", build_dir, entry->d_name); - - const char *ext = get_extension(entry->d_name); - - if (strncmp(ext, ".so", 3) == 0) { - snprintf(link_path, sizeof(link_path), "%s/%s", lib, entry->d_name); - if (!file_exists(link_path)) { - symlink(src_path, link_path); - if (is_verbose) { - printf("%slinked library: %s\n", print_pkgit, src_path); - } - } - } else if (is_executable(src_path) && !is_dir(src_path)) { - if (strcmp(entry->d_name, "bldit") != 0 && - strcmp(entry->d_name, "build.sh") != 0 && - strcmp(entry->d_name, "compile.sh") != 0) { - snprintf(link_path, sizeof(link_path), "%s/%s", bin, entry->d_name); - if (!file_exists(link_path)) { - symlink(src_path, link_path); - if (is_verbose) { - printf("%slinked executable: %s\n", print_pkgit, src_path); - } - } - } - } else if (strcmp(ext, ".h") == 0) { - snprintf(link_path, sizeof(link_path), "%s/%s", inc, entry->d_name); - if (!file_exists(link_path)) { - symlink(src_path, link_path); - if (is_verbose) { - printf("%slinked include: %s\n", print_pkgit, src_path); - } - } - } - } - - closedir(dir); -} \ No newline at end of file diff --git a/src/list_pkgs.c b/src/list_pkgs.c index 5d6fcce..6d4ba3f 100644 --- a/src/list_pkgs.c +++ b/src/list_pkgs.c @@ -12,12 +12,19 @@ void list_pkgs() { DIR* dir_ptr = opendir(src_code); if (dir_ptr == NULL) { - fprintf(stderr, "%scould not open %s\n", print_pkgit, src_code); + fprintf( + stderr, + "%s could not open %s\n", + print_pkgit, src_code + ); return; } while ((dirent_ptr = readdir(dir_ptr)) != NULL) { - if (strcmp(dirent_ptr->d_name, "..") == 0 || strcmp(dirent_ptr->d_name, ".") == 0) { continue; } + if ( + strcmp(dirent_ptr->d_name, "..") == 0 || + strcmp(dirent_ptr->d_name, ".") == 0 + ) continue; printf("%s\n", dirent_ptr->d_name); } } \ No newline at end of file diff --git a/src/lua_build.c b/src/lua_build.c index de82f83..1e90d3a 100644 --- a/src/lua_build.c +++ b/src/lua_build.c @@ -7,17 +7,34 @@ bool lua_build(const char *repository, const char *target, const char *path) { if (is_verbose) printf( - "%sattempting to use build function specified in 'repositories.%s'...\n", + "%s attempting init.lua: 'repositories.%s.build'\n", print_pkgit, repository ); + if (repo_build(repository, target)) { return true; } + if (is_verbose) printf( + "%s failed init.lua: 'repositories.%s.build'\n", + print_warning, repository + ); - if (repo_build(repository)) { return true; } - - if (is_verbose) printf("%sattempting to use build function specified in 'bldit.lua'...\n", print_pkgit); + if (is_verbose) printf( + "%s attempting bldit.lua\n", + print_pkgit + ); if (bldit(target)) { return true; } + if (is_verbose) printf( + "%s failed bldit.lua\n", + print_warning + ); - if (is_verbose) printf("%sattempting to use build functions specified in 'build_systems'...\n", print_pkgit); - if (config_build(path)) { return true; } + if (is_verbose) printf( + "%s attempting init.lua: 'build_systems'\n", + print_pkgit + ); + if (config_build(path, target)) { return true; } + if (is_verbose) printf( + "%s failed init.lua: 'build_systems'\n", + print_warning + ); return false; } \ No newline at end of file diff --git a/src/lua_state.c b/src/lua_state.c index 25e9a7b..c23eb92 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -37,11 +37,11 @@ void init_lua_state() { push_lua_path(L, lua_path); if (luaL_loadfile(L, config_file) || lua_pcall(L, 0, 0, 0)) { printf( - "%scannot run configuration script: %s\n", + "%s cannot run configuration script: %s\n", print_error, lua_tostring(L, -1) ); printf( - "%sto generate a configration file, head into the root directory of the pkgit source and run `make defconfig`\n", + "%s to generate a configration file, head into the root directory of the pkgit source and run `make defconfig`\n", print_pkgit ); exit(EXIT_FAILURE); @@ -49,7 +49,7 @@ void init_lua_state() { if (file_exists(repo_file)) { if (luaL_loadfile(L, repo_file) || lua_pcall(L, 0, 0, 0)) { printf( - "%scannot load repository file: %s\n", + "%s cannot load repository file: %s\n", print_error, lua_tostring(L, -1) ); lua_pop(L, 1); @@ -65,7 +65,7 @@ void init_bldit() { luaL_openlibs(B); if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { if (is_verbose) printf( - "%scannot run bldit script: %s\n", + "%s cannot run bldit script: %s\n", print_warning, lua_tostring(B, -1) ); return; @@ -89,7 +89,7 @@ void cache_install_directories() { } if (!lua_istable(L, -1)) { printf( - "%slua variable 'install_directories' is not a table.\n", + "%s init.lua: 'install_directories' is not a table.\n", print_error ); return; @@ -116,7 +116,7 @@ void install_dependencies(lua_State *L) { lua_getfield(L, -1, "version"); const char *dep_version = lua_tostring(L, -1); lua_pop(L, 1); - Pkg pkg = create_pkg(dep_url, "default"); + Pkg pkg = create_pkg(dep_url); pkg.ver = strdup(dep_version); const int top = lua_gettop(L); char cwd[PATH_MAX]; @@ -130,126 +130,136 @@ void install_dependencies(lua_State *L) { } } -bool repo_build(const char *repository) { - lua_getglobal(L, "repositories"); - if (!config_loaded || !lua_istable(L, -1)) { - if (is_verbose) printf( - "%slua variable 'repositories' is not a table.\n", - print_warning - ); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, repository); +bool target_loop_build(lua_State *L, const char* lua_file, const char *target) { + lua_getfield(L, -1, target); if (!lua_istable(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s' is not a table.\n", - print_warning, repository + "%s %s: 'targets.%s' is not a table.\n", + print_warning, lua_file, target ); - lua_pop(L, 2); + lua_pop(L, 1); return false; } - lua_getfield(L, -1, "dependencies"); - if (!lua_istable(L, -1)) { - if (is_verbose) printf( - "%s'repositories.%s.dependencies' is not a table.\n", - print_warning, repository - ); - } else { + if (lua_istable(L, -1)) { lua_pushnil(L); install_dependencies(L); } lua_pop(L, 1); - lua_getfield(L, -1, "build"); if (!lua_isfunction(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s.build' is not a function: %s\n", - print_warning, repository, lua_tostring(L, -1) + "%s %s: 'targets.%s.build' is not a function.\n", + print_warning, lua_file, target ); lua_pop(L, 3); return false; } if (lua_pcall(L, 0, 0, 0) != LUA_OK) { printf( - "%s'repositories.%s.build' failed: %s\n", - print_warning, repository, lua_tostring(L, -1) + "%s %s: 'targets.%s.build' failed: %s\n", + print_error, lua_file, target, lua_tostring(L, -1) ); lua_pop(L, 3); return false; } - lua_pop(L, 2); return true; } -bool repo_install(const char *repository) { - lua_getglobal(L, "repositories"); - if (!config_loaded || !lua_istable(L, -1)) { - if (is_verbose) printf("%slua variable 'repositories' is not a table.\n", print_warning); - lua_pop(L, 1); - return false; - } - lua_getfield(L, -1, repository); +bool target_loop_install(lua_State *L, const char* lua_file, const char *target) { + lua_getfield(L, -1, target); if (!lua_istable(L, -1)) { - if (is_verbose) printf("%s'repositories.%s' is not a table.\n", print_warning, repository); - lua_pop(L, 2); + if (is_verbose) printf( + "%s %s: 'targets.%s' is not a table.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); return false; } - lua_getfield(L, -1, "pre_install"); if (!lua_isfunction(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s.pre_install' is not a function.\n", - print_warning, repository + "%s %s: 'targets.%s.pre_install' is not a function.\n", + print_warning, lua_file, target ); } else if (lua_pcall(L, 0, 0, 0) != LUA_OK) { if (is_verbose) printf( - "%s'repositories.%s.pre_install' failed: %s\n", - print_warning, repository, lua_tostring(L, -1) + "%s %s: 'targets.%s.pre_install' failed: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) ); } lua_pop(L, 1); - lua_getfield(L, -1, "install"); if (!lua_isfunction(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s.install' is not a function.\n", - print_warning, repository + "%s %s: 'targets.%s.install' is not a function.\n", + print_warning, lua_file, target ); + lua_pop(L, 1); return false; } if (lua_pcall(L, 0, 0, 0) != LUA_OK) { if (is_verbose) printf( - "%s'repositories.%s.install' failed: %s\n", - print_warning, repository, lua_tostring(L, -1) + "%s %s: 'targets.%s.install' failed: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) ); + lua_pop(L, 1); + return false; } lua_pop(L, 1); - lua_getfield(L, -1, "post_install"); if (!lua_isfunction(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s.post_install' is not a function.\n", - print_warning, repository + "%s %s: 'targets.%s.post_install' is not a function.\n", + print_warning, lua_file, target ); } else if (lua_pcall(L, 0, 0, 0) != LUA_OK) { if (is_verbose) printf( - "%s'repositories.%s.post_install' failed: %s\n", - print_warning, repository, lua_tostring(L, -1) + "%s %s: 'targets.%s.post_install' failed: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) ); } + lua_pop(L, 1); + return true; +} - lua_pop(L, 2); +bool target_loop_uninstall(lua_State *L, const char *lua_file, const char *target) { + lua_getfield(L, -1, target); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s' is not a table.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, "uninstall"); + if (!lua_isfunction(L, -1)) { + if (is_verbose) printf( + "%s %s: 'targets.%s.uninstall' is not a function.\n", + print_warning, lua_file, target + ); + lua_pop(L, 1); + return false; + } + if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + if (is_verbose) printf( + "%s %s: 'targets.%s.uninstall' failed: %s\n", + print_warning, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 1); + return false; + } + lua_pop(L, 1); return true; } -bool repo_uninstall(const char *repository) { +bool repo_build(const char *repository, const char *target) { lua_getglobal(L, "repositories"); if (!config_loaded || !lua_istable(L, -1)) { if (is_verbose) printf( - "%slua variable 'repositories' is not a table.\n", + "%s init.lua: 'repositories' is not a table.\n", print_warning ); lua_pop(L, 1); @@ -258,32 +268,102 @@ bool repo_uninstall(const char *repository) { lua_getfield(L, -1, repository); if (!lua_istable(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s' is not a table.\n", + "%s init.lua: 'repositories.%s' is not a table.\n", print_warning, repository ); lua_pop(L, 2); return false; } - lua_getfield(L, -1, "uninstall"); - if (!lua_isfunction(L, -1)) { + lua_getfield(L, -1, "dependencies"); + if (!lua_istable(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s.uninstall' is not a function.\n", + "%s init.lua: 'repositories.%s.dependencies' is not a table.\n", + print_warning, repository + ); + } else { + lua_pushnil(L); + install_dependencies(L); + } + lua_pop(L, 1); + + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.targets' is not a table.\n", print_warning, repository ); return false; } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + bool target_loop_success = target_loop_build(L, "init.lua", target); + lua_pop(L, 3); + return target_loop_success; +} + +bool repo_install(const char *repository, const char* target) { + lua_getglobal(L, "repositories"); + if (!config_loaded || !lua_istable(L, -1)) { if (is_verbose) printf( - "%s'repositories.%s.uninstall' failed: %s\n", - print_warning, repository, lua_tostring(L, -1) + "%s init.lua: 'repositories' is not a table.\n", + print_warning ); + lua_pop(L, 1); return false; } - lua_pop(L, 1); + lua_getfield(L, -1, repository); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s' is not a table.\n", + print_warning, repository + ); + lua_pop(L, 2); + return false; + } + + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.targets' is not a table.\n", + print_warning, repository + ); + return false; + } + bool target_loop_success = target_loop_install(L, "init.lua", target); + lua_pop(L, 3); + return target_loop_success; +} +bool repo_uninstall(const char *repository, const char *target) { + lua_getglobal(L, "repositories"); + if (!config_loaded || !lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories' is not a table.\n", + print_warning + ); + lua_pop(L, 1); + return false; + } + lua_getfield(L, -1, repository); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s' is not a table.\n", + print_warning, repository + ); + lua_pop(L, 2); + return false; + } + + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'repositories.%s.targets' is not a table.\n", + print_warning, repository + ); + return false; + } + bool target_loop_success = target_loop_uninstall(L, "init.lua", target); lua_pop(L, 2); - return true; + return target_loop_success; } bool bldit(const char *target) { @@ -291,24 +371,24 @@ bool bldit(const char *target) { luaL_openlibs(B); if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { - if (is_verbose) printf("%scannot run bldit script: %s\n", print_warning, lua_tostring(B, -1)); + if (is_verbose) printf("%s cannot run bldit script: %s\n", print_warning, lua_tostring(B, -1)); lua_close(B); return false; } lua_getglobal(B, "bldit_version"); if (!lua_isstring(B, -1)) { - if (is_verbose) printf("%sbldit variable 'bldit_version' is not a string.\n", print_warning); + if (is_verbose) printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning); } lua_getglobal(B, "package_version"); if (!lua_isstring(B, -1)) { - if (is_verbose) printf("%sbldit variable 'package_version' is not a string.\n", print_warning); + if (is_verbose) printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning); } - lua_getglobal(B, "global_dependencies"); + lua_getglobal(B, "dependencies"); if (!lua_istable(B, -1)) { - if (is_verbose) printf("%sbldit variable 'global_dependencies' is not a table.\n", print_warning); + if (is_verbose) printf("%s bldit.lua: 'dependencies' is not a table.\n", print_warning); } else { lua_pushnil(B); install_dependencies(B); @@ -317,52 +397,15 @@ bool bldit(const char *target) { lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { - if (is_verbose) printf("%sbldit variable 'targets' is not a table.\n", print_warning); - lua_close(B); - return false; - } - - lua_getfield(B, -1, target); - if (!lua_istable(B, -1)) { - if (is_verbose) printf("%sbldit variable 'targets.%s' is not a table.\n", print_warning, target); - lua_pop(B, 2); - lua_close(B); - return false; - } - - lua_getfield(B, -1, "dependencies"); - if (!lua_istable(B, -1)) { - if (is_verbose) printf("%sbldit variable 'targets.%s.dependencies' is not a table.\n", target, print_warning); - } else { - lua_pushnil(B); - install_dependencies(B); - } - lua_pop(B, 1); - - lua_getfield(B, -1, "build"); - if (!lua_isfunction(B, -1)) { - if (is_verbose) printf( - "%sbldit variable 'targets.%s.build' is not a function.\n", - print_warning, target - ); - lua_pop(B, 3); - lua_close(B); - return false; - } - if (lua_pcall(B, 0, 0, 0) != LUA_OK) { - printf( - "%s'targets.%s.build' failed: %s\n", - print_error, target, lua_tostring(B, -1) - ); - lua_pop(B, 1); - lua_pop(B, 2); + if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning); lua_close(B); return false; } + bool target_loop_success = target_loop_build(B, "bldit.lua", target); lua_pop(B, 2); lua_close(B); - return true; + return target_loop_success; } bool bldit_install(const char *target) { @@ -371,7 +414,7 @@ bool bldit_install(const char *target) { if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { if (is_verbose) printf( - "%scannot run bldit script: %s\n", + "%s cannot run bldit script: %s\n", print_warning, lua_tostring(B, -1) ); lua_close(B); @@ -381,7 +424,7 @@ bool bldit_install(const char *target) { lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { if (is_verbose) printf( - "%sbldit variable 'targets' is not a table.\n", + "%s bldit.lua: 'targets' is not a table.\n", print_warning ); lua_pop(B, 1); @@ -389,64 +432,10 @@ bool bldit_install(const char *target) { return false; } - lua_getfield(B, -1, target); - if (!lua_istable(B, -1)) { - if (is_verbose) printf( - "%sbldit variable 'targets.%s' is not a table.\n", - print_warning, target - ); - lua_pop(B, 2); - lua_close(B); - return false; - } - - lua_getfield(B, -1, "pre_install"); - if (!lua_isfunction(B, -1)) { - if (is_verbose) printf( - "%s'targets.%s.pre_install' is not a function.\n", - print_warning, target - ); - } - if (lua_pcall(B, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'targets.%s.pre_install' failed: %s\n", - print_warning, target, lua_tostring(B, -1) - ); - } - - lua_getfield(B, -1, "install"); - if (!lua_isfunction(B, -1)) { - if (is_verbose) printf( - "%sbldit variable 'targets.%s.install' is not a function.\n", - print_warning, target - ); - } else { - return false; - } - if (lua_pcall(B, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'targets.%s.install' failed: %s\n", - print_warning, target, lua_tostring(B, -1) - ); - } - - lua_getfield(B, -1, "post_install"); - if (!lua_isfunction(B, -1)) { - if (is_verbose) printf( - "%sbldit variable 'targets.%s.post_install' is not a function.\n", - print_warning, target - ); - } - if (lua_pcall(B, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'targets.%s.post_install' failed: %s\n", - print_warning, target, lua_tostring(B, -1) - ); - } - - lua_pop(B, 2); + bool target_loop_success = target_loop_install(B, "bldit.lua", target); + lua_pop(B, 1); lua_close(B); - return true; + return target_loop_success; } bool bldit_uninstall(const char *target) { @@ -455,7 +444,7 @@ bool bldit_uninstall(const char *target) { if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { if (is_verbose) printf( - "%scannot run bldit script: %s\n", + "%s cannot run bldit script: %s\n", print_warning, lua_tostring(B, -1) ); lua_close(B); @@ -465,7 +454,7 @@ bool bldit_uninstall(const char *target) { lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { if (is_verbose) printf( - "%sbldit variable 'targets' is not a table.\n", + "%s bldit.lua: 'targets' is not a table.\n", print_warning ); lua_close(B); @@ -475,7 +464,7 @@ bool bldit_uninstall(const char *target) { lua_getfield(B, -1, target); if (!lua_istable(B, -1)) { if (is_verbose) printf( - "%sbldit variable 'targets.%s' is not a table.\n", + "%s bldit.lua: 'targets.%s' is not a table.\n", print_warning, target ); lua_pop(B, 2); @@ -483,23 +472,14 @@ bool bldit_uninstall(const char *target) { return false; } - lua_getfield(B, -1, "uninstall"); - if (!lua_isfunction(B, -1)) { - if (is_verbose) printf( - "%sbldit variable 'targets.%s.uninstall' is not a function.\n", - print_warning, target - ); - return false; - } - if (lua_pcall(B, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'targets.%s.uninstall' failed: %s\n", - print_warning, target, lua_tostring(B, -1) - ); + lua_getglobal(B, "targets"); + if (!lua_istable(B, -1)) { + if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning); + lua_close(B); return false; } - - lua_pop(B, 2); + bool target_loop_success = target_loop_uninstall(B, "bldit.lua", target); + lua_pop(B, 1); lua_close(B); return true; } @@ -509,7 +489,7 @@ void cache_repos() { lua_getglobal(L, "repositories"); if (!config_loaded || !lua_istable(L, -1)) { printf( - "%slua variable 'repositories' is not a table.\n", + "%s init.lua: 'repositories' is not a table.\n", print_error ); lua_pop(L, 1); @@ -519,7 +499,7 @@ void cache_repos() { while (lua_next(L, -2) != 0) { const char *repo_name = lua_tostring(L, -2); if (!repo_name || !lua_istable(L, -1)) { - printf("%slua variable 'repositories.%s' is not a table\n", print_error, repo_name); + printf("%s init.lua: 'repositories.%s' is not a table\n", print_error, repo_name); lua_pop(L, 1); continue; } @@ -547,7 +527,7 @@ void cache_build_systems() { } if (!lua_istable(L, -1)) { - printf("%slua variable 'build_systems' is not a table.\n", print_error); + printf("%s init.lua: 'build_systems' is not a table.\n", print_error); return; } @@ -555,7 +535,7 @@ void cache_build_systems() { while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); if (lua_isfunction(L, -1) == 0) { - printf("%slua variable 'build_systems.%s' is not a function\n", print_error, key); + printf("%s init.lua: 'build_systems.%s' is not a function\n", print_error, key); lua_pop(L, 1); continue; } @@ -566,12 +546,13 @@ void cache_build_systems() { lua_pop(L, 1); } -bool config_build(const char *path) { +bool config_build(const char *path, const char *target) { lua_getglobal(L, "build_systems"); if (!config_loaded || !lua_istable(L, -1)) { lua_pop(L, 1); return false; } + bool target_loop_success = false; lua_pushnil(L); while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); @@ -585,30 +566,27 @@ bool config_build(const char *path) { lua_pop(L, 1); continue; } - lua_getfield(L, -1, "build"); - if (!lua_isfunction(L, -1)) { - lua_pop(L, 1); - continue; - } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf("%s init.lua: 'targets' is not a table.\n", print_warning); lua_pop(L, 1); continue; } + target_loop_success = target_loop_build(L, "init.lua", target); lua_pop(L, 1); - lua_pop(L, 1); - return true; } lua_pop(L, 1); - return false; + return target_loop_success; } -bool config_install(const char *path) { +bool config_install(const char *path, const char *target) { lua_getglobal(L, "build_systems"); if (!config_loaded || !lua_istable(L, -1)) { lua_pop(L, 1); return false; } lua_pushnil(L); + bool target_loop_success = false; while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); if (!lua_istable(L, -1)) { @@ -621,50 +599,30 @@ bool config_install(const char *path) { lua_pop(L, 1); continue; } - lua_getfield(L, -1, "pre_install"); - if (lua_isfunction(L, -1)) { - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'build_systems.%s.pre_install' is not available\n", - print_warning, key - ); - } - } else { lua_pop(L, 1); } - - lua_getfield(L, -1, "install"); - if (lua_isfunction(L, -1)) { - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'build_systems.%s.install' is not available\n", - print_warning, key - ); - } - } else { lua_pop(L, 1); } - - lua_getfield(L, -1, "post_install"); - if (!lua_isfunction(L, -1)) { - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - if (is_verbose) printf( - "%s'build_systems.%s.post_install' is not available\n", - print_warning, key - ); - } - } else { lua_pop(L, 1); } + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'build_systems.%s.targets' is not a table.\n", + print_warning, key + ); + lua_close(L); + return false; + } + target_loop_success = target_loop_install(L, "init.lua", target); lua_pop(L, 1); - lua_pop(L, 1); - return true; } lua_pop(L, 1); - return false; + return target_loop_success; } -bool config_uninstall(const char *path) { +bool config_uninstall(const char *path, const char *target) { lua_getglobal(L, "build_systems"); if (!config_loaded || !lua_istable(L, -1)) { lua_pop(L, 1); return false; } + bool target_loop_success = false; lua_pushnil(L); while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); @@ -679,20 +637,18 @@ bool config_uninstall(const char *path) { continue; } - lua_getfield(L, -1, "uninstall"); - if (!lua_isfunction(L, -1)) { - lua_pop(L, 1); - continue; - } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { - lua_pop(L, 1); - continue; + lua_getfield(L, -1, "targets"); + if (!lua_istable(L, -1)) { + if (is_verbose) printf( + "%s init.lua: 'build_systems.%s.targets' is not a table.\n", + print_warning, key + ); + lua_close(L); + return false; } - - lua_pop(L, 1); + target_loop_success = target_loop_uninstall(L, "init.lua", target); lua_pop(L, 1); - return true; } lua_pop(L, 1); - return false; + return target_loop_success; } diff --git a/src/remove.c b/src/remove.c deleted file mode 100644 index 1282d44..0000000 --- a/src/remove.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include -#include - -#include "files.h" -#include "vars.h" - -//void remove_pkg(Pkg pkg) { -// char* src_code = pkg.src; -// struct dirent* dirent_ptr; -// DIR* dir_ptr; -// -// if ((dir_ptr = opendir(src_code)) == NULL) { -// fprintf(stderr, "%scould not open %s\n", print_pkgit, src_code); -// } -// -// while ((dirent_ptr = readdir(dir_ptr)) != NULL) { -// struct stat stat_buf; -// FILE* file_ptr = fopen(dirent_ptr->d_name, "r"); -// if (!file_ptr) { continue; } -// if (strcmp(get_filename_ext(dirent_ptr->d_name), ".so") == 0) { -// remove(strcat(map_get(&cached_install_directories, "lib"), strcat("/", dirent_ptr->d_name))); -// } else if (!access(dirent_ptr->d_name, X_OK) && stat_buf.st_mode != S_IFDIR) { -// remove(strcat(map_get(&cached_install_directories, "bin"), strcat("/", dirent_ptr->d_name))); -// } else if (strcmp(get_filename_ext(dirent_ptr->d_name), ".h") == 0) { -// remove(strcat(map_get(&cached_install_directories, "include"), strcat("/", dirent_ptr->d_name))); -// } -// } -// } -//} diff --git a/src/remove_pkg.c b/src/remove_pkg.c index 1dc39db..14e1f4a 100644 --- a/src/remove_pkg.c +++ b/src/remove_pkg.c @@ -9,8 +9,10 @@ #include "remove_pkg.h" #include "vars.h" -static int remove_installed(const char *src_path, const struct stat *sb, - int typeflag, struct FTW *ftwbuf) { +static int remove_installed( + const char *src_path, const struct stat *sb, + int typeflag, struct FTW *ftwbuf +) { (void)sb; (void)ftwbuf; @@ -60,28 +62,33 @@ static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, void remove_pkg(Pkg pkg) { if (!file_exists(pkg.src)) { - printf("%s%s is not installed!\n", print_pkgit, pkg.name); + printf("%s %s is not installed!\n", print_pkgit, pkg.name); return; } chdir(pkg.src); - if (repo_uninstall(pkg.name)) return; - if (bldit_uninstall(pkg.target)) return; - if (config_uninstall(pkg.src)) return; + bool uninstall_available = false; + if (!uninstall_available) if (repo_uninstall(pkg.name, pkg.target)) + uninstall_available = true; + if (!uninstall_available) if (bldit_uninstall(pkg.target)) + uninstall_available = true; + if (!uninstall_available) if (config_uninstall(pkg.src, pkg.target)) + uninstall_available = true; - printf("%sno uninstall function availible for package: %s\n", - print_error, pkg.name); - return; + if (!uninstall_available) printf( + "%s no uninstall function availible for package: %s\n", + print_error, pkg.name + ); - //nftw(pkg.src, remove_installed, 64, FTW_PHYS); - //const char *last_slash = strrchr(pkg.src, '/'); - //char target[MAX_PATH_LEN]; - //if (last_slash && last_slash != pkg.src) { - // size_t parent_len = last_slash - pkg.src; - // snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src); - //} else { - // snprintf(target, sizeof(target), "%s", pkg.src); - //} - //nftw(target, remove_tree, 64, FTW_DEPTH | FTW_PHYS); - //printf("%sremoved %s\n", print_pkgit, pkg.name); + nftw(pkg.src, remove_installed, 64, FTW_PHYS); + const char *last_slash = strrchr(pkg.src, '/'); + char target[MAX_PATH_LEN]; + if (last_slash && last_slash != pkg.src) { + size_t parent_len = last_slash - pkg.src; + snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src); + } else { + snprintf(target, sizeof(target), "%s", pkg.src); + } + nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS); + printf("%s removed %s\n", print_success, pkg.name); } \ No newline at end of file diff --git a/src/update_all.c b/src/update_all.c index 2d941eb..521b1d1 100644 --- a/src/update_all.c +++ b/src/update_all.c @@ -20,13 +20,13 @@ void update_all() { struct dirent* dirent_ptr; DIR* dir_ptr; if ((dir_ptr = opendir(get_install_dir("src"))) == NULL) { - fprintf(stderr, "%scould not open %s\n", print_pkgit, get_install_dir("src")); + fprintf(stderr, "%s could not open %s\n", print_pkgit, get_install_dir("src")); } while ((dirent_ptr = readdir(dir_ptr)) != NULL) { if (strcmp(dirent_ptr->d_name, "..") == 0 || strcmp(dirent_ptr->d_name, ".") == 0) continue; for (size_t i = 0; i < cached_repos_count; i++) { if (!strcmp(dirent_ptr->d_name, cached_repos[i].source_key) == 0) continue; - Pkg pkg = create_pkg(cached_repos[i].source_value, "default"); + Pkg pkg = create_pkg(cached_repos[i].source_value); update_pkg(pkg); } } diff --git a/src/update_pkg.c b/src/update_pkg.c index 093f25c..7511b54 100644 --- a/src/update_pkg.c +++ b/src/update_pkg.c @@ -7,9 +7,9 @@ void update_pkg(Pkg pkg) { if (is_updated(pkg.src)) { - printf("%s%s%s%s is already up to date.\n", print_skipped, green, pkg.name, color_reset); + printf("%s %s%s%s is already up to date.\n", print_skipped, green, pkg.name, color_reset); return; } - printf("%sUpdating package: %s%s%s\n", print_pkgit, green, pkg.name, color_reset); + printf("%s Updating package: %s%s%s\n", print_pkgit, green, pkg.name, color_reset); install_pkg(pkg); } \ No newline at end of file diff --git a/src/vars.c b/src/vars.c index 0aa7f78..a8199af 100644 --- a/src/vars.c +++ b/src/vars.c @@ -11,6 +11,7 @@ bool is_symlink_install = false; bool is_verbose = true; bool is_auto_installed = true; +bool is_forced = false; bool config_exists = false; char home_dir[MAX_PATH_LEN] = {0}; @@ -48,7 +49,7 @@ const char* get_install_dir(const char *key) { return ""; } -const char *version = "0.1.3"; +const char *version = "1.0.0"; const char *red = "\e[0;31m"; const char *green = "\e[0;32m"; @@ -162,27 +163,27 @@ void init_vars() { install_directories[4] = strdup(get_install_dir("src")); static char print_pkgit_buf[256]; - snprintf(print_pkgit_buf, sizeof(print_pkgit_buf), "%s[%s%s%s] %s", + snprintf(print_pkgit_buf, sizeof(print_pkgit_buf), "%s[%s%s%s]%s", bold_yellow, bold_magenta, "pkgit", bold_yellow, color_reset); print_pkgit = print_pkgit_buf; static char print_success_buf[256]; - snprintf(print_success_buf, sizeof(print_success_buf), "%s%s[SUCCESS] %s", + snprintf(print_success_buf, sizeof(print_success_buf), "%s%s [SUCCESS]%s", print_pkgit, green, color_reset); print_success = print_success_buf; static char print_skipped_buf[256]; - snprintf(print_skipped_buf, sizeof(print_skipped_buf), "%s%s[SKIP] %s", + snprintf(print_skipped_buf, sizeof(print_skipped_buf), "%s%s [SKIP]%s", print_pkgit, blue, color_reset); print_skipped = print_skipped_buf; static char print_warning_buf[256]; - snprintf(print_warning_buf, sizeof(print_warning_buf), "%s%s[WARN] %s", + snprintf(print_warning_buf, sizeof(print_warning_buf), "%s%s [WARN]%s", print_pkgit, yellow, color_reset); print_warning = print_warning_buf; static char print_error_buf[256]; - snprintf(print_error_buf, sizeof(print_error_buf), "%s%s[ERROR] %s", + snprintf(print_error_buf, sizeof(print_error_buf), "%s%s [ERROR]%s", print_pkgit, red, color_reset); print_error = print_error_buf; } -- cgit v1.2.3