Quality Assurance, Audit and Tags #14

Merged
kreyren merged 11 commits from QAaudit into central 2022-09-03 10:35:10 +02:00
33 changed files with 3407 additions and 2467 deletions

10
.gitignore vendored

@ -1,7 +1,3 @@
*.ss~
*.ss#*
.#*.ss
*.scm~
*.scm#*
.#*.scm
# Emacs teporary files
**~
**\#

@ -1,7 +1,6 @@
MIT License
Expat License
Copyright (C) 2021 Mike Gran <spk121@yahoo.com>
Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

636
GPLv3-LICENSE.md Normal file

@ -0,0 +1,636 @@
# GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
## Preamble
The GNU General Public License is a free, copyleft license for software and
other kinds of works.
The licenses for most software and other practical works are designed to take
away your freedom to share and change the works. By contrast, the GNU General
Public License is intended to guarantee your freedom to share and change all
versions of a program--to make sure it remains free software for all its users.
We, the Free Software Foundation, use the GNU General Public License for most
of our software; it applies also to any other work released this way by its
authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for them if you wish), that you
receive source code or can get it if you want it, that you can change the
software or use pieces of it in new free programs, and that you know you can do
these things.
To protect your rights, we need to prevent others from denying you these rights
or asking you to surrender the rights. Therefore, you have certain
responsibilities if you distribute copies of the software, or if you modify it:
responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must pass on to the recipients the same freedoms that you received.
You must make sure that they, too, receive or can get the source code. And you
must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps:
1. assert copyright on the software, and
2. offer you this License giving you legal permission to copy, distribute
and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that
there is no warranty for this free software. For both users' and authors' sake,
the GPL requires that modified versions be marked as changed, so that their
problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified
versions of the software inside them, although the manufacturer can do so. This
is fundamentally incompatible with the aim of protecting users' freedom to
change the software. The systematic pattern of such abuse occurs in the area of
products for individuals to use, which is precisely where it is most
unacceptable. Therefore, we have designed this version of the GPL to prohibit
the practice for those products. If such problems arise substantially in other
domains, we stand ready to extend this provision to those domains in future
versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States
should not allow patents to restrict development and use of software on
general-purpose computers, but in those that do, we wish to avoid the special
danger that patents applied to a free program could make it effectively
proprietary. To prevent this, the GPL assures that patents cannot be used to
render the program non-free.
The precise terms and conditions for copying, distribution and modification
follow.
## TERMS AND CONDITIONS
### 0. Definitions.
*This License* refers to version 3 of the GNU General Public License.
*Copyright* also means copyright-like laws that apply to other kinds of works,
such as semiconductor masks.
*The Program* refers to any copyrightable work licensed under this License.
Each licensee is addressed as *you*. *Licensees* and *recipients* may be
individuals or organizations.
To *modify* a work means to copy from or adapt all or part of the work in a
fashion requiring copyright permission, other than the making of an exact copy.
The resulting work is called a *modified version* of the earlier work or a work
*based on* the earlier work.
A *covered work* means either the unmodified Program or a work based on the
Program.
To *propagate* a work means to do anything with it that, without permission,
would make you directly or secondarily liable for infringement under applicable
copyright law, except executing it on a computer or modifying a private copy.
Propagation includes copying, distribution (with or without modification),
making available to the public, and in some countries other activities as well.
To *convey* a work means any kind of propagation that enables other parties to
make or receive copies. Mere interaction with a user through a computer
network, with no transfer of a copy, is not conveying.
An interactive user interface displays *Appropriate Legal Notices* to the
extent that it includes a convenient and prominently visible feature that
1. displays an appropriate copyright notice, and
2. tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the work
under this License, and how to view a copy of this License.
If the interface presents a list of user commands or options, such as a menu, a
prominent item in the list meets this criterion.
### 1. Source Code.
The *source code* for a work means the preferred form of the work for making
modifications to it. *Object code* means any non-source form of a work.
A *Standard Interface* means an interface that either is an official standard
defined by a recognized standards body, or, in the case of interfaces specified
for a particular programming language, one that is widely used among developers
working in that language.
The *System Libraries* of an executable work include anything, other than the
work as a whole, that (a) is included in the normal form of packaging a Major
Component, but which is not part of that Major Component, and (b) serves only
to enable use of the work with that Major Component, or to implement a Standard
Interface for which an implementation is available to the public in source code
form. A *Major Component*, in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system (if any) on
which the executable work runs, or a compiler used to produce the work, or an
object code interpreter used to run it.
The *Corresponding Source* for a work in object code form means all the source
code needed to generate, install, and (for an executable work) run the object
code and to modify the work, including scripts to control those activities.
However, it does not include the work's System Libraries, or general-purpose
tools or generally available free programs which are used unmodified in
performing those activities but which are not part of the work. For example,
Corresponding Source includes interface definition files associated with source
files for the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require, such as
by intimate data communication or control flow between those subprograms and
other parts of the work.
The Corresponding Source need not include anything that users can regenerate
automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
### 2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on
the Program, and are irrevocable provided the stated conditions are met. This
License explicitly affirms your unlimited permission to run the unmodified
Program. The output from running a covered work is covered by this License only
if the output, given its content, constitutes a covered work. This License
acknowledges your rights of fair use or other equivalent, as provided by
copyright law.
You may make, run and propagate covered works that you do not convey, without
conditions so long as your license otherwise remains in force. You may convey
covered works to others for the sole purpose of having them make modifications
exclusively for you, or provide you with facilities for running those works,
provided that you comply with the terms of this License in conveying all
material for which you do not control copyright. Those thus making or running
the covered works for you must do so exclusively on your behalf, under your
direction and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the
conditions stated below. Sublicensing is not allowed; section 10 makes it
unnecessary.
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure
under any applicable law fulfilling obligations under article 11 of the WIPO
copyright treaty adopted on 20 December 1996, or similar laws prohibiting or
restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention is
effected by exercising rights under this License with respect to the covered
work, and you disclaim any intention to limit operation or modification of the
work as a means of enforcing, against the work's users, your or third parties'
legal rights to forbid circumvention of technological measures.
### 4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it,
in any medium, provided that you conspicuously and appropriately publish on
each copy an appropriate copyright notice; keep intact all notices stating that
this License and any non-permissive terms added in accord with section 7 apply
to the code; keep intact all notices of the absence of any warranty; and give
all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may
offer support or warranty protection for a fee.
### 5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it
from the Program, in the form of source code under the terms of section 4,
provided that you also meet all of these conditions:
- a) The work must carry prominent notices stating that you modified it, and
giving a relevant date.
- b) The work must carry prominent notices stating that it is released under
this License and any conditions added under section 7. This requirement
modifies the requirement in section 4 to *keep intact all notices*.
- c) You must license the entire work, as a whole, under this License to
anyone who comes into possession of a copy. This License will therefore
apply, along with any applicable section 7 additional terms, to the whole
of the work, and all its parts, regardless of how they are packaged. This
License gives no permission to license the work in any other way, but it
does not invalidate such permission if you have separately received it.
- d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your work need
not make them do so.
A compilation of a covered work with other separate and independent works,
which are not by their nature extensions of the covered work, and which are not
combined with it such as to form a larger program, in or on a volume of a
storage or distribution medium, is called an *aggregate* if the compilation and
its resulting copyright are not used to limit the access or legal rights of the
compilation's users beyond what the individual works permit. Inclusion of a
covered work in an aggregate does not cause this License to apply to the other
parts of the aggregate.
### 6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4
and 5, provided that you also convey the machine-readable Corresponding Source
under the terms of this License, in one of these ways:
- a) Convey the object code in, or embodied in, a physical product (including
a physical distribution medium), accompanied by the Corresponding Source
fixed on a durable physical medium customarily used for software
interchange.
- b) Convey the object code in, or embodied in, a physical product (including
a physical distribution medium), accompanied by a written offer, valid for
at least three years and valid for as long as you offer spare parts or
customer support for that product model, to give anyone who possesses the
object code either
1. a copy of the Corresponding Source for all the software in the product
that is covered by this License, on a durable physical medium
customarily used for software interchange, for a price no more than your
reasonable cost of physically performing this conveying of source, or
2. access to copy the Corresponding Source from a network server at no
charge.
- c) Convey individual copies of the object code with a copy of the written
offer to provide the Corresponding Source. This alternative is allowed only
occasionally and noncommercially, and only if you received the object code
with such an offer, in accord with subsection 6b.
- d) Convey the object code by offering access from a designated place
(gratis or for a charge), and offer equivalent access to the Corresponding
Source in the same way through the same place at no further charge. You
need not require recipients to copy the Corresponding Source along with the
object code. If the place to copy the object code is a network server, the
Corresponding Source may be on a different server operated by you or a
third party) that supports equivalent copying facilities, provided you
maintain clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the Corresponding
Source, you remain obligated to ensure that it is available for as long as
needed to satisfy these requirements.
- e) Convey the object code using peer-to-peer transmission, provided you
inform other peers where the object code and Corresponding Source of the
work are being offered to the general public at no charge under subsection
6d.
A separable portion of the object code, whose source code is excluded from the
Corresponding Source as a System Library, need not be included in conveying the
object code work.
A *User Product* is either
1. a *consumer product*, which means any tangible personal property which is
normally used for personal, family, or household purposes, or
2. anything designed or sold for incorporation into a dwelling.
In determining whether a product is a consumer product, doubtful cases shall be
resolved in favor of coverage. For a particular product received by a
particular user, *normally used* refers to a typical or common use of that
class of product, regardless of the status of the particular user or of the way
in which the particular user actually uses, or expects or is expected to use,
the product. A product is a consumer product regardless of whether the product
has substantial commercial, industrial or non-consumer uses, unless such uses
represent the only significant mode of use of the product.
*Installation Information* for a User Product means any methods, procedures,
authorization keys, or other information required to install and execute
modified versions of a covered work in that User Product from a modified
version of its Corresponding Source. The information must suffice to ensure
that the continued functioning of the modified object code is in no case
prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as part of a
transaction in which the right of possession and use of the User Product is
transferred to the recipient in perpetuity or for a fixed term (regardless of
how the transaction is characterized), the Corresponding Source conveyed under
this section must be accompanied by the Installation Information. But this
requirement does not apply if neither you nor any third party retains the
ability to install modified object code on the User Product (for example, the
work has been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates for a
work that has been modified or installed by the recipient, or for the User
Product in which it has been modified or installed. Access to a network may be
denied when the modification itself materially and adversely affects the
operation of the network or violates the rules and protocols for communication
across the network.
Corresponding Source conveyed, and Installation Information provided, in accord
with this section must be in a format that is publicly documented (and with an
implementation available to the public in source code form), and must require
no special password or key for unpacking, reading or copying.
### 7. Additional Terms.
*Additional permissions* are terms that supplement the terms of this License by
making exceptions from one or more of its conditions. Additional permissions
that are applicable to the entire Program shall be treated as though they were
included in this License, to the extent that they are valid under applicable
law. If additional permissions apply only to part of the Program, that part may
be used separately under those permissions, but the entire Program remains
governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any
additional permissions from that copy, or from any part of it. (Additional
permissions may be written to require their own removal in certain cases when
you modify the work.) You may place additional permissions on material, added
by you to a covered work, for which you have or can give appropriate copyright
permission.
Notwithstanding any other provision of this License, for material you add to a
covered work, you may (if authorized by the copyright holders of that material)
supplement the terms of this License with terms:
- a) Disclaiming warranty or limiting liability differently from the terms of
sections 15 and 16 of this License; or
- b) Requiring preservation of specified reasonable legal notices or author
attributions in that material or in the Appropriate Legal Notices displayed
by works containing it; or
- c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in reasonable
ways as different from the original version; or
- d) Limiting the use for publicity purposes of names of licensors or authors
of the material; or
- e) Declining to grant rights under trademark law for use of some trade
names, trademarks, or service marks; or
- f) Requiring indemnification of licensors and authors of that material by
anyone who conveys the material (or modified versions of it) with
contractual assumptions of liability to the recipient, for any liability
that these contractual assumptions directly impose on those licensors and
authors.
All other non-permissive additional terms are considered *further restrictions*
within the meaning of section 10. If the Program as you received it, or any
part of it, contains a notice stating that it is governed by this License along
with a term that is a further restriction, you may remove that term. If a
license document contains a further restriction but permits relicensing or
conveying under this License, you may add to a covered work material governed
by the terms of that license document, provided that the further restriction
does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place,
in the relevant source files, a statement of the additional terms that apply to
those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a
separately written license, or stated as exceptions; the above requirements
apply either way.
### 8. Termination.
You may not propagate or modify a covered work except as expressly provided
under this License. Any attempt otherwise to propagate or modify it is void,
and will automatically terminate your rights under this License (including any
patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a
particular copyright holder is reinstated
- a) provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and
- b) permanently, if the copyright holder fails to notify you of the
violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated
permanently if the copyright holder notifies you of the violation by some
reasonable means, this is the first time you have received notice of violation
of this License (for any work) from that copyright holder, and you cure the
violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses
of parties who have received copies or rights from you under this License. If
your rights have been terminated and not permanently reinstated, you do not
qualify to receive new licenses for the same material under section 10.
### 9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy
of the Program. Ancillary propagation of a covered work occurring solely as a
consequence of using peer-to-peer transmission to receive a copy likewise does
not require acceptance. However, nothing other than this License grants you
permission to propagate or modify any covered work. These actions infringe
copyright if you do not accept this License. Therefore, by modifying or
propagating a covered work, you indicate your acceptance of this License to do
so.
### 10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a
license from the original licensors, to run, modify and propagate that work,
subject to this License. You are not responsible for enforcing compliance by
third parties with this License.
An *entity transaction* is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered work
results from an entity transaction, each party to that transaction who receives
a copy of the work also receives whatever licenses to the work the party's
predecessor in interest had or could give under the previous paragraph, plus a
right to possession of the Corresponding Source of the work from the
predecessor in interest, if the predecessor has it or can get it with
reasonable efforts.
You may not impose any further restrictions on the exercise of the rights
granted or affirmed under this License. For example, you may not impose a
license fee, royalty, or other charge for exercise of rights granted under this
License, and you may not initiate litigation (including a cross-claim or
counterclaim in a lawsuit) alleging that any patent claim is infringed by
making, using, selling, offering for sale, or importing the Program or any
portion of it.
### 11. Patents.
A *contributor* is a copyright holder who authorizes use under this License of
the Program or a work on which the Program is based. The work thus licensed is
called the contributor's *contributor version*.
A contributor's *essential patent claims* are all patent claims owned or
controlled by the contributor, whether already acquired or hereafter acquired,
that would be infringed by some manner, permitted by this License, of making,
using, or selling its contributor version, but do not include claims that would
be infringed only as a consequence of further modification of the contributor
version. For purposes of this definition, *control* includes the right to grant
patent sublicenses in a manner consistent with the requirements of this
License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent
license under the contributor's essential patent claims, to make, use, sell,
offer for sale, import and otherwise run, modify and propagate the contents of
its contributor version.
In the following three paragraphs, a *patent license* is any express agreement
or commitment, however denominated, not to enforce a patent (such as an express
permission to practice a patent or covenant not to sue for patent
infringement). To *grant* such a patent license to a party means to make such
an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the
Corresponding Source of the work is not available for anyone to copy, free of
charge and under the terms of this License, through a publicly available
network server or other readily accessible means, then you must either
1. cause the Corresponding Source to be so available, or
2. arrange to deprive yourself of the benefit of the patent license for this
particular work, or
3. arrange, in a manner consistent with the requirements of this License, to
extend the patent license to downstream recipients.
*Knowingly relying* means you have actual knowledge that, but for the patent
license, your conveying the covered work in a country, or your recipient's use
of the covered work in a country, would infringe one or more identifiable
patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you
convey, or propagate by procuring conveyance of, a covered work, and grant a
patent license to some of the parties receiving the covered work authorizing
them to use, propagate, modify or convey a specific copy of the covered work,
then the patent license you grant is automatically extended to all recipients
of the covered work and works based on it.
A patent license is *discriminatory* if it does not include within the scope of
its coverage, prohibits the exercise of, or is conditioned on the non-exercise
of one or more of the rights that are specifically granted under this License.
You may not convey a covered work if you are a party to an arrangement with a
third party that is in the business of distributing software, under which you
make payment to the third party based on the extent of your activity of
conveying the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory patent
license
- a) in connection with copies of the covered work conveyed by you (or copies
made from those copies), or
- b) primarily for and in connection with specific products or compilations
that contain the covered work, unless you entered into that arrangement, or
that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied
license or other defenses to infringement that may otherwise be available to
you under applicable patent law.
### 12. No Surrender of Others' Freedom.
If 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 convey a covered work so
as to satisfy simultaneously your obligations under this License and any other
pertinent obligations, then as a consequence you may not convey it at all. For
example, if you agree to terms that obligate you to collect a royalty for
further conveying from those to whom you convey the Program, the only way you
could satisfy both those terms and this License would be to refrain entirely
from conveying the Program.
### 13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to
link or combine any covered work with a work licensed under version 3 of the
GNU Affero General Public License into a single combined work, and to convey
the resulting work. The terms of this License will continue to apply to the
part which is the covered work, but the special requirements of the GNU Affero
General Public License, section 13, concerning interaction through a network
will apply to the combination as such.
### 14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU
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
that a certain numbered version of the GNU General Public License *or any later
version* applies to it, you have the option of following the terms and
conditions either of that numbered version or of any later version published by
the Free Software Foundation. If the Program does not specify a version number
of the GNU General Public License, you may choose any version ever published by
the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the
GNU General Public License can be used, that proxy's public statement of
acceptance of a version permanently authorizes you to choose that version for
the Program.
Later license versions may give you additional or different permissions.
However, no additional obligations are imposed on any author or copyright
holder as a result of your choosing to follow a later version.
### 15. Disclaimer of Warranty.
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.
### 16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 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.
### 17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot
be given local legal effect according to their terms, reviewing courts shall
apply local law that most closely approximates an absolute waiver of all civil
liability in connection with the Program, unless a warranty or assumption of
liability accompanies a copy of the Program in return for a fee.
## 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 state 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 a brief idea of what it does.>
Copyright (C) <year> <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 3 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 <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like
this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program 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, your program's commands might
be different; for a GUI interface, you would use an *about box*.
You should also get your employer (if you work as a programmer) or school, if
any, to sign a *copyright disclaimer* for the program, if necessary. For more
information on this, and how to apply and follow the GNU GPL, see
[http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
The GNU 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. But first, please read
[http://www.gnu.org/philosophy/why-not-lgpl.html](http://www.gnu.org/philosophy/why-not-lgpl.html).

32
TAGS.org Normal file

@ -0,0 +1,32 @@
#+TITLE: TAGS
This project is tagging code using the following syntax:
#+BEGIN_SRC scheme-mode
;; MAIN_TAG-SUB_TAG(Tag Author Signature): Comment
#+END_SRC
Which in practice might be used as:
#+BEGIN_SRC scheme-mode
;; FIXME-QA(Krey): This code needs to be improved for whatever reason
(some (scheme (code)))
#+END_SRC
** List of Tags
- FIXME = Used to tag code that needs attention
- FIXME-QA = Used to tag code with Quality Assurance issues
- FIXME-DOCS = Tags code that needs documentation
- FIXME-TRANSLATE = Needs definition for handling translations
- DNR = Do Not Release - Usage prevents new version release, used to tag code that needs to be addressed prior
- DNM = Do Not Merge - Usage in merge/pull requests blocks syncing the code, used to tag code that needs to be addressed before merge can happen
- PROD/PRODUCTION = Code that should be considered prior to it's usage in production environment
- TRANSLATE = Needs to be translated
- WTF = Code that is not fully understood what it is doing
** Repository-wide tags
Tags that apply repository-wide
- FIXME(Krey): The repository is using things like =(format ... (green)..)= to make the text green, these should be renamed on e.g. =(font-green)=

1
examples/zz-README.org Normal file

@ -0,0 +1 @@
Example use of the project

@ -1,28 +0,0 @@
(define-module (make main)
#:use-module (ice-9 getopt-long)
#:export (main)
)
(define EXIT_SUCCESS 0)
(define EXIT_NOT_UP_TO_DATE 1)
(define EXIT_FAILURE 2)
(define option-spec
'((environment-overrides (single-char #\e))
(makefile (single-char #\f) (value #t))
(ignore-errors (single-char #\i))
(keep-going (single-char #\k))
(dry-run (single-char #\n))
(print-data-base (single-char #\p))
(question (single-char #\q))
(no-builtin-rules (single-char #\r))
(stop (single-char #\S))
(silent (single-char #\s))
(touch (single-char #\t))))
(define (main args)
(let ((options (getopt-long args option-spec)))
(write options)
(newline)
EXIT_SUCCESS))

3
pmake

@ -1,3 +0,0 @@
#!/usr/bin/env sh
exec guile -L . -e '(@ (make main) main)' -s "$0" "$@"
!#

20
pman Executable file

@ -0,0 +1,20 @@
#!/usr/bin/env sh
# shellcheck shell=sh # Written to comply with IEEE Std 1003.1-2017 (POSIX)
# The Project Manager ("pman") -- GNU Guile-based solution for project management
# Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
#
# This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
#
# This file incorporates work covered by the following copyright and permission notice:
#
# Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
exec guile -L . -e '(@ (pmake main) main)' -s "$0" "$@"
!#

@ -1,58 +0,0 @@
(define-module (potato builtins)
#:export (builtin-makevars
builtin-rules))
(define builtin-makevars
'(("MAKE" . "make")
("AR" . "ar")
("ARFLAGS" . "-rv")
("YACC" . "yacc")
("YFLAGS" . "")
("LEX" . "lex")
("LFLAGS" . "")
("LDFLAGS" . "")
("CC" . "cc")
("CFLAGS" . "-g -O2")
("FC" . "gfortran")
("FFLAGS" . "-O1")
("GUILE" . "guile")
("GUILD" . "guild")
("GFLAGS" . "-W2")))
#;(define builtin-rules
`((".c"
""
(,~ ,($ CC) ,($ CFLAGS) ,($ LDFLAGS) "-o" ,$@ ,$<))
(".f"
""
(,~ ,($ FC) ,($ FFLAGS) ,($ LDFLAGS) "-o" ,$@ ,$<))
(".sh"
""
(,~ "cp" ,$< ,$@)
(,~ "chmod a+x" ,$@))
(".c"
".o"
(,~ ,($ CC) ,($ CFLAGS) -c ,$<))
(".f"
".o"
(,~ ,($ FC) ,($ FFLAGS) -c ,$<))
(".y"
".o"
(,~ ,($ YACC) ,($ YFLAGS) ,$<))
(".l"
".o"
(,~ ,($ LEX) ,($ LFLAGS) ,$<)
(,~ ,($ CC) ,($ CFLAGS) "-c" lex.yy.c)
"rm -f lex.yy.c"
(,~ "mv lex.yy.o" ,$@))
(".y"
".c"
(,~ ,($ YACC) ,($ YFLAGS) ,$<)
(,~ "mv y.tab.c" ,$@))
(".l"
".c"
(,~ ,($ LEX) ,($ LDFLAGS) ,$<)
("mv lex.yy.c" ,$@))
(".scm"
".go"
(,~ ,($ GUILD) "compile" ,($ GFLAGS) ,$<))))

@ -1,80 +0,0 @@
-(define-module (potato exceptions)
#:use-module (ice-9 exceptions)
#:export (bad-key-type
bad-value-type
bad-proc-output
invalid-macro
not-a-regular-file
not-a-procedure
no-read-access-to-file
))
(define (make-bad-key-type origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Wrong type for key. Expecting string or procedure.")
(make-exception-with-irritants irritants)))
(define (bad-key-type origin irritant)
(raise-exception (make-bad-key-type origin irritant)))
(define (make-bad-value-type origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Wrong type for value. Expecting string or procedure.")
(make-exception-with-irritants irritants)))
(define (bad-value-type origin irritant)
(raise-exception (make-bad-value-type origin irritant)))
(define (make-bad-proc-output origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Procedure does not evaluate to a string.")
(make-exception-with-irritants irritants)))
(define (bad-proc-output origin irritant)
(raise-exception (make-bad-proc-output origin irritant)))
(define (make-invalid-macro origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Invalid macro format")
(make-exception-with-irritants irritants)))
(define (invalid-macro origin irritant)
(raise-exception (make-invalid-macro origin irritant)))
(define (make-not-a-regular-file origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Not a regular file")
(make-exception-with-irritants irritants)))
(define (not-a-regular-file origin irritant)
(raise-exception (make-not-a-regular-file origin irritant)))
(define (make-not-a-procedure origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Not a procedure")
(make-exception-with-irritants irritants)))
(define (not-a-procedure origin irritant)
(raise-exception (make-not-a-procedure origin irritant)))
(define (make-no-read-access-to-file origin irritants)
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Do not have permissions to read file")
(make-exception-with-irritants irritants)))
(define (no-read-access-to-file origin irritant)
(raise-exception (make-no-read-access-to-file origin irritant)))

@ -1,295 +0,0 @@
(define-module (potato make)
#:use-module (srfi srfi-1)
#:use-module (ice-9 exceptions)
#:use-module (ice-9 optargs)
#:use-module (ice-9 getopt-long)
#:use-module (ice-9 receive)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:export (initialize
execute)
#:re-export (%suffix-rules
lazy-assign ?=
assign :=
reference $ Q
reference-func $$
target-rule :
suffix-rule ->
target-name $@
target-basename $*
newer-prerequisites $? $$?
prerequisites $^ $$^
primary-prerequisite $<
string-compose ~
silent-compose ~@
always-execute-compose ~+
ignore-error-compose ~-
install-alternate-system-driver
))
(define %version "1.0")
(define %debug-argv0 #f)
;; #:re-export (
;; lazy-assign ?=
;; assign :=
;; ref $
;; target-rule :
;; suffix-rule ->
;; compose ~
;; ))
;; Asynchronous events.
;; SIGHUP, SIGTERM, SIGINT and SIGQUIT remove the current target
;; unless that target is a directory or the target is a prerequisite
;; of .PRECIOUS or the -n, -q, or -p option was specified. This
;; deletion shall be reported to the error port, then the default for
;; that action will continue.
;; .SILENT
;; The utility shall write all commands to the standard output unless
;; the -s option was specified, the command is prefixed with +, or
;; .SILENT has the current target as a prerequisite or has no pre
;; requisites.
;; Nothing to be done
;; If make was invoked but found no work to do, it shall write a
;; message to standard output that no action was taken
;; File Touched
;; If the -t option was specified, make shall write to standard
;; output a message for each file that was touched.
;; Verbosity is 0 = silent, 1 = terse, 2 = default, 3 = verbose
(define %verbosity 2)
(define %opt-verbose #f)
(define %opt-ignore-errors #f)
(define %opt-continue-on-error #f)
(define %targets '())
(define %initialized #f)
(define (critical spec . args)
(apply format (append (list #t spec) args)))
(define (print spec . args)
(when (>= %verbosity 2)
(apply format (append (list #t spec) args))))
(define (debug spec . args)
(when (>= %verbosity 3)
(apply format (append (list #t spec) args))))
(define option-spec
'((help (single-char #\h) (value #f))
(version (single-char #\v) (value #f))
(verbosity (single-char #\V) (value #t))
(environment (single-char #\e) (value #f))
(elevate-environment (single-char #\E) (value #f))
(builtins (single-char #\b) (value #f))
(ignore-errors (value #f))
(continue-on-error (single-char #\k) (value #f))
(no-execution (single-char #\n) (value #f))
(ascii (single-char #\A) (value #f))
(strict (single-char #\S) (value #f))
))
(define (display-help-and-exit argv0)
(format #t "~A [-hvqVeEbn] [KEY=VALUE ...] [targets ...]~%" argv0)
(format #t " -h, --help print help and exit~%")
(format #t " -v, --version print version and exit~%")
(format #t " -V 0..3, --verbosity=0..3~%")
(format #t " set output level from 0=silent to 3=verbose~%")
(format #t " -e, --environment use environment variables~%")
(format #t " -E, --elevate-environment~%")
(format #t " use environment variables and let~%")
(format #t " them override script variables~%")
(format #t " -b, --builtins~%")
(format #t " include some common variables and suffix rules~%")
(format #t " --ignore-errors~%")
(format #t " ignore all errors~%")
(format #t " -k, --continue-on-error~%")
(format #t " after an error, keep building other targets~%")
(format #t " -n, --no-execution~%")
(format #t " only execute rules marked as 'always execute'~%")
(format #t " -a, --ascii~%")
(format #t " ASCII only output and no colors~%")
(format #t " -S, --strict~%")
(format #t " causes some behaviours to throw errors~%")
(exit 0))
(define (display-version-and-exit argv0)
(format #t "~a~%" argv0)
(format #t " using potato make~a~%" %version)
(exit 0))
(define (parse-macros lst)
"Search for list for strings of the form KEY=VAR and return a list
of pairs of KEY VAL"
(filter-map
(lambda (str)
(let ((tok (string-split str #\=)))
(cond
((= 1 (length tok))
#f)
((= 2 (length tok))
(cons (car tok) (cadr tok)))
(else
(invalid-macro "parse-macros" str)))))
lst))
(define (parse-targets lst)
"Search the list for strings that don't have equals signs, and
return them in a list."
(filter-map
(lambda (str)
(if (string-index str #\=)
#f
str))
lst))
(define* (initialize #:optional
(arguments #f))
"Set up the options, rules, and makevars. If ARGUMENTS
is not set, it will use options, makevars, and targets as
specified by the command line. If it is set, it is
expected to be a list of strings that are command-line
arguments."
;; If left unset, assume user want all the command line arguments.
(when (not arguments)
(set! arguments (command-line)))
;; If the user has set it to '(), expecting a null environment, add
;; back in a filename, which is required.
(when (null? arguments)
(set! arguments (list (car (program-arguments)))))
;; We start of with the --help and --version command-line arguments.
(let ((options (getopt-long arguments option-spec))
(%opt-builtins #f)
(%opt-environment #f)
(%opt-elevate-environment #f)
(%opt-no-errors #f)
(%opt-continue-on-error #f)
(%opt-no-execution #f)
(%opt-ascii #f)
(%opt-strict #f))
(when (option-ref options 'help #f)
(display-help-and-exit (car arguments)))
(when (option-ref options 'version #f)
(display-version-and-exit (car arguments)))
;; Then, we do --environment, because we need to know that
;; before we start parsing MAKEFLAGS
(set! %opt-environment
(option-ref options 'environment #f))
;; Parse MAKEFLAGS before the command-line, because we want
;; command-line options to override MAKEFLAGS options.
(when %opt-environment
(let ((mf (getenv "MAKEFLAGS")))
(when mf
(let ((tokens (string-tokenize mf)))
(when (member "silent" tokens)
(set! %verbosity 0))
(when (member "terse" tokens)
(set! %verbosity 1))
(when (member "verbose" tokens)
(set! %verbosity 3))
(when (member "builtins" tokens)
(set! %opt-builtins #t))
(when (member "ascii" tokens)
(set! %opt-ascii #t))
(when (member "ignore-errors" tokens)
(set! %opt-ignore-errors #t))
(when (member "continue-on-error" tokens)
(set! %opt-continue-on-error #t))
(when (member "strict" tokens)
(set! %opt-strict #t))
(when (member "no-execution" tokens)
(set! %opt-no-execution #t))))))
;; Now the bulk of the command-line options.
(when (option-ref options 'verbosity #f)
(let ((verbosity (string->number (option-ref options 'verbosity #f))))
(when verbosity
(set! %verbosity verbosity))))
(when (option-ref options 'builtins #f)
(set! %opt-builtins #t))
(when (option-ref options 'elevate-environment #f)
(set! %opt-elevate-environment #t))
(when (option-ref options 'ignore-errors #f)
(set! %opt-ignore-errors #t))
(when (option-ref options 'continue-on-error #f)
(set! %opt-continue-on-error #t))
(when (option-ref options 'no-execution #f)
(set! %opt-no-execution #t))
(when (option-ref options 'ascii #f)
(set! %opt-ascii #t))
(when (option-ref options 'strict #f)
(set! %opt-strict #t))
;; Now that all the options are set, we can set up
;; the build environment.
(let ((extra (option-ref options '() '())))
(initialize-text %opt-ascii)
(initialize-makevars (parse-macros extra)
%opt-environment
%opt-elevate-environment
%opt-builtins
%opt-strict
%verbosity
%opt-ascii)
;; The remaining command-line words are the build targets that
;; we're going to tackle.
(set! %targets (parse-targets extra))
(initialize-rules %targets
%opt-builtins
%opt-ignore-errors
%opt-continue-on-error
%opt-no-execution
%verbosity
%opt-ascii)
(set! %initialized #t)
%targets
)))
(define* (execute #:key (targets '()))
"This function runs build actions. TARGETS, if provided, is a list
of target names to be executed. If TARGETS is not provided, the
targets listed on the parsed command-line are used."
;; First, let's figure out what targets we're building.
(unless %initialized
(critical "The initialize procedure was not called in this build script.~%")
(critical "Using an empty environment.~%"))
(when (null? targets)
(set! targets %targets))
(when (null? targets)
(debug "No build target was explicitely specified.~%")
(let ((rule (first-target-rule-name)))
(if rule
(begin
(debug "Using first rule ~a~A~a as the build target.~%" (lquo) rule (rquo))
(set! targets (list rule)))
;; else
(debug "There are no target rules in the recipe.~%"))))
;; Build each target in order.
(when (not (null? targets))
(let loop ((target (car targets))
(rest (cdr targets)))
(if (not (build target))
(begin
(print "The recipe for “~A” has failed.~%" target)
#f)
;; else
(begin
(print "The recipe “~A” finished successfully.~%" target)
(if (not (null? rest))
(loop (car rest) (cdr rest))
;; True if all targets are built successfully.
#t))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

@ -1,406 +0,0 @@
(define-module (potato makevars)
#:use-module (srfi srfi-1)
#:use-module (ice-9 format)
#:use-module (potato exceptions)
#:use-module (potato builtins)
#:use-module (potato text)
#:export (initialize-makevars
%makevars
%elevate-environment?
lazy-assign ?=
assign :=
reference $ Q
reference-func $$
dump-makevars
))
;; There are five priority levels
;; 1. defined - in the script itself
;; 2. command-line
;; 3. makeflags - in the MAKEFLAGS environment variable
;; 4. env - specified in the environment
;; 5. built-in - one of the built-in macros
;; The lower priority level always win, unless the '-e' flag was set
;; If the '-e' flag is set level 1 doesn't override level 3 and 4.
(define %level-name '("unknown" "script" "command-line" "makeflags" "environment" "built-in"))
(define %ascii? #f)
(define %makevars (make-hash-table))
(define %elevate-environment? #f)
(define %strict #f)
(define %verbose? #t)
(define (debug spec . args)
(when %verbose?
(apply format (append (list #t spec) args))))
(define (split-at-equals str)
"Splits the string at the first equals sign, ignoring
later equals signs."
(let ((idx (string-index str #\=)))
(if (and idx (> idx 0))
(cons (substring str 0 idx)
(substring str (1+ idx)))
;; else
#f)))
(define (string-append-with-spaces lst)
"Appends the strings in lst, adding spaces in between."
(fold
(lambda (elem prev)
(string-append prev " " elem))
(car lst)
(cdr lst)))
(define (override? old-priority new-priority)
"The logic of whether which makemacro priority levels can override
others."
(if %elevate-environment?
(if (and (or (= old-priority 2) (= old-priority 3) (= old-priority 4))
(= new-priority 1))
#f
;; else
(<= new-priority old-priority))
;; else
(<= new-priority old-priority)))
(define* (makevars-set key
#:optional (new-val "") (new-priority 1))
"Maybe add key / val to %makevars hash table, if there is sufficient
priority."
;; Note that VAL can be either a string or a procedure. If it is a
;; procedure, it is converted into a promise to be evaluated later.
(let* ((val&priority (hash-ref %makevars key))
(old-val (if (pair? val&priority) (cdr val&priority) #f))
(old-priority (if (pair? val&priority) (cdr val&priority) #f)))
(when (or (not old-val)
(override? old-priority new-priority))
(if (procedure? new-val)
(hash-set! %makevars key (cons (delay new-val) new-priority))
(hash-set! %makevars key (cons new-val new-priority)))
(when %verbose? (print-makevar key))))
*unspecified*)
(define (makevars-add-keyvals keyvals)
"Adds any suitable macros passed in from the command line, which
here are expected to be a list of key / val string pairs."
(for-each
(lambda (entry)
(let ((key (car entry))
(val (cdr entry)))
(unless (or (string=? key "SHELL")
(string=? key "MAKEFLAGS"))
(makevars-set key val 2))))
keyvals))
(define (makevars-add-makeflags)
"Adds any suitable environment variables found in the MAKEFLAGS
environment variable to the macro store"
(let ((makeflags (getenv "MAKEFLAGS")))
(when makeflags
(for-each
(lambda (entry)
(let* ((keyval (split-at-equals entry))
(key (if keyval (car keyval) #f))
(val (if keyval (cdr keyval) #f)))
(unless (or (not (string? key))
(string=? key "SHELL")
(string=? key "MAKEFLAGS"))
(makevars-set key val 3))))
(string-split makeflags #\space)))))
(define (makevars-add-environment)
"Adds any suitable environment variables to the macro store, but not
the value of MAKEFLAGS or SHELL."
(for-each
(lambda (entry)
(let* ((keyval (split-at-equals entry))
(key (if keyval (car keyval) #f))
(val (if keyval (cdr keyval) #f)))
(unless (or (string=? key "SHELL")
(string=? key "MAKEFLAGS"))
(makevars-set key val 4))))
(environ)))
(define (makevars-add-builtins)
"Adds the default macros to the store"
(for-each
(lambda (keyval)
(makevars-set (car keyval) (cdr keyval) 5))
builtin-makevars))
(define (print-makevar key)
(let ((val (hash-ref %makevars key)))
(let ((keyval-string
(if (zero? (string-length (car val)))
(string-copy key)
(string-append key " " (right-arrow) " " (car val)))))
;; Replace any control characters in VAL, like newline or tab
(set! keyval-string
(string-fold
(lambda (c str)
(string-append str
(if (char<? c #\space)
(C0 c)
(string c))))
""
keyval-string))
;; Truncate
(if (> (string-length keyval-string) 60)
(if %ascii?
(set! keyval-string
(string-append (substring keyval-string 0 57) "..."))
(set! keyval-string
(string-append (substring keyval-string 0 59) "…"))))
(let* ((space (make-string (- 64 (string-length keyval-string))
#\space))
(priority (cdr val))
(source-string (list-ref '("unknown"
"script"
"command line"
"MAKEFLAGS"
"environment"
"built-in")
priority)))
(display "Var: ")
(display keyval-string)
(display space)
(display source-string)
(newline)))))
(define (dump-makevars)
"Write out a list of the current makevars."
(when (not (zero? (hash-count (const #t) %makevars)))
(display (underline))
(display "Makevars")
(display (default))
(newline)
(let ((keyvals
(sort
(hash-map->list cons %makevars)
(lambda (a b)
(string<? (car a) (car b))))))
(for-each
(lambda (keyval)
(let ((key (car keyval))
(val (cdr keyval)))
(let ((keyval-string
(if (zero? (string-length (car val)))
(string-copy key)
(string-append key " " (right-arrow) " " (car val)))))
;; Replace any control characters in VAL, like newline or tab
(set! keyval-string
(string-fold
(lambda (c str)
(string-append str
(if (char<? c #\space)
(C0 c)
(string c))))
""
keyval-string))
;; Truncate
(if (> (string-length keyval-string) 60)
(if %ascii?
(set! keyval-string
(string-append (substring keyval-string 0 57) "..."))
(set! keyval-string
(string-append (substring keyval-string 0 59) "…"))))
(let* ((space (make-string (- 64 (string-length keyval-string))
#\space))
(priority (cdr val))
(source-string (list-ref '("unknown"
"script"
"command line"
"MAKEFLAGS"
"environment"
"built-in")
priority)))
(display " ")
(display keyval-string)
(display space)
(display source-string)
(newline)))))
keyvals))))
(define (initialize-makevars keyvals
environment?
elevate-environment?
builtins?
strict?
verbosity
ascii?)
(set! %elevate-environment? elevate-environment?)
(hash-clear! %makevars)
(set! %strict strict?)
(set! %verbose? (= verbosity 3))
(set! %ascii? ascii?)
(when builtins?
(makevars-add-builtins))
(when (or environment? elevate-environment?)
(makevars-add-environment)
(makevars-add-makeflags))
(makevars-add-keyvals keyvals))
;; API
(define* (lazy-assign key #:optional (val ""))
"This procedure sets an entry in the %makevars hash table.
KEY must be a string or a thunk that evaluates to a string. Likewise
VAL.
If KEY is a thunk, it is immediately evaluated to a string to use as
the key in the hash table entry.
If VAL is a thunk, it is stored as a *promise* to be evaluated
later. The promise will be evaluated the first time this key is
referenced.
If VAL is not given, the empty string will be used."
(when (procedure? key)
(set! key (key)))
(unless (string? key)
(set! key (format #f "~a" key)))
(makevars-set key (delay val)))
(define-syntax ?=
(lambda (stx)
(syntax-case stx ()
((_ key val)
#'(lazy-assign (symbol->string (syntax->datum #'key)) val))
((_ key)
#'(lazy-assign (symbol->string (syntax->datum #'key)))))))
(define* (assign key #:optional (val ""))
"This procedure sets an entry in the %makevars hash table.
KEY must be a string or a thunk that evaluates to a string. Likewise
VAL.
If KEY and/or VAL is a thunk, it is immediately evaluated to a
string to use as the key in the hash table entry.
If VAL is not given, the empty string will be used."
(when (procedure? key)
(set! key (key)))
(unless (string? key)
(set! key (format #f "~a" key)))
(when (procedure? val)
(set! val (val)))
(unless (string? val)
(set! val (format #f "~a" val)))
(makevars-set key val))
(define-syntax :=
(lambda (stx)
(syntax-case stx ()
((_ key val)
#'(assign (symbol->string (syntax->datum #'key)) val))
((_ key)
#'(assign (symbol->string (syntax->datum #'key)))))))
(define* (reference key quoted? #:optional (transformer #f))
"Looks up KEY in the %makevars hash table. KEY may be a string
or a procedure that evaluates to a string.
If the value of the key
in the hash table was a *promise* it will be forced,
evaluated, and set to that result.
If no transformer is supplied, the looked up value will be
returned.
TRANSFORMER, if
supplied, should be a procedure of one string argument that returns a
string. If a transformer is supplied, it will be applied to every
space-separated token in the looked-up value."
(when (and (not (string? key))
(not (procedure? key)))
(bad-key-type "reference" (list key)))
(when (procedure? key)
(set! key (key))
(unless (string? key)
(bad-proc-output "reference" key)))
(when (not (string? key))
(set! key (format #t "~a" key)))
(let* ((val&priority (hash-ref %makevars key))
(val (if (pair? val&priority) (car val&priority) #f))
(priority (if (pair? val&priority) (cdr val&priority) #f)))
(if (not val)
(if %strict
(error (format #t "There is no makevar for key ~a~%~!" key))
;; else
(if quoted?
"\"\""
""))
;; else
(begin
(cond
((promise? val)
(set! val (force val))
(cond
((string? val)
;; noop
#t)
((procedure? val)
(set! val (val)))
(else
(set! val (format #f "~a" val)))))
((string? val)
;; noop
#f)
(else
(set! val (format #f "~a" val))))
(hash-set! %makevars key (cons val priority))
(when %verbose? (print-makevar key))
(when (procedure? transformer)
(set! val (string-append-with-spaces
(map transformer
(string-tokenize val)))))
(if quoted?
(string-append "\"" val "\"")
val)))))
(define-syntax $
(lambda (stx)
(syntax-case stx ()
((_ key transformer)
#'(reference (symbol->string (syntax->datum #'key)) #f transformer))
((_ key)
#'(reference (symbol->string (syntax->datum #'key)) #f)))))
(define-syntax Q
(lambda (stx)
(syntax-case stx ()
((_ key transformer)
#'(reference (symbol->string (syntax->datum #'key)) #t transformer))
((_ key)
#'(reference (symbol->string (syntax->datum #'key)) #t)))))
(define (reference-func key)
"Looks up KEY in the %makevars hash table. KEY shall be a string
or a procedure that evaluates to a string.
If the value of the key
in the hash table was a *promise*, a procedure will be returned that,
when called, will call that promise. If the value of the key is
a string, a procedure will be returned that, when called, returns
that string."
(when (and (not (string? key))
(not (procedure? key)))
(bad-key-type "reference" (list key)))
(when (procedure? key)
(set! key (key))
(unless (string? key)
(bad-proc-output "reference" key))
(let* ((val&priority (hash-ref %makevars key))
(val (if (pair? val&priority) (cdr val&priority) #f)))
(if (not val)
#f
;; else
(begin
(if (promise? val)
(lambda ()
(let ((VAL (force val)))
;; FIXME: put verbose print here?
VAL))
;; else
(lambda ()
val)))))))
(define-syntax $$
(lambda (stx)
(syntax-case stx ()
((_ key)
#'(reference-func (symbol->string (syntax->datum #'key)))))))

@ -1,254 +0,0 @@
(define-module (potato parse-lib)
#:use-module (srfi srfi-1)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 optargs)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:export(
read-line-handle-escaped-newline
string-collapse-continuations
string-count-backslashes-at-end
string-count-matching-chars-at-end
string-find-char-unquote
string-find-preceding-backslashes
string-find-repeated-chars
string-next-token
string-remove-comments
string-starts-with?
string-shrink-whitespace
))
(define (read-line-handle-escaped-newline)
"Reads a line of text from the current input port.
If the line ends with an odd number of backslashes, the following line
is read and appended. The output string has newlines as line
terminators.
It returns two values
- the string containing the one or more lines read
- the number of lines read."
(let loop ((output "")
(nline 0))
(let ((line (read-line)))
(if (eof-object? line)
(values output nline)
;; else
(if (odd? (string-count-backslashes-at-end line))
(loop (string-append output (string-drop-right line 1) "\n")
(1+ nline))
;; else
(values (string-append output line "\n") (1+ nline)))))))
(define* (string-collapse-continuations str #:optional (squash-whitespace? #f))
"Returns a new string where backslash+newline is discarded, and
backslash+backslash+newline becomes backslash+newline. Any whitespace
after the newline may be squashed to a single space, if
squash-whitespace? is #t."
(let loop ((str str)
(newline-index (string-rindex str #\newline)))
(if (not newline-index)
(string-copy str)
;; else
(let* ((backslash-index (string-find-preceding-backslashes str newline-index))
(backslash-count (- newline-index backslash-index)))
(cond
((even? backslash-count)
;; We cut the number of backslashes in half, but, keep the newline.
(loop
(string-append
(substring str 0 backslash-index)
(make-string (quotient backslash-count 2) #\\)
(substring str newline-index))
(string-rindex str #\newline 0 backslash-index)))
(else
;; We cut the number of backslashes in half, remove a backslash
;; and newline, maybe squash any following whitespace.
(loop
(string-append
(substring str 0 backslash-index)
(make-string (quotient backslash-count 2) #\\)
(if squash-whitespace?
(string-shrink-whitespace
(substring str (1+ newline-index))
0)
(substring str (1+ newline-index))))
(string-rindex str #\newline 0 backslash-index))))))))
(define (string-count-backslashes-at-end str)
(string-count-matching-chars-at-end str #\\))
(define (string-count-matching-chars-at-end str c)
(if (not (string? str))
0
;; else
(let ((len (string-length str)))
(if (zero? len)
0
;; else
(let loop ((i (1- len))
(n 0))
(if (char=? (string-ref str i) c)
(if (zero? i)
(1+ n)
;; else
(loop (1- i) (1+ n)))
;; else
n))))))
(define* (string-find-char-unquote str #:optional (stop1 #f) (stop2 #f) #:key (blank #f) (ignorevars #f))
"Search string for an unquoted stopchar. Search until the end of
line is reached or until the blank char is reached. A backslash
quotes the stopchars and the blank.
The stopchars and blank may be #f, to ignore them in this call.
If ignorevars is #t, stopchars inside of variable references are ignored
Returns two values
- A string with the quoting backslashes removed
- The position of the first unquoted stopchar, or #f"
(let ((i 0)
(str2 (string-copy str))
(ret #f))
(while #t
(while (and (< i (string-length str))
(not (or
(and stop1 (eqv? (string-ref str i) stop1))
(and stop2 (eqv? (string-ref str i) stop2))
(and ignorevars (eqv? (string-ref str i) #\$))
(and blank (char-set-contains? char-set:blank (string-ref str i))))))
(set! i (1+ i)))
(when (>= i (string-length str))
(break))
;; If we stopped due to a variable reference, skip its contents
(when (and ignorevars (eqv? (string-ref str i) #\$))
(let ((openparen (false-if-exception (string-ref str (1+ i)))))
(set! i (+ i 2))
(when (or (eqv? openparen #\() (eqv? openparen #\{))
(let ((pcount 1)
(closeparen (if (eqv? openparen #\()
#\)
#\})))
(while (< i (string-length str))
(cond
((eqv? (string-ref str i) openparen)
(set! pcount (1+ pcount)))
((eqv? (string-ref str i) closeparen)
(set! pcount (1- pcount))
(when (zero? pcount)
(set! i (1+ i))
(break))))
(set! i (1+ i)))))
;; Skipped the variable reference: look for STOPCHARS again
(continue)))
(if (and (> i 0) (eqv? (string-ref str (1- i)) #\\))
;; Search for more backslashes
(let ((j 2))
(while (and (>= (- i j) 0)
(eqv? (string-ref str (- i j)) #\\))
(set! j (1+ j)))
(set! j (1- j))
;; Copy the string to swallow half the backslashes
(set! str2
(string-append
(string-take str (- i j))
(string-drop str (- i (quotient j 2)))))
(set! i (- i (quotient j 2)))
(when (even? j)
;; All the backslashes quoted each other; the stopchar
;; was unquoted
(set! ret #t)
(break))
(set! str str2))
;; else
;; no backslash in sight
(begin
(set! ret #t)
(break))))
(if ret
(values i str2)
(values #f #f))))
(define (string-find-preceding-backslashes str i)
"Given I, a position in a string, this returns a position,
of first of a range sequential backslashes that immediately precedes
that position in the string. If no backslashes precede that position,
I is returned."
(let loop ((j i))
(cond
((= j 0)
0)
((char=? (string-ref str (1- j)) #\\)
(loop (1- j)))
(else
j))))
(define (string-find-repeated-chars str c)
"Given a character c, this finds the position of of first instance
of the character in the string. If the character repeats, it returns,
as a pair, the position of the character, and the position after the
run of characters. If the character is not present, it returns #f"
(let ((i (string-index str c)))
(if (not i)
#f
;; else
(let ((len (string-length str)))
(if (= (1+ i) len)
(cons i (1+ i))
;; else
(let loop ((j (1+ i)))
(if (false-if-exception (char=? (string-ref str j) c))
(loop (1+ j))
;; else
(cons i j))))))))
(define (string-next-token str i)
"Given a position i, this returns the position of the first
non-whitespace character after i. If the end of line is reached,
it returns the length of the string."
(or
(string-index str
(lambda (c)
(char-set-contains? char-set:blank c))
i)
(string-length str)))
(define (string-remove-comments str)
"Returns a copy of str with any '#' comments removed"
(let ((i (string-find-char-unquote str #\#)))
(if i
(string-take str i)
(string-copy str))))
(define (string-shrink-whitespace str start)
"Given a string, and a location in a string, this returns a new copy
of string where all the whitespace beginning at location i is replaced
by a single space"
(let ((len (string-length str)))
(if (or (>= start len)
(not (char-set-contains? char-set:blank (string-ref str start))))
(string-copy str)
;; else
(let loop ((end start))
(cond
((>= end len)
(string-append (substring str 0 start) " "))
((char-set-contains? char-set:blank (string-ref str end))
(loop (1+ end)))
(else
(string-append (substring str 0 start) " " (substring str end))))))))
(define (string-starts-with? str c)
(char=? (string-ref str 0) c))

@ -1,107 +0,0 @@
(define-module (potato parse)
#:use-module (srfi srfi-1)
#:use-module (ice-9 receive)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:use-module (potato parse-lib)
#:export (parse _readline))
;; A makefile can contain rules, macro definitions, include lines,
;; and comments.
(define (parse filename)
(with-input-from-file filename _eval #:guess-encoding #t))
(define (_eval)
(let ((filenames #f)
(ignoring #f)
(commands '()))
(while #t
(receive (line nlines)
(read-line-handle-escaped-newline)
(cond
((zero? nlines)
(break))
((string-starts-with? line #\tab)
;; Shell-command lines
(when filenames
(when ignoring
(continue))
(set! commands (append commands (list line)))))
(else
(display
(string-trim-both
(string-remove-comments
(string-collapse-continuations line #t))))
(newline)))))))
(define (string-parse-variable-definition str i)
"Parse a string as a variable definition."
(let loop ((i (string-next-token str)))
(cond
((= i (string-length str))
(values i 'null))
((char=? (string-ref str i) #\#)
;; Comments aren't variable definitions.
(values i 'null))
((char=? (string-ref str i) #\$)
;; This begins a variable expansion reference.
(let* ((openparen (false-if-exception (string-ref str (1+ i))))
(closeparen (if (eqv? openparen #\()
#\)
(if (eqv? openparen #\{)
#\}
#f))))
(if (not closeparen)
(values i 'null)
;; else, skip over the matching closeparen
(begin
(let ((count 0))
(while #t
(set! i (1+ i))
(when (char=? (string-ref str i) openparen)
(set! count (1+ count)))
(when (char=? (string-ref str i) closeparen)
(set! count (1- count))
(when (zero? count)
(set! i (1+ i))
(break)))))
;; Any whitespace before the operator?
(when (char-set-contains? char-set:blank (string-ref str i))
(set! wspace #t)
(set! i (string-next-token str i)))
(cond
((eqv? (string-ref str i) #\=)
(values (1+ i) 'recursive))
((and (eqv? (string-ref str i) #\:)
(eqv? (string-ref str (1+ i)) #\=))
(values (+ i 2) 'simple))
((and (eqv? (string-ref str i) #\+)
(eqv? (string-ref str (1+ i)) #\=))
(values (+ i 2) 'append))
((and (eqv? (string-ref str i) #\?)
(eqv? (string-ref str (1+ i)) #\=))
(values (+ i 2) 'conditional))
(else
(values i 'null)))))))
(else
(values i 'null)))))
#|
(define (parse-var-assignment line)
(let ((i (string-next-token line 0)))
(if (= i (string-length line))
#f
;; else
(while #t
|#

@ -1,176 +0,0 @@
(define-module (potato parser)
#:use-module (ice-9 peg)
#:use-module (srfi srfi-1)
#:use-module (ice-9 rdelim)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:export (parse))
;; A makefile can contain rules, macro definitions, include lines,
;; and comments.
(define (parse filename)
(with-input-from-file filename parse-input #:guess-encoding #t))
(define (last-char str)
(string-ref str (1- (string-length str))))
(define (parse-input)
(while #t
(let loop ((line "")
(str (read-line)))
(cond
((eof-object? str)
(break))
((char=? (last-char str) #\\)
(loop (string-append line str) (read-line)))
(else
(parse-line (string-append line str)))))))
;; For include lines
(define-peg-pattern I_TOK none "include")
(define-peg-pattern I_SPACE none (or " " "\t"))
(define-peg-pattern I_FILENAME_CHAR body (or (range #\a #\z)
(range #\A #\Z)
(range #\0 #\9)
"_" "-" "."))
(define-peg-pattern I_FILENAME all (+ I_FILENAME_CHAR))
(define-peg-pattern I_NL none "\n")
(define-peg-pattern I_COMMENT none (and "#" (* peg-any)))
(define-peg-pattern INCLUDE all (and I_TOK
(+ (and (* I_SPACE)
I_FILENAME))
(* I_SPACE)
(? I_COMMENT)))
;; For comment lines
(define-peg-pattern C_SPACE none (or " " "\t"))
(define-peg-pattern C_COMMENT none (and "#" (* peg-any)))
(define-peg-pattern COMMENT none (or C_COMMENT
(and (+ C_SPACE) (not-followed-by peg-any))))
(define (parse-line line)
(write (peg:tree (match-pattern INCLUDE line)))
(newline)
(write (peg:tree (match-pattern COMMENT line)))
(newline)
(cond
((line-is-include? line)
(format #t "INCLUDE: ~S~%" line))
((line-is-comment? line)
(format #t "COMMENT: ~S~%" line))
((line-is-macro? line)
(format #t "MACRO: ~S~%" line))
((line-is-special-target? line)
(format #t "SPECIAL: ~S~%" line))
((line-is-inference-rule? line)
(format #t "INFERENCE: ~S~%" line))
((line-is-rule? line)
(format #t "RULE: ~S~%" line))
(else
(format #t "UNKNOWN: ~S~%" line))))
(define (line-is-include? line)
(and (> (string-length line) 8)
(string= line "include " 0 8)))
(define (line-is-comment? line)
(or (string-null? (string-trim-both line char-set:whitespace))
(char=? (string-ref line 0) #\#)))
(define (line-is-macro? line)
(let ((len (string-length line)))
(let loop ((i 0))
(if (>= i len)
#f
;; else
(let ((c (string-ref line i)))
(cond
((and (zero? i)
(not (char-is-pcs? c)))
#f)
((and (not (zero? i))
(char=? #\= c))
#t)
((not (char-is-pcs-or-space? c))
#f)
(else
(loop (+ i 1)))))))))
(define (line-is-special-target? line)
(or (and (>= (string-length line) 8)
(string= line ".DEFAULT" 0 8))
(and (>= (string-length line) 8)
(string= line ".IGNORE" 0 7))
(and (>= (string-length line) 6)
(string= line ".POSIX"))
(and (>= (string-length line) 9)
(string= line ".PRECIOUS" 0 9))
(and (>= (string-length line) 9)
(string= line ".SCCS_GET" 0 9))
(and (>= (string-length line) 7)
(string= line ".SILENT" 0 7))))
(define (line-is-rule? line)
(let ((len (string-length line)))
(let loop ((i 0))
(if (>= i len)
#f
;; else
(let ((c (string-ref line i)))
(cond
((and (zero? i)
(not (char-is-pcs? c)))
#f)
((and (not (zero? i))
(char=? #\: c))
#t)
((not (char-is-pcs-or-space? c))
#f)
(else
(loop (+ i 1)))))))))
(define (line-is-inference-rule? line)
(let ((len (string-length line)))
(let loop ((i 0)
(dot-count 0))
(if (>= i len)
#f
;; else
(let ((c (string-ref line i)))
(cond
((and (zero? i)
(not (char=? #\. c)))
#f)
((and (not (zero? i))
(char=? #\: c))
(if (or (= dot-count 1)
(= dot-count 2))
#t
#f))
((not (char-is-pcs? c))
#f)
(else
(loop (+ i 1)
(+ dot-count
(if (char=? c #\.)
1
0))))))))))
(define (char-is-pcs? c)
(or (and (char<=? #\a c) (char>=? #\z c))
(and (char<=? #\A c) (char>=? #\Z c))
(and (char<=? #\0 c) (char>=? #\9 c))
(char=? #\. c)
(char=? #\_ c)))
(define (char-is-pcs-or-space? c)
(or (char-is-pcs? c)
(char=? #\space c)))

@ -1,943 +0,0 @@
(define-module (potato rules)
#:use-module (ice-9 pretty-print)
#:use-module (ice-9 optargs)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (potato exceptions)
#:use-module (potato builtins)
#:use-module (potato makevars)
#:use-module (potato text)
#:export(<target-rule>
<suffix-rule>
<node>
%target-rules
%suffix-rules
initialize-rules
first-target-rule-name
install-alternate-system-driver
target-rule :
suffix-rule ->
target-name $@
newer-prerequisites $? $$?
primary-prerequisite $<
target-basename $*
prerequisites $^ $$^
build
string-compose ~
silent-compose ~@
always-execute-compose ~+
ignore-error-compose ~-
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GLOBALS
(define %ignore-errors? #f)
(define %continue-on-error? #f)
(define %no-execution? #f)
(define %verbosity 2)
(define %ascii? #f)
(define %top-level-targets '())
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HELPER FUNCTIONS
(define (basename str)
"Strip off the '.ext' part of a filename string."
(unless (string? str)
(scm-error 'wrong-type-arg "basename" "Not a string: ~S" (list str) #f))
(let ((idx (string-index-right str #\.)))
(if idx
(substring str 0 idx)
str)))
(define (base-compose . args)
"Returns a lambda that appends args together as a string,
adding intermediate spaces. If an arg is a procedure,
it is evaluated."
(lambda ()
;; Loop over all the args, appending them together as a
;; string. Try to be smart about the types of args.
(let loop ((args args)
(result ""))
(cond
((null? args)
result)
(else
(let ((arg (car args))
(effective-arg #f))
(cond
((procedure? arg)
(set! effective-arg (arg))
(unless (string? effective-arg)
(bad-proc-output "~" arg)))
((string? arg)
(set! effective-arg arg))
(else
;; Not a string or procedure?
;; Let's just write it, I guess. YOLO!
(set! effective-arg
(format #f "~a" arg))))
;; Loop, only adding spaces as necessary
(let ((need-a-space?
(and (not (string-null? result))
(not (string-null? effective-arg)))))
(loop
(cdr args)
(string-append
result
(if need-a-space? " " "")
effective-arg)))))))))
(define (string-compose . args)
(cons 'default (apply base-compose args)))
(define ~ string-compose)
(define (ignore-error-compose . args)
(cons 'ignore-error (apply base-compose args)))
(define ~- ignore-error-compose)
(define (silent-compose . args)
(cons 'silent (apply base-compose args)))
(define ~@ silent-compose)
(define (always-execute-compose . args)
(cons 'always-execute (apply base-compose args)))
(define ~+ always-execute-compose)
(define (regular-file? filename)
(unless (string? filename)
(scm-error 'wrong-type-arg "regular-file?" "Not a string: ~S" (list filename) #f))
(let ((st (stat filename #f)))
(eq? (stat:type st) 'regular)))
(define (compute-mtime filename)
(unless (string? filename)
(scm-error 'wrong-type-arg "regular-file?" "Not a string: ~S" (list filename) #f))
(let ((st (stat filename #f)))
(+ (* 1000000000 (stat:mtime st))
(stat:mtimensec st))))
(define %system-proc system)
(define (install-alternate-system-driver proc)
"Give a procure to use rather than the standard 'system' procedure,
installs it as the system driver. Returns the old system driver."
(unless (procedure? proc)
(scm-error 'wrong-type-arg "install-alternate-system-driver" "Not a procedure: ~S" (list proc) #f))
(let ((old-proc %system-proc))
(set! %system-proc proc)
old-proc))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TARGET STRUCT AND METHODS
(define-record-type <target-rule>
(make-target-rule name prerequisites recipes priority)
target-rule?
;; A filename, for real targets, or just a name for phony targets
(name target-rule-get-name target-rule-set-name!)
;; A list of filenames and/or phony targets that have target rules
(prerequisites target-rule-get-prerequisites
target-rule-set-prerequisites!)
;; A list of strings or procedures
(recipes target-rule-get-recipes
target-rule-set-recipes!)
;; 1 = script-defined. 2 = built-in
(priority target-rule-get-priority
target-rule-set-priority!))
;; List of all target rules in order of importance
(define %target-rules '())
(define* (target-rule name #:optional (prerequisites '()) #:rest recipes)
"Register a new target rule"
(when (>= %verbosity 3)
(if (null? prerequisites)
(format #t "Target rule: ~a~A~a~%~!" (lquo) name (rquo))
(format #t "Target rule: ~a~A~a ~A ~A~%~!" (lquo) name (rquo) (left-arrow) prerequisites)))
;; Empty recipes is shorthand for a recipe that always passes.
(when (null? recipes)
(set! recipes (list #t)))
;; If any recipes are raw strings, we need to make them into
;; (cons 'default string)
(let ((recipes2
(map (lambda (recipe)
(cond
((pair? recipe)
recipe)
(else
(cons 'default recipe))))
recipes)))
(let ((rule (make-target-rule name prerequisites recipes2 1)))
;; Add to %target-rules
(set! %target-rules (cons rule %target-rules)))))
;; Alias
(define : target-rule)
(define (first-target-rule-name)
(if (null? %target-rules)
#f
;; else
(target-rule-get-name (last %target-rules))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SUFFIX STRUCT AND METHODS
(define-record-type <suffix-rule>
(make-suffix-rule source-suffix target-suffix recipes priority)
suffix-rule?
;; A string, usually like ".c". Or a string->string proc.
(source-suffix suffix-rule-get-source
suffix-rule-set-source)
;; A string, usually like ".o". Or a string->bool proc.
(target-suffix suffix-rule-get-target
suffix-rule-set-suffix!)
;; A list of strings or procedures
(recipes suffix-rule-get-recipes
suffix-rule-set-recipes!)
;; 1 = script-defined. 2 = built-in
(priority suffix-rule-get-priority
suffix-rule-set-priority!))
;; The list of all registered suffix rules in order of importance
(define %suffix-rules '())
(define (suffix-rule source target . recipes)
"Register a suffix rule"
;; FIXME: Typecheck
(when (>= %verbosity 3)
(format #t "Suffix rule: ~a~A~a ~A ~a~A~a~%~!"
(lquo) source (rquo) (right-arrow) (lquo) target (rquo)))
;; If any recipes are raw strings, we need to make them into
;; (cons 'default string)
(let ((recipes2
(map (lambda (recipe)
(cond
((pair? recipe)
recipe)
(else
(cons 'default recipe))))
recipes)))
(let ((rule (make-suffix-rule source target recipes2 1)))
(set! %suffix-rules (cons rule %suffix-rules)))))
;; Alias
(define -> suffix-rule)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NODE STRUCT AND METHODS
(define-record-type <node>
(make-node name parent status)
node?
;; For a real target, this is a filename. For a phony target it is
;; just a label.
(name node-get-name node-set-name!)
;; A <node> which is the parent of this node, or #f.
(parent node-get-parent node-set-parent!)
;; If 'name' is a regular file, mtime holds its last modification
;; time in nanoseconds since the epoch. If 'name' does not exist,
;; _mtime is #f.
(mtime node-get-mtime node-set-mtime!)
;; One of 'pass, 'fail, or 'undetermined
(status node-get-status node-set-status!)
;; Either 'target or 'suffix or 'default
(rule-type node-get-rule-type node-set-rule-type!)
;; A list of rules
(rules node-get-rules node-set-rules!)
(children node-get-children node-set-children!)
)
(define (using-target-rule? node)
(eq? 'target (node-get-rule-type node)))
(define (using-suffix-rules? node)
(eq? 'suffix (node-get-rule-type node)))
(define (using-default-rule? node)
(eq? 'default (node-get-rule-type node)))
(define (set-fail! node)
(node-set-status! node 'fail))
(define (set-pass! node)
(node-set-status! node 'pass))
(define (failed? node)
(eqv? (node-get-status node) 'fail))
(define (passed? node)
(eqv? (node-get-status node) 'pass))
(define (leaf-node? node)
(null? (node-get-children node)))
(define (undetermined? node)
(eq? (node-get-status node) 'undetermined))
(define (any-child-has-passed? node)
(unless (node? node)
(scm-error 'wrong-type-arg "any-child-has-passed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "any-child-has-passed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(any passed? children)))
(define (every-child-has-passed? node)
(unless (node? node)
(scm-error 'wrong-type-arg "every-child-has-passed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "every-child-has-passed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(every passed? children)))
(define (any-child-has-failed? node)
(unless (node? node)
(scm-error 'wrong-type-arg "any-child-has-failed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "any-child-has-failed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(any failed? children)))
(define (every-child-has-failed? node)
(unless (node? node)
(scm-error 'wrong-type-arg "every-child-has-failed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "every-child-has-failed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(every failed? children)))
(define (children-complete? node)
(cond
((leaf-node? node)
#t)
((eqv? 'target (node-get-rule-type node))
(or (every-child-has-passed? node)
(any-child-has-failed? node)))
((eqv? 'suffix (node-get-rule-type node))
(or (every-child-has-failed? node)
(any-child-has-passed? node)))
(else
#f)))
(define (children-passed? node)
(cond
((null? (node-get-children node))
#t)
((eq? 'target (node-get-rule-type node))
(every-child-has-passed? node))
((eq? 'suffix (node-get-rule-type node))
(any-child-has-passed? node))
(else
#f)))
(define (get-next-child node)
"Return the first child node that is not yet PASS or FAIL"
(let ((children (node-get-children node)))
(cond
((null? children)
#f)
(else
(any (lambda (child)
(if (eqv? (node-get-status child) 'undetermined)
child
#f))
children)))))
(define (has-parent? node)
(if (node-get-parent node)
#t
#f))
(define (has-children? node)
(if (null? (node-get-children node))
#f
#t))
(define (get-parent node)
(node-get-parent node))
(define (up-to-date? node)
"Checks if node is up to date:
- it has an mtime
- all its children have mtimes
- its mtime is older than the mtime of its children"
(let ((children (node-get-children node))
(parent-mtime (node-get-mtime node)))
(if (or (null? children) (not (integer? parent-mtime)))
;; Targets without children are always rebuilt.
;; Targets without mtimes are always rebuilt.
#f
(let ((children-mtime (map node-get-mtime children)))
(if (every (lambda (child-mtime)
(and (integer? child-mtime)
(>= parent-mtime child-mtime)))
children-mtime)
#t
#f)))))
(define (node-depth node)
(let loop ((depth 0)
(cur node))
(if (has-parent? cur)
(loop (1+ depth) (get-parent cur))
;;
depth)))
(define (node-depth-string node)
(make-string (* 2 (node-depth node)) #\space))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; AUTOMATIC VARIABLES
(define target-name 'unspecified)
(define target-basename 'unspecified)
(define prerequisites '())
(define primary-prerequisite 'unspecified)
(define newer-prerequisites '())
(define (string-append-with-spaces lst)
"Appends the strings in lst, adding spaces in between."
(if (null? lst)
""
;; else
(fold
(lambda (elem prev)
(string-append prev " " elem))
(car lst)
(cdr lst))))
(define $@ (lambda () target-name))
(define $* (lambda () target-basename))
(define $< (lambda () primary-prerequisite))
(define $$? (lambda () newer-prerequisites))
(define $? (lambda () (string-append-with-spaces newer-prerequisites)))
(define $$^ (lambda () prerequisites))
(define $^ (lambda () (string-append-with-spaces prerequisites)))
(define (target-rule-prep-automatic-variables node rule)
(set! target-name (node-get-name node))
(set! target-basename (basename target-name))
(set! prerequisites (target-rule-get-prerequisites rule))
(set! primary-prerequisite (if (null? prerequisites) "" (car prerequisites)))
(set! newer-prerequisites
;; If this node doesn't have a real file attached, then all
;; prerequistes are "newer".
(if (not (node-get-mtime node))
prerequisites
;; Prerequisites that have no mtime or a higher mtime are
;; "newer".
(filter-map
(lambda (name)
(cond
((and (file-exists? name)
(regular-file? name)
(>= (node-get-mtime node) (compute-mtime name)))
name)
((not (file-exists? name))
name)
(else
#f)))
prerequisites))))
(define (suffix-rule-prep-automatic-variables node rule)
(set! target-name (node-get-name node))
(set! target-basename (basename target-name))
(set! primary-prerequisite (string-append target-basename (suffix-rule-get-source rule)))
(set! prerequisites (list primary-prerequisite))
(set! newer-prerequisites
;; If this node doesn't have a real file attached, then the
;; prerequisite is newer.
(if (not (node-get-mtime node))
(list primary-prerequisite)
;; Prerequisites that have no mtime or a higher mtime are
;; "newer".
(cond
((and (file-exists? primary-prerequisite)
(regular-file? primary-prerequisite)
(> (node-get-mtime node) (compute-mtime primary-prerequisite)))
(list primary-prerequisite))
(else
'())))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MIXED METHODS
;; requiring more than one of node, automatic variables, suffix rules
;; and target rules
(define (add-builtins)
#|
(-> ".c" ""
(~ ($ CC) ($ CFLAGS) ($ LDFLAGS) "-o" $@ $<))
(-> ".f" ""
(~ ($ FC) ($ FFLAGS) ($ LDFLAGS) "-o" $@ $<))
(-> ".sh" ""
(~ "cp" $< $@)
(~ "chmod a+x" $< $@))
|#
(-> ".c" ".o"
(~ ($ CC) ($ CFLAGS) "-c" $<))
(-> ".f" ".o"
(~ ($ FC) ($ FFLAGS) ",c" $<))
(-> ".y" ".o"
(~ ($ YACC) ($ YFLAGS) $<))
(-> ".l" ".o"
(~ ($ LEX) ($ LFLAGS) $<)
(~ ($ CC) ($ CFLAGS) "-c lex.yy.c")
"rm -f lex.yy.c"
(~ "mv lex.yy.o" $@))
(-> ".y" ".c"
(~ ($ YACC) ($ YFLAGS) $<)
(~ "mv y.tab.c" $@))
(-> ".l" ".c"
(~ ($ LEX) ($ LDFLAGS) $<)
(~ "mv lex.yy.c" $@))
(-> ".scm" ".go"
(~ ($ GUILD) "compile" ($ GFLAGS) $<)))
(define (run-target-rule! node)
"Runs the (singular) target rule associated with this node."
(unless (node? node)
(scm-error 'wrong-type-arg "run-target-rule!" "Not a node: ~S" (list node) #f))
(let ((rules (node-get-rules node)))
(when (null? rules)
(scm-error 'misc-error "run-target-rule!" "Node ~S has no target rules"
(list (node-get-name node)) #f))
(unless (= 1 (length rules))
(scm-error 'misc-error "run-target-rule!" "Node ~S has ~A target rules"
(list (node-get-name node) (length rules)) #f))
(unless (or (leaf-node? node) (every-child-has-passed? node))
(scm-error 'misc-error "run-target-rule!" "Node ~S: not all children have passed"
(list (node-get-name node)) #f))
(let ((rule (car rules)))
(target-rule-prep-automatic-variables node rule)
(run-recipes! node (target-rule-get-recipes rule))
(let ((status (node-get-status node)))
status))))
(define (run-suffix-rules! node)
"Runs the one-or-more suffix rules associated with this node. It
runs them one-by-one, quitting on the first success."
(unless (node? node)
(scm-error 'wrong-type'arg "run-suffix-rules!" "Not a node: ~S" (list node) #f))
(let ((rules (node-get-rules node))
(children (node-get-children node)))
(when (null? rules)
(scm-error 'misc-error "run-suffix-rules!" "Node ~S has no rules"
(list (node-get-name node)) #f))
(when (null? children)
(scm-error 'misc-error "run-suffix-rule!" "Node ~S has no children"
(list (node-get-name node)) #f))
(unless (any-child-has-passed? node)
(scm-error 'misc-error "run-suffix-rule!" "Node ~S: not child has passed"
(list (node-get-name node)) #f))
(unless (= (length rules) (length children))
(scm-error 'misc-error "run-suffix-rule!" "Node ~S: must have as many children as rules"
(list (node-get-name node)) #f))
(let ((i 0)
(len (length children)))
(while (< i len)
(let ((rule (list-ref rules i))
(child (list-ref children i)))
(when (passed? child)
(when (>= %verbosity 3)
(format #t "~A: attempting to make using ~a~A~a ~a ~a~A~a rule"
(node-get-name node)
(lquo) (suffix-rule-get-source rule) (rquo)
(right-arrow)
(lquo) (suffix-rule-get-target rule) (rquo)))
(suffix-rule-prep-automatic-variables node rule)
(run-recipes! node (suffix-rule-get-recipes rule)))
(when (passed? node)
(break))
(set! i (1+ i)))))
(when (>= %verbosity 3)
(if (passed? node)
(format #t "PASS: ~a~%~!" (node-get-name node))
(format #t "FAIL: ~a~%~!" (node-get-name node))))
(node-get-status node)))
(define (run-recipes! node recipes)
"Runs the recipes on this node, one by one. Recipes are either
strings, procedures that return strings, or generic procedures. If a
failure condition happens, mark the node as having failed."
(unless (node? node)
(scm-error 'wrong-type-arg "run-recipes!" "Not a node: ~S" (list node) #f))
;;(unless (and (list? recipes) (not (null? recipes)))
;; (scm-error 'wrong-type-arg "run-recipes!" "Not a non-null list: ~S" (list recipes) #f))
(let ((i 0)
(len (length recipes)))
(while (< i len)
(let* ((opt/recipe (list-ref recipes i))
(opt (car opt/recipe))
(recipe (cdr opt/recipe)))
;; Recipes are either
;; - strings to pass to system
;; - procedures that return a string which is passed
;; to system
;; - procedures (that don't return a string) that are executed
;; that pass unless they return #f
;; OPT is one of 'default, 'ignore, 'silent
(cond
((eq? recipe #t)
(set-pass! node))
((eq? recipe #f)
(set-fail! node))
((string? recipe)
(when (= %verbosity 1)
(format #t "~a~%~!" (node-get-name node)))
(when (or (and (= %verbosity 2) (not (eq? 'silent opt)))
(= %verbosity 3))
(format #t "~A~%~!" recipe))
(let ((retval (%system-proc recipe)))
(if (zero? retval)
(set-pass! node)
(set-fail! node))))
((procedure? recipe)
(let ((retval (recipe)))
(cond
;; If a procedure returns a string, that string gets
;; processed by system.
((string? retval)
(when (= %verbosity 1)
(format #t "~a~%~!" (node-get-name node)))
(when (or (and (= %verbosity 2) (not (eq? 'silent opt)))
(= %verbosity 3))
(format #t "~A~%~!" retval))
(let ((retval2 (%system-proc retval)))
(if (zero? retval2)
(set-pass! node)
(set-fail! node))))
;; A scheme procedure recipe that returns false.
((eqv? retval #f)
(set-fail! node))
(else
;; Otherwise, this was a procedure that didn't return
;; #f or a string, so it gets a pass.
(set-pass! node)))))
(else
;; Can't be converted to a viable string or procedure
(scm-error 'misc-error "run-recipes!" "bad recipe: ~S" (list recipe) #f)))
(when (failed? node) (break))
(set! i (1+ i))))
(when (passed? node)
(let ((name (node-get-name node)))
(when (and (file-exists? name)
(regular-file? name))
(node-set-mtime! node (compute-mtime name)))))))
(define (run-default-rule! node)
"The default rule if not other rule exists. It just passes if the
file exists."
(let ((name (node-get-name node)))
(if (and (file-exists? name)
(regular-file? name))
(begin
(set-pass! node)
(node-set-mtime! node (compute-mtime name)))
;; else
(set-fail! node))))
;; Start at root
;; If cur is UNDETERMINED, find a leaf that is UNDETERMINED.
;; Descent to first leaf.
;; If self's mtime is earlier than parent's mtime, mark self as PASS.
;; Elif self has rules, run rules and mark self PASS/FAIL.
;; Else self has no mtime or rules, so mark self FAIL.
;; Go to parent.
;; IF PASS or FAIL, go to parent
;; IF UNDETERMINED do these...
;; Are we done with the children?
;; If AND rule and one child is FAIL, stop
;; If OR rule and one child is PASS, stop
;; If no children left, stop
;; Else keep going
;; Did the children pass?
;; IF AND rule and all children are PASS, true
;; IF OR rule an one child is PASS, true
;; Otherwise, false
;; If the children FAIL, cur is FAIL
;; If the children PASS, run rules and mark self PASS/FAIL
;; Go to parent
;; 3 failures
;; - If anything fails, stop immediately
;; - If anything fails, searching through tree
;; - Ignore errors
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LET'S GO!
(define (initialize-rules targets builtins? ignore-errors? continue-on-error? no-execution? verbosity ascii?)
(set! %target-rules '())
(set! %suffix-rules '())
(set! %top-level-targets targets)
(set! %ignore-errors? ignore-errors?)
(set! %continue-on-error? continue-on-error?)
(set! %no-execution? no-execution?)
(set! %verbosity verbosity)
(set! %ascii? ascii?)
(when builtins?
(add-builtins)))
(define (create-node name parent)
"Constructs a tree of nodes, with name as the root node."
(when (and (node? parent) (> (node-depth parent) 30))
(error "Stack overflow"))
(let ((node (make-node name parent 'undetermined)))
(node-set-children! node '())
(node-set-rule-type! node 'default)
;; FIXME: here check that this name differs from all ancestor's
;; names
;; Try to the file's modification time.
(when (file-exists? name)
(when (not (regular-file? name))
(not-a-regular-file "create-node" name))
(when (not (access? name R_OK))
(no-read-access-to-file "create-node" name))
(node-set-mtime! node (compute-mtime name)))
;; Search for matching target rule.
(when (not (null? %target-rules))
(let loop ((rule (car %target-rules))
(rest (cdr %target-rules)))
;; N.B: here we assume target rule names and
;; predicates are exclusively strings.
(if (string=? name (target-rule-get-name rule))
(begin
;; OK we have a matching rule
(node-set-rules! node (list rule))
(node-set-rule-type! node 'target)
;; For target-rules, the prerequisites comes from the
;; rule itself.
;; Oooh, recursion!
(node-set-children! node
(map (lambda (prereq)
(create-node prereq node))
(target-rule-get-prerequisites rule))))
;; else
(if (not (null? rest))
(loop (car rest) (cdr rest))
;; else, no matching rule found
(node-set-rules! node '())))))
;; If no rule found so far, search for suffix rules.
(when (null? (node-get-rules node))
(for-each
(lambda (rule)
(let ((targ (suffix-rule-get-target rule)))
(when (string-suffix? targ name)
;; For suffix rules, there will be exactly one child per
;; rule and the name of the child is constructed from a
;; suffix and the parent's name.
(node-set-rules! node (cons rule (node-get-rules node)))
(node-set-rule-type! node 'suffix)
(let* ((src (suffix-rule-get-source rule))
(prereq
(string-append
(string-drop-right name (string-length src))
src)))
;; Note the recursion here.
(node-set-children! node
(cons (create-node prereq node)
(node-get-children node)))))))
%suffix-rules))
;; FIXME: First matching rule has highest priority? Or is last better?
(node-set-rules! node (reverse (node-get-rules node)))
(node-set-children! node (reverse (node-get-children node)))
;;(format #t "matching suffix rules ~S~%~!" (node-get-rules node))
;;(format #t "matching children rules ~S~%~!" (node-get-children node))
;; And node is ready to go
node))
(define (build root)
"Give a tree of <node>, this executes the recipes therein.
This is where the magic happens."
(let ((tree (create-node root #f)))
(let ((node tree))
(when (>= %verbosity 3)
(format #t "~ABegin building target ~a~A~a.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(while #t
(when (>= %verbosity 3)
(format #t "~AConsidering target ~a~A~a.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(if (undetermined? node)
(begin
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a is undetermined.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo))
(unless (node-get-mtime node)
(format #t "~AFile ~a~A~a does not exist.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo))))
(if (children-complete? node)
(begin
(when (and (>= %verbosity 3) (has-children? node))
(format #t "~AFinished prerequisites of target file ~a~A~a.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(if (children-passed? node)
(begin
(when (and (>= %verbosity 3) (has-children? node))
(format #t "~AThe prerequisites of target file ~a~A~a have passed.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(if (up-to-date? node)
(begin
(when (node-get-mtime node)
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a is up to date.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo))))
(set-pass! node))
;; else, not up to date
(begin
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a is not up to date.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(cond
((using-target-rule? node)
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a has a target rule.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(run-target-rule! node))
((using-suffix-rules? node)
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a has a suffix rule.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(run-suffix-rules! node))
((using-default-rule? node)
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a is using the default rule.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(run-default-rule! node))
(else
(error "bad rules")))
(if (passed? node)
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a has passed.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a has failed.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))))))
;; else, children have failed
(begin
(when (>= %verbosity 3)
(format #t "~AThe prerequisites of target file ~a~A~a have failed.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(set-fail! node))))
;; else, children aren't complete
(begin
(when (>= %verbosity 3)
(format #t "~AThe prerequisites of target file ~a~A~a are incomplete.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(let ((next (get-next-child node)))
(when (>= %verbosity 3)
(format #t "~ADescending node ~a~A~a ~a ~a~A~a.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(right-arrow)
(lquo) (node-get-name next) (rquo)))
(set! node (get-next-child node))
))))
;; else, this node is determined
(begin
(if (passed? node)
(when (>= %verbosity 2)
(format #t "~A~a~A~a: ~APASS~A~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)
(green) (default)))
(when (>= %verbosity 2)
(format #t "~A~a~A~a: ~AFAIL~A~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)
(red) (default))))
(if (has-parent? node)
(begin
(when (>= %verbosity 3)
(format #t "~AAscending node ~a~A~a ~a ~a~A~a.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(right-arrow)
(lquo) (node-get-name (node-get-parent node)) (rquo)))
(set! node (get-parent node)))
;; else, there is no parent to this node
(begin
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a has no parent.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(if (passed? node)
(when (>= %verbosity 1)
(format #t "~A~a~A~a: ~ACOMPLETE~A~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(green) (default)))
(when (>= %verbosity 1)
(format #t "~A~a~A~a: ~ACOMPLETE~A~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(red) (default))))
(break)))))))
;; Return the command output of the root node
(passed? tree)))

@ -1,108 +0,0 @@
(define-module (potato text)
#:export (underline
default
right-arrow
left-arrow
ellipses
C0
red green
lquo
rquo
initialize-text))
(define %fancy #t)
(define (initialize-text ascii)
(set! %fancy (not ascii)))
(define (default)
(if %fancy
(string #\escape #\[ #\0 #\m)
""))
(define (bold)
(if %fancy
(string #\escape #\[ #\1 #\m)
""))
(define (underline)
(if %fancy
(string #\escape #\[ #\4 #\m)
""))
(define (red)
(if %fancy
(string #\escape #\[ #\3 #\1 #\m)
""))
(define (green)
(if %fancy
(string #\escape #\[ #\3 #\2 #\m)
""))
(define (blue)
(if %fancy
(string #\escape #\[ #\3 #\4 #\m)
""))
(define (important)
(if %fancy
"⚠" ; U+26A0 WARNING SIGN
"!!!"))
(define (stop)
(if %fancy
"🛑" ; U+26A0 WARNING SIGN
"XXX"))
(define (right-arrow)
(if %fancy
"→" "->"))
(define (left-arrow)
(if %fancy
"←" "<-"))
(define (ellipses)
(if %fancy "…" "..."))
(define (QED)
(if %fancy "∎" "QED")) ; U+220E END OF PROOF
(define (C0 c)
(if %fancy
;; Replace control codes with control pictures
(string (integer->char (+ #x2400 (char->integer c))))
(list-ref '("<NUL>" "<SOH>" "<STX>" "<ETX>" "<EOT>" "<ENQ>"
"<ACK>" "<BEL>" "<BS>" "<HT>" "<LF>"
"<VT>" "<FF>" "<CR>" "<SO>" "<SI>"
"<DLE>" "<DC1>" "<DC2>" "<DC3>" "<DC4>"
"<NAK>" "<SYN>" "<ETB>" "<CAN>" "<EM>"
"<SUB>" "<ESC>" "<FS>" "<GS>" "<RS>"
"<US>")
(char->integer c))))
(define (lquo)
(if %fancy (string #\“) (string #\")))
(define (rquo)
(if %fancy (string #\”) (string #\")))
(define (BOL)
"go to beginning of line"
(if %fancy (string #\escape #\[ #\G) "\n"))
#|
in quiet mode it is just
target -> parent (when building)
target -> parent (on pass)
target -> parent (on fail but continue)
🛑 target -> parent (on stop)
(on successful completion)
in normal mode it is
? target -> parent
recipe truncated to 70 cols, using C0 control pics
etc
then
target -> parent (on pass)
|#

51
src/pmake/main.scm Normal file

@ -0,0 +1,51 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(define-module (make main)
#:use-module (ice-9 getopt-long)
#:export (main))
;;; Commentary:
;;;
;;; Backend for the `pman` command to process the command line arguments using the standardized 'getopts-long' as described in the GNU Guile reference manual <https://www.gnu.org/software/guile/manual/html_node/getopt_002dlong.html>.
;;;
;;; Code:
;; Declare exit codes
(define EXIT_SUCCESS 0)
(define EXIT_NOT_UP_TO_DATE 1)
(define EXIT_FAILURE 2)
(define option-spec
'((environment-overrides (single-char #\e))
(makefile (single-char #\f) (value #t))
(ignore-errors (single-char #\i))
(keep-going (single-char #\k))
(dry-run (single-char #\n))
(print-data-base (single-char #\p))
(question (single-char #\q))
(no-builtin-rules (single-char #\r))
(stop (single-char #\S))
(silent (single-char #\s))
(touch (single-char #\t))))
(define (main args)
(let ((options (getopt-long args option-spec)))
(write options)
(newline)
EXIT_SUCCESS))
;;; make.scm ends here

1
src/pmake/zz-README.org Normal file

@ -0,0 +1 @@
Backend the command `pmake`

0
src/pmake/zz-README.org~ Normal file

44
src/potato/builtins.scm Normal file

@ -0,0 +1,44 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(define-module (potato builtins)
#:export (builtin-makevars))
;;; Commentary:
;;;
;;; Dedicated to the declaration of built-in functionality such as variables, rules, tasks, etc..
;;;
;;; Code:
(define builtin-makevars
'(("MAKE" . "make")
("AR" . "ar")
("ARFLAGS" . "-rv")
("YACC" . "yacc")
("YFLAGS" . "")
("LEX" . "lex")
("LFLAGS" . "")
("LDFLAGS" . "")
("CC" . "cc")
("CFLAGS" . "-g -O2")
("FC" . "gfortran")
("FFLAGS" . "-O1")
("GUILE" . "guile")
("GUILD" . "guild")
("GFLAGS" . "-W2")))
;;; builtins.scm ends here

121
src/potato/exceptions.scm Normal file

@ -0,0 +1,121 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato exceptions)
#:use-module (ice-9 exceptions)
#:export (bad-key-type
bad-value-type
bad-proc-output
invalid-macro
not-a-regular-file
not-a-procedure
no-read-access-to-file))
;;; Commentary:
;;;
;;; Dedicated to handling 'exceptions' as in termination of the program
;;;
;;; Code:
;; FIXME-QA(Krey): This code is using 'bad' which is hard to understand without context, thus should be changed on 'unexpected'
(define (make-bad-key-type origin irritants)
"Exception used when bad key is parsed to 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
;; FIXME-TRANSLATE(Krey)
(make-exception-with-message "Wrong type for key. Expecting string or procedure.")
(make-exception-with-irritants irritants)))
(define (bad-key-type origin irritant)
"Generic exception for unexpected key"
(raise-exception (make-bad-key-type origin irritant)))
(define (make-bad-value-type origin irritants)
"Exception for unexpected value in the 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
;; FIXME-TRANSLATE(Krey)
(make-exception-with-message "Wrong type for value. Expecting string or procedure.")
(make-exception-with-irritants irritants)))
(define (bad-value-type origin irritant)
"Generic exception for unexpected value"
(raise-exception (make-bad-value-type origin irritant)))
(define (make-bad-proc-output origin irritants)
"Exception for unexpected process output in 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Procedure does not evaluate to a string.")
(make-exception-with-irritants irritants)))
(define (bad-proc-output origin irritant)
"Generic exception for unexpected process output"
(raise-exception (make-bad-proc-output origin irritant)))
(define (make-invalid-macro origin irritants)
"Exception for invalid macro in 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Invalid macro format")
(make-exception-with-irritants irritants)))
(define (invalid-macro origin irritant)
"Generic exception for invalid macro"
(raise-exception (make-invalid-macro origin irritant)))
(define (make-not-a-regular-file origin irritants)
"Exception for not regular file in 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Not a regular file")
(make-exception-with-irritants irritants)))
(define (not-a-regular-file origin irritant)
"Generic exception for when regular file is not parsed"
(raise-exception (make-not-a-regular-file origin irritant)))
(define (make-not-a-procedure origin irritants)
"Exception for when regular file is not parsed in the 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Not a procedure")
(make-exception-with-irritants irritants)))
(define (not-a-procedure origin irritant)
"Generic exception for when procedure is not parsed"
(raise-exception (make-not-a-procedure origin irritant)))
(define (make-no-read-access-to-file origin irritants)
"Exception for when we don't have the expected read access to the file in 'make' functionality"
(make-exception
(make-programming-error)
(make-exception-with-origin origin)
(make-exception-with-message "Do not have permissions to read file")
(make-exception-with-irritants irritants)))
(define (no-read-access-to-file origin irritant)
"Generic exception for when we don't have the excepted read access to the file"
(raise-exception (make-no-read-access-to-file origin irritant)))
;;; exceptions.scm end here

319
src/potato/make.scm Normal file

@ -0,0 +1,319 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato make)
#:use-module (srfi srfi-1)
#:use-module (ice-9 exceptions)
#:use-module (ice-9 optargs)
#:use-module (ice-9 getopt-long)
#:use-module (ice-9 receive)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:export (initialize execute)
#:re-export (%suffix-rules
lazy-assign ?=
assign :=
reference $ Q
reference-func $$
target-rule :
suffix-rule ->
target-name $@
target-basename $*
newer-prerequisites $? $$?
prerequisites $^ $$^
primary-prerequisite $<
string-compose ~
silent-compose ~@
always-execute-compose ~+
ignore-error-compose ~-
install-alternate-system-driver))
;;; Commentary:
;;;
;;; Entry file to the project, designed for handling the functionality
;;;
;;; Code:
;; FIXME-QA(Krey): This file includes debugging utilities that should be exported into a standalone library to make this software more maintainable
;; FIXME-QA(Krey): Needs refactor
;; FIXME-QA(Krey): Why is this here?
;; Project version
(define %version "1.0")
;; WTF(Krey)
(define %debug-argv0 #f)
;; FIXME-DOCS(Krey): Lacks context
;;; Asynchronous events.
;;; SIGHUP, SIGTERM, SIGINT and SIGQUIT remove the current target
;;; unless that target is a directory or the target is a prerequisite
;;; of .PRECIOUS or the -n, -q, or -p option was specified. This
;;; deletion shall be reported to the error port, then the default for
;;; that action will continue.
;;; .SILENT
;;; The utility shall write all commands to the standard output unless
;;; the -s option was specified, the command is prefixed with +, or
;;; .SILENT has the current target as a prerequisite or has no pre
;;; requisites.
;;; Nothing to be done
;;; If make was invoked but found no work to do, it shall write a
;;; message to standard output that no action was taken
;;; File Touched
;;; If the -t option was specified, make shall write to standard
;;; output a message for each file that was touched.
;;; Output handlers
;;; These handlers are designed to be used for debug management
;; Verbosity is 0 = silent, 1 = terse, 2 = default, 3 = verbose
(define %verbosity 2)
;; WTF(Krey): Option to set verbose output and %verbosity defining the "deepness" of output?
(define %opt-verbose #f)
;; WTF(Krey): Option to ignore errors?
(define %opt-ignore-errors #f)
;; WTF(Krey): Option to continue on errors?
(define %opt-continue-on-error #f)
;; WTF(Krey): Generic definition of targets for appending?
(define %targets '())
;; WTF(Krey): No idea
(define %initialized #f)
(define (critical spec . args)
"Output to handle 'cricital' output messages"
(apply format (append (list #t spec) args)))
;; FIXME-QA(Krey): The 'print' is too generic, should we rename it?
(define (print spec . args)
"Output to handle printing of output. Only works when verbosity is set to 2 and higher"
(when (>= %verbosity 2)
(apply format (append (list #t spec) args))))
(define (debug spec . args)
"Output to handle level 3 debug messages"
(when (>= %verbosity 3)
(apply format (append (list #t spec) args))))
(define option-spec
'((help (single-char #\h) (value #f))
(version (single-char #\v) (value #f))
(verbosity (single-char #\V) (value #t))
(environment (single-char #\e) (value #f))
(elevate-environment (single-char #\E) (value #f))
(builtins (single-char #\b) (value #f))
(ignore-errors (value #f))
(continue-on-error (single-char #\k) (value #f))
(no-execution (single-char #\n) (value #f))
(ascii (single-char #\A) (value #f))
(strict (single-char #\S) (value #f))))
;; FIXME-QA(Krey): This is calling `format` multiple times to print one line which is resource inefficient
(define (display-help-and-exit argv0)
"Function used to output help message and exit"
(format #t "~A [-hvqVeEbn] [KEY=VALUE ...] [targets ...]~%" argv0)
(format #t " -h, --help print help and exit~%")
(format #t " -v, --version print version and exit~%")
(format #t " -V 0..3, --verbosity=0..3~%")
(format #t " set output level from 0=silent to 3=verbose~%")
(format #t " -e, --environment use environment variables~%")
(format #t " -E, --elevate-environment~%")
(format #t " use environment variables and let~%")
(format #t " them override script variables~%")
(format #t " -b, --builtins~%")
(format #t " include some common variables and suffix rules~%")
(format #t " --ignore-errors~%")
(format #t " ignore all errors~%")
(format #t " -k, --continue-on-error~%")
(format #t " after an error, keep building other targets~%")
(format #t " -n, --no-execution~%")
(format #t " only execute rules marked as 'always execute'~%")
(format #t " -a, --ascii~%")
(format #t " ASCII only output and no colors~%")
(format #t " -S, --strict~%")
(format #t " causes some behaviours to throw errors~%")
(exit 0))
;; FIXME-QA(Krey): Why is this accepting input?
(define (display-version-and-exit argv0)
"Function to output the project version and exit"
(format #t "~a~%" argv0)
(format #t " using potato make~a~%" %version)
(exit 0))
(define (parse-macros lst)
"Search for list for strings of the form KEY=VAR and return a list
of pairs of KEY VAL"
(filter-map
(lambda (str)
(let ((tok (string-split str #\=)))
(cond
((= 1 (length tok))
#f)
((= 2 (length tok))
(cons (car tok) (cadr tok)))
(else
(invalid-macro "parse-macros" str)))))
lst))
(define (parse-targets lst)
"Search the list for strings that don't have equals signs, and return them in a list."
(filter-map
(lambda (str)
(if (string-index str #\=)
#f
str))
lst))
(define* (initialize #:optional
(arguments #f))
"Set up the options, rules, and makevars. If ARGUMENTS is not set, it will use options, makevars, and targets as specified by the command line. If it is set, it is expected to be a list of strings that are command-line arguments." ;; If left unset, assume user want all the command line arguments.
(when (not arguments)
(set! arguments (command-line)))
;; If the user has set it to '(), expecting a null environment, add
;; back in a filename, which is required.
(when (null? arguments)
(set! arguments (list (car (program-arguments)))))
;; We start of with the --help and --version command-line arguments.
(let ((options (getopt-long arguments option-spec))
(%opt-builtins #f)
(%opt-environment #f)
(%opt-elevate-environment #f)
(%opt-no-errors #f)
(%opt-continue-on-error #f)
(%opt-no-execution #f)
(%opt-ascii #f)
(%opt-strict #f))
(when (option-ref options 'help #f)
(display-help-and-exit (car arguments)))
(when (option-ref options 'version #f)
(display-version-and-exit (car arguments)))
;; Then, we do --environment, because we need to know that
;; before we start parsing MAKEFLAGS
(set! %opt-environment
(option-ref options 'environment #f))
;; Parse MAKEFLAGS before the command-line, because we want
;; command-line options to override MAKEFLAGS options.
(when %opt-environment
(let ((mf (getenv "MAKEFLAGS")))
(when mf
(let ((tokens (string-tokenize mf)))
(when (member "silent" tokens)
(set! %verbosity 0))
(when (member "terse" tokens)
(set! %verbosity 1))
(when (member "verbose" tokens)
(set! %verbosity 3))
(when (member "builtins" tokens)
(set! %opt-builtins #t))
(when (member "ascii" tokens)
(set! %opt-ascii #t))
(when (member "ignore-errors" tokens)
(set! %opt-ignore-errors #t))
(when (member "continue-on-error" tokens)
(set! %opt-continue-on-error #t))
(when (member "strict" tokens)
(set! %opt-strict #t))
(when (member "no-execution" tokens)
(set! %opt-no-execution #t))))))
;; Now the bulk of the command-line options.
(when (option-ref options 'verbosity #f)
(let ((verbosity (string->number (option-ref options 'verbosity #f))))
(when verbosity
(set! %verbosity verbosity))))
(when (option-ref options 'builtins #f)
(set! %opt-builtins #t))
(when (option-ref options 'elevate-environment #f)
(set! %opt-elevate-environment #t))
(when (option-ref options 'ignore-errors #f)
(set! %opt-ignore-errors #t))
(when (option-ref options 'continue-on-error #f)
(set! %opt-continue-on-error #t))
(when (option-ref options 'no-execution #f)
(set! %opt-no-execution #t))
(when (option-ref options 'ascii #f)
(set! %opt-ascii #t))
(when (option-ref options 'strict #f)
(set! %opt-strict #t))
;; Now that all the options are set, we can set up
;; the build environment.
(let ((extra (option-ref options '() '())))
(initialize-text %opt-ascii)
(initialize-makevars (parse-macros extra)
%opt-environment
%opt-elevate-environment
%opt-builtins
%opt-strict
%verbosity
%opt-ascii)
;; The remaining command-line words are the build targets that
;; we're going to tackle.
(set! %targets (parse-targets extra))
(initialize-rules %targets
%opt-builtins
%opt-ignore-errors
%opt-continue-on-error
%opt-no-execution
%verbosity
%opt-ascii)
(set! %initialized #t) %targets)))
(define* (execute #:key (targets '()))
"This function runs build actions. TARGETS, if provided, is a list
of target names to be executed. If TARGETS is not provided, the
targets listed on the parsed command-line are used."
;; First, let's figure out what targets we're building.
(unless %initialized
(critical "The initialize procedure was not called in this build script.~%")
(critical "Using an empty environment.~%"))
(when (null? targets)
(set! targets %targets))
(when (null? targets)
(debug "No build target was explicitely specified.~%")
(let ((rule (first-target-rule-name)))
(if rule
(begin
(debug "Using first rule ~a~A~a as the build target.~%" (lquo) rule (rquo))
(set! targets (list rule)))
;; else
(debug "There are no target rules in the recipe.~%"))))
;; Build each target in order
(when (not (null? targets))
(let loop ((target (car targets))
(rest (cdr targets)))
(if (not (build target))
(begin
(print "The recipe for “~A” has failed.~%" target)
#f)
;; else
(begin
(print "The recipe “~A” finished successfully.~%" target)
(if (not (null? rest))
(loop (car rest) (cdr rest))
;; True if all targets are built successfully.
#t))))))
;;; make.scm ends here

433
src/potato/makevars.scm Normal file

@ -0,0 +1,433 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato makevars)
#:use-module (srfi srfi-1)
#:use-module (ice-9 format)
#:use-module (potato exceptions)
#:use-module (potato builtins)
#:use-module (potato text)
#:export (initialize-makevars
%makevars
%elevate-environment?
lazy-assign ?=
assign :=
reference $ Q
reference-func $$
dump-makevars))
;;; Commentary:
;;;
;;; Used to handle the 'makevars' functionality meaning assigning and managing environmental variables into variables used by guile
;;;
;;; Code:
;; Defines the priority level
;; There are five priority levels
;; 1. defined - in the script itself
;; 2. command-line
;; 3. makeflags - in the MAKEFLAGS environment variable
;; 4. env - specified in the environment
;; 5. built-in - one of the built-in macros
;;
;; The lower priority level always win, unless the '-e' flag was set
;; If the '-e' flag is set level 1 doesn't override level 3 and 4.
(define %level-name '("unknown"
"script"
"command-line"
"makeflags"
"environment"
"built-in"))
;; WTF(Krey): No idea.. something with ASCII? If ASCII is supported?
(define %ascii? #f)
;; WTF(Krey)
(define %makevars (make-hash-table))
;; WTF(Krey)
(define %elevate-environment? #f)
;; WTF(Krey)
(define %strict #f)
;; WTF(Krey)
(define %verbose? #t)
;; WTF(Krey)
(define (debug spec . args)
"Output to handle debugging messages"
(when %verbose?
(apply format (append (list #t spec) args))))
(define (split-at-equals str)
"Splits the string at the first equals sign, ignoring later equals signs."
(let ((idx (string-index str #\=)))
(if (and idx (> idx 0))
(cons (substring str 0 idx)
(substring str (1+ idx)))
;; else
#f)))
(define (string-append-with-spaces lst)
"Appends the strings in lst, adding spaces in between."
(fold
(lambda (elem prev)
(string-append prev " " elem))
(car lst)
(cdr lst)))
(define (override? old-priority new-priority)
"The logic of whether which makemacro priority levels can override
others."
(if %elevate-environment?
(if (and (or (= old-priority 2) (= old-priority 3) (= old-priority 4))
(= new-priority 1))
#f
;; else
(<= new-priority old-priority))
;; else
(<= new-priority old-priority)))
(define* (makevars-set key
#:optional (new-val "") (new-priority 1))
"Maybe add key / val to %makevars hash table, if there is sufficient
priority."
;; Note that VAL can be either a string or a procedure. If it is a
;; procedure, it is converted into a promise to be evaluated later.
(let* ((val&priority (hash-ref %makevars key))
(old-val (if (pair? val&priority) (cdr val&priority) #f))
(old-priority (if (pair? val&priority) (cdr val&priority) #f)))
(when (or (not old-val)
(override? old-priority new-priority))
(if (procedure? new-val)
(hash-set! %makevars key (cons (delay new-val) new-priority))
(hash-set! %makevars key (cons new-val new-priority)))
(when %verbose? (print-makevar key))))
*unspecified*)
(define (makevars-add-keyvals keyvals)
"Adds any suitable macros passed in from the command line, which here are expected to be a list of key / val string pairs."
(for-each
(lambda (entry)
(let ((key (car entry))
(val (cdr entry)))
(unless (or (string=? key "SHELL")
(string=? key "MAKEFLAGS"))
(makevars-set key val 2))))
keyvals))
(define (makevars-add-makeflags)
"Adds any suitable environment variables found in the MAKEFLAGS environment variable to the macro store"
(let ((makeflags (getenv "MAKEFLAGS")))
(when makeflags
(for-each
(lambda (entry)
(let* ((keyval (split-at-equals entry))
(key (if keyval (car keyval) #f))
(val (if keyval (cdr keyval) #f)))
(unless (or (not (string? key))
(string=? key "SHELL")
(string=? key "MAKEFLAGS"))
(makevars-set key val 3))))
(string-split makeflags #\space)))))
(define (makevars-add-environment)
"Adds any suitable environment variables to the macro store, but not the value of MAKEFLAGS or SHELL."
(for-each
(lambda (entry)
(let* ((keyval (split-at-equals entry))
(key (if keyval (car keyval) #f))
(val (if keyval (cdr keyval) #f)))
(unless (or (string=? key "SHELL")
(string=? key "MAKEFLAGS"))
(makevars-set key val 4))))
(environ)))
(define (makevars-add-builtins)
"Adds the default macros to the store"
(for-each
(lambda (keyval)
(makevars-set (car keyval) (cdr keyval) 5))
builtin-makevars))
;; FIXME-DOCS(Krey)
(define (print-makevar key)
(let ((val (hash-ref %makevars key)))
(let ((keyval-string
(if (zero? (string-length (car val)))
(string-copy key)
(string-append key " " (right-arrow) " " (car val)))))
;; Replace any control characters in VAL, like newline or tab
(set! keyval-string
(string-fold
(lambda (c str)
(string-append str
(if (char<? c #\space)
(C0 c)
(string c))))
""
keyval-string))
;; Truncate
(if (> (string-length keyval-string) 60)
(if %ascii?
(set! keyval-string
(string-append (substring keyval-string 0 57) "..."))
(set! keyval-string
(string-append (substring keyval-string 0 59) "…"))))
(let* ((space (make-string (- 64 (string-length keyval-string))
#\space))
(priority (cdr val))
(source-string (list-ref '("unknown"
"script"
"command line"
"MAKEFLAGS"
"environment"
"built-in")
priority)))
(display "Var: ")
(display keyval-string)
(display space)
(display source-string)
(newline)))))
(define (dump-makevars)
"Write out a list of the current makevars."
(when (not (zero? (hash-count (const #t) %makevars)))
(display (underline))
(display "Makevars")
(display (default))
(newline)
(let ((keyvals
(sort
(hash-map->list cons %makevars)
(lambda (a b)
(string<? (car a) (car b))))))
(for-each
(lambda (keyval)
(let ((key (car keyval))
(val (cdr keyval)))
(let ((keyval-string
(if (zero? (string-length (car val)))
(string-copy key)
(string-append key " " (right-arrow) " " (car val)))))
;; Replace any control characters in VAL, like newline or tab
(set! keyval-string
(string-fold
(lambda (c str)
(string-append str
(if (char<? c #\space)
(C0 c)
(string c))))
""
keyval-string))
;; Truncate
(if (> (string-length keyval-string) 60)
(if %ascii?
(set! keyval-string
(string-append (substring keyval-string 0 57) "..."))
(set! keyval-string
(string-append (substring keyval-string 0 59) "…"))))
(let* ((space (make-string (- 64 (string-length keyval-string))
#\space))
(priority (cdr val))
(source-string (list-ref '("unknown"
"script"
"command line"
"MAKEFLAGS"
"environment"
"built-in")
priority)))
(display " ")
(display keyval-string)
(display space)
(display source-string)
(newline)))))
keyvals))))
;; FIXME-DOCS(Krey)
(define (initialize-makevars keyvals
environment?
elevate-environment?
builtins?
strict?
verbosity
ascii?)
(set! %elevate-environment? elevate-environment?)
(hash-clear! %makevars)
(set! %strict strict?)
(set! %verbose? (= verbosity 3))
(set! %ascii? ascii?)
(when builtins?
(makevars-add-builtins))
(when (or environment? elevate-environment?)
(makevars-add-environment)
(makevars-add-makeflags))
(makevars-add-keyvals keyvals))
;;; API
(define* (lazy-assign key #:optional (val ""))
"This procedure sets an entry in the %makevars hash table.
KEY must be a string or a thunk that evaluates to a string. Likewise
VAL.
If KEY is a thunk, it is immediately evaluated to a string to use as the key in the hash table entry.
If VAL is a thunk, it is stored as a *promise* to be evaluated later. The promise will be evaluated the first time this key is
referenced.
If VAL is not given, the empty string will be used."
(when (procedure? key)
(set! key (key)))
(unless (string? key)
(set! key (format #f "~a" key)))
(makevars-set key (delay val)))
(define-syntax ?=
(lambda (stx)
(syntax-case stx ()
((_ key val)
#'(lazy-assign (symbol->string (syntax->datum #'key)) val))
((_ key)
#'(lazy-assign (symbol->string (syntax->datum #'key)))))))
(define* (assign key #:optional (val ""))
"This procedure sets an entry in the %makevars hash table.
KEY must be a string or a thunk that evaluates to a string. Likewise
VAL.
If KEY and/or VAL is a thunk, it is immediately evaluated to a string to use as the key in the hash table entry.
If VAL is not given, the empty string will be used."
(when (procedure? key)
(set! key (key)))
(unless (string? key)
(set! key (format #f "~a" key)))
(when (procedure? val)
(set! val (val)))
(unless (string? val)
(set! val (format #f "~a" val)))
(makevars-set key val))
(define-syntax :=
(lambda (stx)
(syntax-case stx ()
((_ key val)
#'(assign (symbol->string (syntax->datum #'key)) val))
((_ key)
#'(assign (symbol->string (syntax->datum #'key)))))))
(define* (reference key quoted? #:optional (transformer #f))
"Looks up KEY in the %makevars hash table. KEY may be a string
or a procedure that evaluates to a string.
If the value of the key in the hash table was a *promise* it will be forced, evaluated, and set to that result.
If no transformer is supplied, the looked up value will be returned.
TRANSFORMER, if supplied, should be a procedure of one string argument that returns a string. If a transformer is supplied, it will be applied to every space-separated token in the looked-up value."
(when (and (not (string? key))
(not (procedure? key)))
(bad-key-type "reference" (list key)))
(when (procedure? key)
(set! key (key))
(unless (string? key)
(bad-proc-output "reference" key)))
(when (not (string? key))
(set! key (format #t "~a" key)))
(let* ((val&priority (hash-ref %makevars key))
(val (if (pair? val&priority) (car val&priority) #f))
(priority (if (pair? val&priority) (cdr val&priority) #f)))
(if (not val)
(if %strict
(error (format #t "There is no makevar for key ~a~%~!" key))
;; else
(if quoted?
"\"\""
""))
;; else
(begin
(cond
((promise? val)
(set! val (force val))
(cond
((string? val)
;; noop
#t)
((procedure? val)
(set! val (val)))
(else
(set! val (format #f "~a" val)))))
((string? val)
;; noop
#f)
(else
(set! val (format #f "~a" val))))
(hash-set! %makevars key (cons val priority))
(when %verbose? (print-makevar key))
(when (procedure? transformer)
(set! val (string-append-with-spaces
(map transformer
(string-tokenize val)))))
(if quoted?
(string-append "\"" val "\"")
val)))))
;; FIXME-DOCS(Krey)
(define-syntax $
(lambda (stx)
(syntax-case stx ()
((_ key transformer)
#'(reference (symbol->string (syntax->datum #'key)) #f transformer))
((_ key)
#'(reference (symbol->string (syntax->datum #'key)) #f)))))
;; FIXME-DOCS(Krey)
(define-syntax Q
(lambda (stx)
(syntax-case stx ()
((_ key transformer)
#'(reference (symbol->string (syntax->datum #'key)) #t transformer))
((_ key)
#'(reference (symbol->string (syntax->datum #'key)) #t)))))
(define (reference-func key)
"Looks up KEY in the %makevars hash table. KEY shall be a string or a procedure that evaluates to a string.
If the value of the key in the hash table was a *promise*, a procedure will be returned that, when called, will call that promise.
If the value of the key is a string, a procedure will be returned that, when called, returns that string."
(when (and (not (string? key))
(not (procedure? key)))
(bad-key-type "reference" (list key)))
(when (procedure? key)
(set! key (key))
(unless (string? key)
(bad-proc-output "reference" key))
(let* ((val&priority (hash-ref %makevars key))
(val (if (pair? val&priority) (cdr val&priority) #f)))
(if (not val)
#f
;; else
(begin
(if (promise? val)
(lambda ()
(let ((VAL (force val)))
;; FIXME(spk121): put verbose print here?
VAL))
;; else
(lambda ()
val)))))))
;; FIXME-DOCS(Krey)
(define-syntax $$
(lambda (stx)
(syntax-case stx ()
((_ key)
#'(reference-func (symbol->string (syntax->datum #'key)))))))
;; makevards.scm ends here

260
src/potato/parse-lib.scm Normal file

@ -0,0 +1,260 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato parse-lib)
#:use-module (srfi srfi-1)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 optargs)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:export(
read-line-handle-escaped-newline
string-collapse-continuations
string-count-backslashes-at-end
string-count-matching-chars-at-end
string-find-char-unquote
string-find-preceding-backslashes
string-find-repeated-chars
string-next-token
string-remove-comments
string-starts-with?
string-shrink-whitespace))
;;; Commentary:
;;;
;;; Backend code used for the parsing of non-guile makefiles
;;;
;;; Code:
(define (read-line-handle-escaped-newline)
"Reads a line of text from the current input port.
If the line ends with an odd number of backslashes, the following line is read and appended. The output string has newlines as line terminators.
It returns two values
- the string containing the one or more lines read
- the number of lines read."
(let loop ((output "")
(nline 0))
(let ((line (read-line)))
(if (eof-object? line)
(values output nline)
;; else
(if (odd? (string-count-backslashes-at-end line))
(loop (string-append output (string-drop-right line 1) "\n")
(1+ nline))
;; else
(values (string-append output line "\n") (1+ nline)))))))
(define* (string-collapse-continuations str #:optional (squash-whitespace? #f))
"Returns a new string where backslash+newline is discarded, and backslash+backslash+newline becomes backslash+newline. Any whitespace after the newline may be squashed to a single space, if squash-whitespace? is #t."
(let loop ((str str)
(newline-index (string-rindex str #\newline)))
(if (not newline-index)
(string-copy str)
;; else
(let* ((backslash-index (string-find-preceding-backslashes str newline-index))
(backslash-count (- newline-index backslash-index)))
(cond
((even? backslash-count)
;; We cut the number of backslashes in half, but, keep the newline.
(loop
(string-append
(substring str 0 backslash-index)
(make-string (quotient backslash-count 2) #\\)
(substring str newline-index))
(string-rindex str #\newline 0 backslash-index)))
(else
;; We cut the number of backslashes in half, remove a backslash and newline, maybe squash any following whitespace.
(loop
(string-append
(substring str 0 backslash-index)
(make-string (quotient backslash-count 2) #\\)
(if squash-whitespace?
(string-shrink-whitespace
(substring str (1+ newline-index))
0)
(substring str (1+ newline-index))))
(string-rindex str #\newline 0 backslash-index))))))))
;; FIXME-DOCS(Krey)
(define (string-count-backslashes-at-end str)
(string-count-matching-chars-at-end str #\\))
;; FIXME-DOCS(Krey)
(define (string-count-matching-chars-at-end str c)
(if (not (string? str))
0
;; else
(let ((len (string-length str)))
(if (zero? len)
0
;; else
(let loop ((i (1- len))
(n 0))
(if (char=? (string-ref str i) c)
(if (zero? i)
(1+ n)
;; else
(loop (1- i) (1+ n)))
;; else
n))))))
(define* (string-find-char-unquote str #:optional (stop1 #f) (stop2 #f) #:key (blank #f) (ignorevars #f))
"Search string for an unquoted stopchar. Search until the end of line is reached or until the blank char is reached. A backslash quotes the stopchars and the blank.
The stopchars and blank may be #f, to ignore them in this call.
If ignorevars is #t, stopchars inside of variable references are ignored
Returns two values
- A string with the quoting backslashes removed
- The position of the first unquoted stopchar, or #f"
(let ((i 0)
(str2 (string-copy str))
(ret #f))
(while #t
(while (and (< i (string-length str))
(not (or
(and stop1 (eqv? (string-ref str i) stop1))
(and stop2 (eqv? (string-ref str i) stop2))
(and ignorevars (eqv? (string-ref str i) #\$))
(and blank (char-set-contains? char-set:blank (string-ref str i))))))
(set! i (1+ i)))
(when (>= i (string-length str))
(break))
;; If we stopped due to a variable reference, skip its contents
(when (and ignorevars (eqv? (string-ref str i) #\$))
(let ((openparen (false-if-exception (string-ref str (1+ i)))))
(set! i (+ i 2))
(when (or (eqv? openparen #\() (eqv? openparen #\{))
(let ((pcount 1)
(closeparen (if (eqv? openparen #\()
#\)
#\})))
(while (< i (string-length str))
(cond
((eqv? (string-ref str i) openparen)
(set! pcount (1+ pcount)))
((eqv? (string-ref str i) closeparen)
(set! pcount (1- pcount))
(when (zero? pcount)
(set! i (1+ i))
(break))))
(set! i (1+ i)))))
;; Skipped the variable reference: look for STOPCHARS again
(continue)))
(if (and (> i 0) (eqv? (string-ref str (1- i)) #\\))
;; Search for more backslashes
(let ((j 2))
(while (and (>= (- i j) 0)
(eqv? (string-ref str (- i j)) #\\))
(set! j (1+ j)))
(set! j (1- j))
;; Copy the string to swallow half the backslashes
(set! str2
(string-append
(string-take str (- i j))
(string-drop str (- i (quotient j 2)))))
(set! i (- i (quotient j 2)))
(when (even? j)
;; All the backslashes quoted each other; the stopchar was unquoted
(set! ret #t)
(break))
(set! str str2))
;; else
;; no backslash in sight
(begin
(set! ret #t)
(break))))
(if ret
(values i str2)
(values #f #f))))
(define (string-find-preceding-backslashes str i)
"Given I, a position in a string, this returns a position, of first of a range sequential backslashes that immediately precedes that position in the string. If no backslashes precede that position, I is returned."
(let loop ((j i))
(cond
((= j 0)
0)
((char=? (string-ref str (1- j)) #\\)
(loop (1- j)))
(else
j))))
(define (string-find-repeated-chars str c)
"Given a character c, this finds the position of of first instance of the character in the string. If the character repeats, it returns, as a pair, the position of the character, and the position after the run of characters. If the character is not present, it returns #f"
(let ((i (string-index str c)))
(if (not i)
#f
;; else
(let ((len (string-length str)))
(if (= (1+ i) len)
(cons i (1+ i))
;; else
(let loop ((j (1+ i)))
(if (false-if-exception (char=? (string-ref str j) c))
(loop (1+ j))
;; else
(cons i j))))))))
(define (string-next-token str i)
"Given a position i, this returns the position of the first non-whitespace character after i. If the end of line is reached, it returns the length of the string."
(or
(string-index str
(lambda (c)
(char-set-contains? char-set:blank c))
i)
(string-length str)))
(define (string-remove-comments str)
"Returns a copy of str with any '#' comments removed"
(let ((i (string-find-char-unquote str #\#)))
(if i
(string-take str i)
(string-copy str))))
(define (string-shrink-whitespace str start)
"Given a string, and a location in a string, this returns a new copy of string where all the whitespace beginning at location i is replaced by a single space"
(let ((len (string-length str)))
(if (or (>= start len)
(not (char-set-contains? char-set:blank (string-ref str start))))
(string-copy str)
;; else
(let loop ((end start))
(cond
((>= end len)
(string-append (substring str 0 start) " "))
((char-set-contains? char-set:blank (string-ref str end))
(loop (1+ end)))
(else
(string-append (substring str 0 start) " " (substring str end))))))))
(define (string-starts-with? str c)
(char=? (string-ref str 0) c))
;;; parse-libs.scm ends here

134
src/potato/parse.scm Normal file

@ -0,0 +1,134 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato parse)
#:use-module (srfi srfi-1)
#:use-module (ice-9 receive)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:use-module (potato parse-lib)
#:export (parse _readline))
;;; Commentary:
;;;
;;; Functionality to parse non-guile makefiles
;;;
;;; Code:
;; A makefile can contain rules, macro definitions, include lines, and comments.
(define (parse filename)
"FIXME-DOCS"
(with-input-from-file filename _eval #:guess-encoding #t))
(define (_eval)
"FIXME-DOCS"
(let ((filenames #f)
(ignoring #f)
(commands '()))
;; FIXME-QA(Krey): `(while #t` is not robust enough, specify the logic to lesser the chance of infinite loops
(while #t
(receive (line nlines)
(read-line-handle-escaped-newline)
(cond
((zero? nlines)
(break))
((string-starts-with? line #\tab)
;; Shell-command lines
(when filenames
(when ignoring
(continue))
(set! commands (append commands (list line)))))
(else
(display
(string-trim-both
(string-remove-comments
(string-collapse-continuations line #t))))
(newline)))))))
(define (string-parse-variable-definition str i)
"Parse a string as a variable definition"
(let loop ((i (string-next-token str)))
(cond
((= i (string-length str))
(values i 'null))
((char=? (string-ref str i) #\#)
;; Comments aren't variable definitions.
(values i 'null))
((char=? (string-ref str i) #\$)
;; This begins a variable expansion reference.
(let* ((openparen (false-if-exception (string-ref str (1+ i))))
(closeparen (if (eqv? openparen #\()
#\)
(if (eqv? openparen #\{)
#\}
#f))))
(if (not closeparen)
(values i 'null)
;; else, skip over the matching closeparen
(begin
(let ((count 0))
(while #t
(set! i (1+ i))
(when (char=? (string-ref str i) openparen)
(set! count (1+ count)))
(when (char=? (string-ref str i) closeparen)
(set! count (1- count))
(when (zero? count)
(set! i (1+ i))
(break)))))
;; Any whitespace before the operator?
(when (char-set-contains? char-set:blank (string-ref str i))
(set! wspace #t)
(set! i (string-next-token str i)))
(cond
((eqv? (string-ref str i) #\=)
(values (1+ i) 'recursive))
((and (eqv? (string-ref str i) #\:)
(eqv? (string-ref str (1+ i)) #\=))
(values (+ i 2) 'simple))
((and (eqv? (string-ref str i) #\+)
(eqv? (string-ref str (1+ i)) #\=))
(values (+ i 2) 'append))
((and (eqv? (string-ref str i) #\?)
(eqv? (string-ref str (1+ i)) #\=))
(values (+ i 2) 'conditional))
(else
(values i 'null)))))))
(else
(values i 'null)))))
;; STUB(Krey): Unfinished code by original author, kept here in case we need to finish it in the future
#|
(define (parse-var-assignment line)
(let ((i (string-next-token line 0)))
(if (= i (string-length line))
#f
;; else
(while #t
|#
;;; parse.scm ends here

208
src/potato/parser.scm Normal file

@ -0,0 +1,208 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato parser)
#:use-module (ice-9 peg)
#:use-module (srfi srfi-1)
#:use-module (ice-9 rdelim)
#:use-module (system vm trace)
#:use-module (potato exceptions)
#:use-module (potato makevars)
#:use-module (potato rules)
#:use-module (potato text)
#:export (parse))
;;; Commentary:
;;;
;;; Core functionality of the parsed for non-guile makefiles
;;;
;;; Code:
;; A makefile can contain rules, macro definitions, include lines,
;; and comments.
(define (parse filename)
"FIXME-DOCS"
(with-input-from-file filename parse-input #:guess-encoding #t))
(define (last-char str)
"FIXME-DOCS"
(string-ref str (1- (string-length str))))
(define (parse-input)
"FIXME-DOCS"
(while #t
(let loop ((line "")
(str (read-line)))
(cond
((eof-object? str)
(break))
((char=? (last-char str) #\\)
(loop (string-append line str) (read-line)))
(else
(parse-line (string-append line str)))))))
;; For include lines
(define-peg-pattern I_TOK none "include")
(define-peg-pattern I_SPACE none (or " " "\t"))
(define-peg-pattern I_FILENAME_CHAR body (or (range #\a #\z)
(range #\A #\Z)
(range #\0 #\9)
"_" "-" "."))
(define-peg-pattern I_FILENAME all (+ I_FILENAME_CHAR))
(define-peg-pattern I_NL none "\n")
(define-peg-pattern I_COMMENT none (and "#" (* peg-any)))
(define-peg-pattern INCLUDE all (and I_TOK
(+ (and (* I_SPACE)
I_FILENAME))
(* I_SPACE)
(? I_COMMENT)))
;; For comment lines
(define-peg-pattern C_SPACE none (or " " "\t"))
(define-peg-pattern C_COMMENT none (and "#" (* peg-any)))
(define-peg-pattern COMMENT none (or C_COMMENT
(and (+ C_SPACE) (not-followed-by peg-any))))
(define (parse-line line)
"FIXME-DOCS"
(write (peg:tree (match-pattern INCLUDE line)))
(newline)
(write (peg:tree (match-pattern COMMENT line)))
(newline)
(cond
((line-is-include? line)
(format #t "INCLUDE: ~S~%" line))
((line-is-comment? line)
(format #t "COMMENT: ~S~%" line))
((line-is-macro? line)
(format #t "MACRO: ~S~%" line))
((line-is-special-target? line)
(format #t "SPECIAL: ~S~%" line))
((line-is-inference-rule? line)
(format #t "INFERENCE: ~S~%" line))
((line-is-rule? line)
(format #t "RULE: ~S~%" line))
(else
(format #t "UNKNOWN: ~S~%" line))))
(define (line-is-include? line)
"FIXME-DOCS"
(and (> (string-length line) 8)
(string= line "include " 0 8)))
(define (line-is-comment? line)
"FIXME-DOCS"
(or (string-null? (string-trim-both line char-set:whitespace))
(char=? (string-ref line 0) #\#)))
(define (line-is-macro? line)
"FIXME-DOCS"
(let ((len (string-length line)))
(let loop ((i 0))
(if (>= i len)
#f
;; else
(let ((c (string-ref line i)))
(cond
((and (zero? i)
(not (char-is-pcs? c)))
#f)
((and (not (zero? i))
(char=? #\= c))
#t)
((not (char-is-pcs-or-space? c))
#f)
(else
(loop (+ i 1)))))))))
(define (line-is-special-target? line)
"FIXME-DOCS"
(or (and (>= (string-length line) 8)
(string= line ".DEFAULT" 0 8))
(and (>= (string-length line) 8)
(string= line ".IGNORE" 0 7))
(and (>= (string-length line) 6)
(string= line ".POSIX"))
(and (>= (string-length line) 9)
(string= line ".PRECIOUS" 0 9))
(and (>= (string-length line) 9)
(string= line ".SCCS_GET" 0 9))
(and (>= (string-length line) 7)
(string= line ".SILENT" 0 7))))
(define (line-is-rule? line)
"FIXME-DOCS"
(let ((len (string-length line)))
(let loop ((i 0))
(if (>= i len)
#f
;; else
(let ((c (string-ref line i)))
(cond
((and (zero? i)
(not (char-is-pcs? c)))
#f)
((and (not (zero? i))
(char=? #\: c))
#t)
((not (char-is-pcs-or-space? c))
#f)
(else
(loop (+ i 1)))))))))
(define (line-is-inference-rule? line)
"FIXME-DOCS"
(let ((len (string-length line)))
(let loop ((i 0)
(dot-count 0))
(if (>= i len)
#f
;; else
(let ((c (string-ref line i)))
(cond
((and (zero? i)
(not (char=? #\. c)))
#f)
((and (not (zero? i))
(char=? #\: c))
(if (or (= dot-count 1)
(= dot-count 2))
#t
#f))
((not (char-is-pcs? c))
#f)
(else
(loop (+ i 1)
(+ dot-count
(if (char=? c #\.)
1
0))))))))))
(define (char-is-pcs? c)
"FIXME-DOCS"
(or (and (char<=? #\a c) (char>=? #\z c))
(and (char<=? #\A c) (char>=? #\Z c))
(and (char<=? #\0 c) (char>=? #\9 c))
(char=? #\. c)
(char=? #\_ c)))
(define (char-is-pcs-or-space? c)
"FIXME-DOCS"
(or (char-is-pcs? c)
(char=? #\space c)))
;;; parser.scm ends here

989
src/potato/rules.scm Normal file

@ -0,0 +1,989 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato rules)
#:use-module (ice-9 pretty-print)
#:use-module (ice-9 optargs)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (potato exceptions)
#:use-module (potato builtins)
#:use-module (potato makevars)
#:use-module (potato text)
#:export(<target-rule>
<suffix-rule>
<node>
%target-rules
%suffix-rules
initialize-rules
first-target-rule-name
install-alternate-system-driver
target-rule :
suffix-rule ->
target-name $@
newer-prerequisites $? $$?
primary-prerequisite $<
target-basename $*
prerequisites $^ $$^
build
string-compose ~
silent-compose ~@
always-execute-compose ~+
ignore-error-compose ~-))
;;; Commentary:
;;;
;;; Dedicated to logic processing of rules/tasks
;;;
;;; Code:
;; FIXME-QA(Krey): Should be re-structured so that the function that are just making aliases to procedures have their own section for easier navigation
;; FIXME-QA/PROD(Krey): Doesn't seem to have a robust code and is using lot of functions that have potential for infinite loops, should be considered prior to deployment into a production environment
;;; GLOBALS
(define %ignore-errors? #f) ;; FIXME-QA/DOCS(Krey): What is this variable used for?
(define %continue-on-error? #f) ;; FIXME-QA/DOCS(Krey): What is this variable used for?
(define %no-execution? #f) ;; FIXME-QA/DOCS(Krey): What is this variable used for?
(define %verbosity 2) ;; FIXME-QA/DOCS(Krey): What is this variable used for?
(define %ascii? #f) ;; FIXME-QA/DOCS(Krey): What is this variable used for?
(define %top-level-targets '()) ;; FIXME-QA/DOCS(Krey): What is this variable used for?
;;; HELPER FUNCTIONS
(define (basename str)
"Strip off the '.ext' part of a filename string."
(unless (string? str)
(scm-error 'wrong-type-arg "basename" "Not a string: ~S" (list str) #f))
(let ((idx (string-index-right str #\.)))
(if idx
(substring str 0 idx)
str)))
(define (base-compose . args)
"Returns a lambda that appends args together as a string, adding intermediate spaces. If an arg is a procedure, it is evaluated."
(lambda ()
;; Loop over all the args, appending them together as a string. Try to be smart about the types of args.
(let loop ((args args)
(result ""))
(cond
((null? args)
result)
(else
(let ((arg (car args))
(effective-arg #f))
(cond
((procedure? arg)
(set! effective-arg (arg))
(unless (string? effective-arg)
(bad-proc-output "~" arg)))
((string? arg)
(set! effective-arg arg))
(else
;; NOTE(spk121): Not a string or procedure? Let's just write it, I guess. YOLO!
(set! effective-arg
(format #f "~a" arg))))
;; Loop, only adding spaces as necessary
(let ((need-a-space?
(and (not (string-null? result))
(not (string-null? effective-arg)))))
(loop
(cdr args)
(string-append
result
(if need-a-space? " " "")
effective-arg)))))))))
(define (string-compose . args)
"FIXME-DOCS"
(cons 'default (apply base-compose args)))
(define ~ string-compose)
(define (ignore-error-compose . args)
"FIXME-DOCS"
(cons 'ignore-error (apply base-compose args)))
(define ~- ignore-error-compose)
(define (silent-compose . args)
"FIXME-DOCS"
(cons 'silent (apply base-compose args)))
(define ~@ silent-compose)
(define (always-execute-compose . args)
"FIXME-DOCS"
(cons 'always-execute (apply base-compose args)))
(define ~+ always-execute-compose)
(define (regular-file? filename)
"FIXME-DOCS"
(unless (string? filename)
(scm-error 'wrong-type-arg "regular-file?" "Not a string: ~S" (list filename) #f))
(let ((st (stat filename #f)))
(eq? (stat:type st) 'regular)))
(define (compute-mtime filename)
"FIXME-DOCS"
(unless (string? filename)
(scm-error 'wrong-type-arg "regular-file?" "Not a string: ~S" (list filename) #f))
(let ((st (stat filename #f)))
(+ (* 1000000000 (stat:mtime st))
(stat:mtimensec st))))
;; FIXME-DOCS/QA(Krey): What is this doing?
(define %system-proc system)
(define (install-alternate-system-driver proc)
"Give a procure to use rather than the standard 'system' procedure, installs it as the system driver. Returns the old system driver."
(unless (procedure? proc)
(scm-error 'wrong-type-arg "install-alternate-system-driver" "Not a procedure: ~S" (list proc) #f))
(let ((old-proc %system-proc))
(set! %system-proc proc)
old-proc))
;;; TARGET STRUCT AND METHODS
(define-record-type <target-rule>
(make-target-rule name prerequisites recipes priority)
target-rule?
;; A filename, for real targets, or just a name for phony targets
(name target-rule-get-name target-rule-set-name!)
;; A list of filenames and/or phony targets that have target rules
(prerequisites target-rule-get-prerequisites
target-rule-set-prerequisites!)
;; A list of strings or procedures
(recipes target-rule-get-recipes
target-rule-set-recipes!)
;; 1 = script-defined. 2 = built-in
(priority target-rule-get-priority
target-rule-set-priority!))
;; List of all target rules in order of importance
(define %target-rules '())
(define* (target-rule name #:optional (prerequisites '()) #:rest recipes)
"Register a new target rule"
(when (>= %verbosity 3)
(if (null? prerequisites)
(format #t "Target rule: ~a~A~a~%~!" (lquo) name (rquo))
(format #t "Target rule: ~a~A~a ~A ~A~%~!" (lquo) name (rquo) (left-arrow) prerequisites)))
;; Empty recipes is shorthand for a recipe that always passes.
(when (null? recipes)
(set! recipes (list #t)))
;; NOTE(spk121): If any recipes are raw strings, we need to make them into `(cons 'default string)`
(let ((recipes2
(map (lambda (recipe)
(cond
((pair? recipe)
recipe)
(else
(cons 'default recipe))))
recipes)))
(let ((rule (make-target-rule name prerequisites recipes2 1)))
;; Add to %target-rules
(set! %target-rules (cons rule %target-rules)))))
;; Alias
(define : target-rule)
(define (first-target-rule-name)
(if (null? %target-rules)
#f
;; else
(target-rule-get-name (last %target-rules))))
;;; SUFFIX STRUCT AND METHODS
(define-record-type <suffix-rule>
(make-suffix-rule source-suffix target-suffix recipes priority)
suffix-rule?
;; A string, usually like ".c". Or a string->string proc.
(source-suffix suffix-rule-get-source
suffix-rule-set-source)
;; A string, usually like ".o". Or a string->bool proc.
(target-suffix suffix-rule-get-target
suffix-rule-set-suffix!)
;; A list of strings or procedures
(recipes suffix-rule-get-recipes
suffix-rule-set-recipes!)
;; 1 = script-defined. 2 = built-in
(priority suffix-rule-get-priority
suffix-rule-set-priority!))
;; The list of all registered suffix rules in order of importance
(define %suffix-rules '())
(define (suffix-rule source target . recipes)
"Register a suffix rule"
;; FIXME(spk121): Typecheck
(when (>= %verbosity 3)
(format #t "Suffix rule: ~a~A~a ~A ~a~A~a~%~!"
(lquo) source (rquo) (right-arrow) (lquo) target (rquo)))
;; NOTE(spk121): If any recipes are raw strings, we need to make them into `(cons 'default string)`
(let ((recipes2
(map (lambda (recipe)
(cond
((pair? recipe)
recipe)
(else
(cons 'default recipe))))
recipes)))
(let ((rule (make-suffix-rule source target recipes2 1)))
(set! %suffix-rules (cons rule %suffix-rules)))))
;; Alias
(define -> suffix-rule)
;;; NODE STRUCT AND METHODS
(define-record-type <node>
(make-node name parent status)
node?
;; For a real target, this is a filename. For a phony target it is
;; just a label.
(name node-get-name node-set-name!)
;; A <node> which is the parent of this node, or #f.
(parent node-get-parent node-set-parent!)
;; If 'name' is a regular file, mtime holds its last modification
;; time in nanoseconds since the epoch. If 'name' does not exist,
;; _mtime is #f.
(mtime node-get-mtime node-set-mtime!)
;; One of 'pass, 'fail, or 'undetermined
(status node-get-status node-set-status!)
;; Either 'target or 'suffix or 'default
(rule-type node-get-rule-type node-set-rule-type!)
;; A list of rules
(rules node-get-rules node-set-rules!)
(children node-get-children node-set-children!))
(define (using-target-rule? node)
"FIXME-DOCS"
(eq? 'target (node-get-rule-type node)))
(define (using-suffix-rules? node)
"FIXME-DOCS"
(eq? 'suffix (node-get-rule-type node)))
(define (using-default-rule? node)
"FIXME-DOCS"
(eq? 'default (node-get-rule-type node)))
(define (set-fail! node)
"FIXME-DOCS"
(node-set-status! node 'fail))
(define (set-pass! node)
"FIXME-DOCS"
(node-set-status! node 'pass))
(define (failed? node)
"FIXME-DOCS"
(eqv? (node-get-status node) 'fail))
(define (passed? node)
"FIXME-DOCS"
(eqv? (node-get-status node) 'pass))
(define (leaf-node? node)
"FIXME-DOCS"
(null? (node-get-children node)))
(define (undetermined? node)
"FIXME-DOCS"
(eq? (node-get-status node) 'undetermined))
(define (any-child-has-passed? node)
"FIXME-DOCS"
(unless (node? node)
(scm-error 'wrong-type-arg "any-child-has-passed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "any-child-has-passed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(any passed? children)))
(define (every-child-has-passed? node)
"FIXME-DOCS"
(unless (node? node)
(scm-error 'wrong-type-arg "every-child-has-passed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "every-child-has-passed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(every passed? children)))
(define (any-child-has-failed? node)
"FIXME-DOCS"
(unless (node? node)
(scm-error 'wrong-type-arg "any-child-has-failed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "any-child-has-failed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(any failed? children)))
(define (every-child-has-failed? node)
"FIXME-DOCS"
(unless (node? node)
(scm-error 'wrong-type-arg "every-child-has-failed?" "Not a node: ~S" (list node) #f))
(when (null? (node-get-children node))
(scm-error 'misc-error "every-child-has-failed?" "Node ~a has no children"
(list (node-get-name node)) #t))
(let ((children (node-get-children node)))
(every failed? children)))
(define (children-complete? node)
"FIXME-DOCS"
(cond
((leaf-node? node)
#t)
((eqv? 'target (node-get-rule-type node))
(or (every-child-has-passed? node)
(any-child-has-failed? node)))
((eqv? 'suffix (node-get-rule-type node))
(or (every-child-has-failed? node)
(any-child-has-passed? node)))
(else
#f)))
(define (children-passed? node)
"FIXME-DOCS"
(cond
((null? (node-get-children node))
#t)
((eq? 'target (node-get-rule-type node))
(every-child-has-passed? node))
((eq? 'suffix (node-get-rule-type node))
(any-child-has-passed? node))
(else
#f)))
(define (get-next-child node)
"Return the first child node that is not yet PASS or FAIL"
(let ((children (node-get-children node)))
(cond
((null? children)
#f)
(else
(any (lambda (child)
(if (eqv? (node-get-status child) 'undetermined)
child
#f))
children)))))
(define (has-parent? node)
"FIXME-DOCS"
(if (node-get-parent node)
#t
#f))
(define (has-children? node)
"FIXME-DOCS"
(if (null? (node-get-children node))
#f
#t))
(define (get-parent node)
"FIXME-DOCS"
(node-get-parent node))
(define (up-to-date? node)
"Checks if node is up to date:
- it has an mtime
- all its children have mtimes
- its mtime is older than the mtime of its children"
(let ((children (node-get-children node))
(parent-mtime (node-get-mtime node)))
(if (or (null? children) (not (integer? parent-mtime)))
;; Targets without children are always rebuilt.
;; Targets without mtimes are always rebuilt.
#f
(let ((children-mtime (map node-get-mtime children)))
(if (every (lambda (child-mtime)
(and (integer? child-mtime)
(>= parent-mtime child-mtime)))
children-mtime)
#t
#f)))))
(define (node-depth node)
"FIXME-DOCS"
(let loop ((depth 0)
(cur node))
(if (has-parent? cur)
(loop (1+ depth) (get-parent cur))
;;
depth)))
(define (node-depth-string node)
(make-string (* 2 (node-depth node)) #\space))
;; AUTOMATIC VARIABLES
(define target-name 'unspecified) ;; FIXME-DOCS(Krey): What is this variable doing?
(define target-basename 'unspecified) ;; FIXME-DOCS(Krey): What is this variable doing?
(define prerequisites '()) ;; FIXME-DOCS(Krey): What is this variable doing?
(define primary-prerequisite 'unspecified) ;; FIXME-DOCS(Krey): What is this variable doing?
(define newer-prerequisites '()) ;; FIXME-DOCS(Krey): What is this variable doing?
(define (string-append-with-spaces lst)
"Appends the strings in lst, adding spaces in between."
(if (null? lst)
""
;; else
(fold
(lambda (elem prev)
(string-append prev " " elem))
(car lst)
(cdr lst))))
;; Aliases
(define $@ (lambda () target-name))
(define $* (lambda () target-basename))
(define $< (lambda () primary-prerequisite))
(define $$? (lambda () newer-prerequisites))
(define $? (lambda () (string-append-with-spaces newer-prerequisites)))
(define $$^ (lambda () prerequisites))
(define $^ (lambda () (string-append-with-spaces prerequisites)))
(define (target-rule-prep-automatic-variables node rule)
"FIXME-DOCS"
(set! target-name (node-get-name node))
(set! target-basename (basename target-name))
(set! prerequisites (target-rule-get-prerequisites rule))
(set! primary-prerequisite (if (null? prerequisites) "" (car prerequisites)))
(set! newer-prerequisites
;; If this node doesn't have a real file attached, then all prerequistes are "newer"
(if (not (node-get-mtime node))
prerequisites
;; Prerequisites that have no mtime or a higher mtime are "newer"
(filter-map
(lambda (name)
(cond
((and (file-exists? name)
(regular-file? name)
(>= (node-get-mtime node) (compute-mtime name)))
name)
((not (file-exists? name))
name)
(else
#f)))
prerequisites))))
(define (suffix-rule-prep-automatic-variables node rule)
"FIXME-DOCS"
(set! target-name (node-get-name node))
(set! target-basename (basename target-name))
(set! primary-prerequisite (string-append target-basename (suffix-rule-get-source rule)))
(set! prerequisites (list primary-prerequisite))
(set! newer-prerequisites
;; If this node doesn't have a real file attached, then the prerequisite is newer
(if (not (node-get-mtime node))
(list primary-prerequisite)
;; Prerequisites that have no mtime or a higher mtime are "newer"
(cond
((and (file-exists? primary-prerequisite)
(regular-file? primary-prerequisite)
(> (node-get-mtime node) (compute-mtime primary-prerequisite)))
(list primary-prerequisite))
(else
'())))))
;;; MIXED METHODS
;;; requiring more than one of node, automatic variables, suffix rules and target rules
(define (add-builtins)
"FIXME-DOCS"
;; FIXME(Krey): Commented out by the original author, figure out what we want to do with it
#|
(-> ".c" ""
(~ ($ CC) ($ CFLAGS) ($ LDFLAGS) "-o" $@ $<))
(-> ".f" ""
(~ ($ FC) ($ FFLAGS) ($ LDFLAGS) "-o" $@ $<))
(-> ".sh" ""
(~ "cp" $< $@)
(~ "chmod a+x" $< $@))
|#
(-> ".c" ".o"
(~ ($ CC) ($ CFLAGS) "-c" $<))
(-> ".f" ".o"
(~ ($ FC) ($ FFLAGS) ",c" $<))
(-> ".y" ".o"
(~ ($ YACC) ($ YFLAGS) $<))
(-> ".l" ".o"
(~ ($ LEX) ($ LFLAGS) $<)
(~ ($ CC) ($ CFLAGS) "-c lex.yy.c")
"rm -f lex.yy.c"
(~ "mv lex.yy.o" $@))
(-> ".y" ".c"
(~ ($ YACC) ($ YFLAGS) $<)
(~ "mv y.tab.c" $@))
(-> ".l" ".c"
(~ ($ LEX) ($ LDFLAGS) $<)
(~ "mv lex.yy.c" $@))
(-> ".scm" ".go"
(~ ($ GUILD) "compile" ($ GFLAGS) $<)))
(define (run-target-rule! node)
"Runs the (singular) target rule associated with this node"
(unless (node? node)
(scm-error 'wrong-type-arg "run-target-rule!" "Not a node: ~S" (list node) #f))
(let ((rules (node-get-rules node)))
(when (null? rules)
(scm-error 'misc-error "run-target-rule!" "Node ~S has no target rules"
(list (node-get-name node)) #f))
(unless (= 1 (length rules))
(scm-error 'misc-error "run-target-rule!" "Node ~S has ~A target rules"
(list (node-get-name node) (length rules)) #f))
(unless (or (leaf-node? node) (every-child-has-passed? node))
(scm-error 'misc-error "run-target-rule!" "Node ~S: not all children have passed"
(list (node-get-name node)) #f))
(let ((rule (car rules)))
(target-rule-prep-automatic-variables node rule)
(run-recipes! node (target-rule-get-recipes rule))
(let ((status (node-get-status node)))
status))))
(define (run-suffix-rules! node)
"Runs the one-or-more suffix rules associated with this node. It runs them one-by-one, quitting on the first success"
(unless (node? node)
(scm-error 'wrong-type'arg "run-suffix-rules!" "Not a node: ~S" (list node) #f))
(let ((rules (node-get-rules node))
(children (node-get-children node)))
(when (null? rules)
(scm-error 'misc-error "run-suffix-rules!" "Node ~S has no rules"
(list (node-get-name node)) #f))
(when (null? children)
(scm-error 'misc-error "run-suffix-rule!" "Node ~S has no children"
(list (node-get-name node)) #f))
(unless (any-child-has-passed? node)
(scm-error 'misc-error "run-suffix-rule!" "Node ~S: not child has passed"
(list (node-get-name node)) #f))
(unless (= (length rules) (length children))
(scm-error 'misc-error "run-suffix-rule!" "Node ~S: must have as many children as rules"
(list (node-get-name node)) #f))
(let ((i 0)
(len (length children)))
(while (< i len)
(let ((rule (list-ref rules i))
(child (list-ref children i)))
(when (passed? child)
(when (>= %verbosity 3)
(format #t "~A: attempting to make using ~a~A~a ~a ~a~A~a rule"
(node-get-name node)
(lquo) (suffix-rule-get-source rule) (rquo)
(right-arrow)
(lquo) (suffix-rule-get-target rule) (rquo)))
(suffix-rule-prep-automatic-variables node rule)
(run-recipes! node (suffix-rule-get-recipes rule)))
(when (passed? node)
(break))
(set! i (1+ i)))))
(when (>= %verbosity 3)
(if (passed? node)
(format #t "PASS: ~a~%~!" (node-get-name node))
(format #t "FAIL: ~a~%~!" (node-get-name node))))
(node-get-status node)))
(define (run-recipes! node recipes)
"Runs the recipes on this node, one by one. Recipes are either strings, procedures that return strings, or generic procedures. If a
failure condition happens, mark the node as having failed."
(unless (node? node)
(scm-error 'wrong-type-arg "run-recipes!" "Not a node: ~S" (list node) #f))
;; FIXME(Krey): Commented out by the original author, figure out what we want to do with it
;;(unless (and (list? recipes) (not (null? recipes)))
;; (scm-error 'wrong-type-arg "run-recipes!" "Not a non-null list: ~S" (list recipes) #f))
(let ((i 0)
(len (length recipes)))
(while (< i len)
(let* ((opt/recipe (list-ref recipes i))
(opt (car opt/recipe))
(recipe (cdr opt/recipe)))
;; Recipes are either
;; - strings to pass to system
;; - procedures that return a string which is passed to system
;; - procedures (that don't return a string) that are executed that pass unless they return #f
;; OPT is one of 'default, 'ignore, 'silent
(cond
((eq? recipe #t)
(set-pass! node))
((eq? recipe #f)
(set-fail! node))
((string? recipe)
(when (= %verbosity 1)
(format #t "~a~%~!" (node-get-name node)))
(when (or (and (= %verbosity 2) (not (eq? 'silent opt)))
(= %verbosity 3))
(format #t "~A~%~!" recipe))
(let ((retval (%system-proc recipe)))
(if (zero? retval)
(set-pass! node)
(set-fail! node))))
((procedure? recipe)
(let ((retval (recipe)))
(cond
;; If a procedure returns a string, that string gets processed by system
((string? retval)
(when (= %verbosity 1)
(format #t "~a~%~!" (node-get-name node)))
(when (or (and (= %verbosity 2) (not (eq? 'silent opt)))
(= %verbosity 3))
(format #t "~A~%~!" retval))
(let ((retval2 (%system-proc retval)))
(if (zero? retval2)
(set-pass! node)
(set-fail! node))))
;; A scheme procedure recipe that returns false.
((eqv? retval #f)
(set-fail! node))
(else
;; Otherwise, this was a procedure that didn't return #f or a string, so it gets a pass.
(set-pass! node)))))
(else
;; Can't be converted to a viable string or procedure
(scm-error 'misc-error "run-recipes!" "bad recipe: ~S" (list recipe) #f)))
(when (failed? node) (break))
(set! i (1+ i))))
(when (passed? node)
(let ((name (node-get-name node)))
(when (and (file-exists? name)
(regular-file? name))
(node-set-mtime! node (compute-mtime name)))))))
(define (run-default-rule! node)
"The default rule if not other rule exists. It just passes if the file exists"
(let ((name (node-get-name node)))
(if (and (file-exists? name)
(regular-file? name))
(begin
(set-pass! node)
(node-set-mtime! node (compute-mtime name)))
;; else
(set-fail! node))))
;; Start at root
;; If cur is UNDETERMINED, find a leaf that is UNDETERMINED.
;; Descent to first leaf.
;; If self's mtime is earlier than parent's mtime, mark self as PASS.
;; Elif self has rules, run rules and mark self PASS/FAIL.
;; Else self has no mtime or rules, so mark self FAIL.
;; Go to parent.
;; IF PASS or FAIL, go to parent
;; IF UNDETERMINED do these...
;; Are we done with the children?
;; If AND rule and one child is FAIL, stop
;; If OR rule and one child is PASS, stop
;; If no children left, stop
;; Else keep going
;; Did the children pass?
;; IF AND rule and all children are PASS, true
;; IF OR rule an one child is PASS, true
;; Otherwise, false
;; If the children FAIL, cur is FAIL
;; If the children PASS, run rules and mark self PASS/FAIL
;; Go to parent
;; 3 failures
;; - If anything fails, stop immediately
;; - If anything fails, searching through tree
;; - Ignore errors
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LET'S GO!
(define (initialize-rules targets builtins? ignore-errors? continue-on-error? no-execution? verbosity ascii?)
(set! %target-rules '())
(set! %suffix-rules '())
(set! %top-level-targets targets)
(set! %ignore-errors? ignore-errors?)
(set! %continue-on-error? continue-on-error?)
(set! %no-execution? no-execution?)
(set! %verbosity verbosity)
(set! %ascii? ascii?)
(when builtins?
(add-builtins)))
(define (create-node name parent)
"Constructs a tree of nodes, with name as the root node."
(when (and (node? parent) (> (node-depth parent) 30))
;; FIXME-TRANSLATE(Krey)
(error "Stack overflow"))
(let ((node (make-node name parent 'undetermined)))
(node-set-children! node '())
(node-set-rule-type! node 'default)
;; FIXME(spk121): here check that this name differs from all ancestor's names
;; Try to the file's modification time.
(when (file-exists? name)
(when (not (regular-file? name))
(not-a-regular-file "create-node" name))
(when (not (access? name R_OK))
(no-read-access-to-file "create-node" name))
(node-set-mtime! node (compute-mtime name)))
;; Search for matching target rule
(when (not (null? %target-rules))
(let loop ((rule (car %target-rules))
(rest (cdr %target-rules)))
;; NOTE(spk121): here we assume target rule names and predicates are exclusively strings
(if (string=? name (target-rule-get-name rule))
(begin
;; OK we have a matching rule
(node-set-rules! node (list rule))
(node-set-rule-type! node 'target)
;; For target-rules, the prerequisites comes from the rule itself
;; Oooh, recursion!
(node-set-children! node
(map (lambda (prereq)
(create-node prereq node))
(target-rule-get-prerequisites rule))))
;; else
(if (not (null? rest))
(loop (car rest) (cdr rest))
;; else, no matching rule found
(node-set-rules! node '())))))
;; If no rule found so far, search for suffix rules.
(when (null? (node-get-rules node))
(for-each
(lambda (rule)
(let ((targ (suffix-rule-get-target rule)))
(when (string-suffix? targ name)
;; For suffix rules, there will be exactly one child per rule and the name of the child is constructed from a suffix and the parent's name
(node-set-rules! node (cons rule (node-get-rules node)))
(node-set-rule-type! node 'suffix)
(let* ((src (suffix-rule-get-source rule))
(prereq
(string-append
(string-drop-right name (string-length src))
src)))
;; Note the recursion here.
(node-set-children! node
(cons (create-node prereq node)
(node-get-children node)))))))
%suffix-rules))
;; FIXME(spk121): First matching rule has highest priority? Or is last better?
(node-set-rules! node (reverse (node-get-rules node)))
(node-set-children! node (reverse (node-get-children node)))
;; FIXME(Krey): This was commented out by the original author, figure out what we want to do with it
;;(format #t "matching suffix rules ~S~%~!" (node-get-rules node))
;;(format #t "matching children rules ~S~%~!" (node-get-children node))
;; And node is ready to go
node))
(define (build root)
"Give a tree of <node>, this executes the recipes therein.
This is where the magic happens."
(let ((tree (create-node root #f)))
(let ((node tree))
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ABegin building target ~a~A~a.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(while #t
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~AConsidering target ~a~A~a.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(if (undetermined? node)
(begin
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a is undetermined.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo))
(unless (node-get-mtime node)
;; FIXME-TRANSLATE(Krey)
(format #t "~AFile ~a~A~a does not exist.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo))))
(if (children-complete? node)
(begin
(when (and (>= %verbosity 3) (has-children? node))
;; FIXME-TRANSLATE(Krey)
(format #t "~AFinished prerequisites of target file ~a~A~a.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(if (children-passed? node)
(begin
(when (and (>= %verbosity 3) (has-children? node))
;; FIXME-TRANSLATE(Krey)
(format #t "~AThe prerequisites of target file ~a~A~a have passed.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(if (up-to-date? node)
(begin
(when (node-get-mtime node)
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a is up to date.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo))))
(set-pass! node))
;; else, not up to date
(begin
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a is not up to date.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(cond
((using-target-rule? node)
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a has a target rule.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(run-target-rule! node))
((using-suffix-rules? node)
(when (>= %verbosity 3)
(format #t "~ATarget file ~a~A~a has a suffix rule.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(run-suffix-rules! node))
((using-default-rule? node)
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a is using the default rule.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(run-default-rule! node))
(else
(error "bad rules")))
(if (passed? node)
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a has passed.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a has failed.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))))))
;; else, children have failed
(begin
(when (>= %verbosity 3)
(format #t "~AThe prerequisites of target file ~a~A~a have failed.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(set-fail! node))))
;; else, children aren't complete
(begin
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~AThe prerequisites of target file ~a~A~a are incomplete.~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)))
(let ((next (get-next-child node)))
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ADescending node ~a~A~a ~a ~a~A~a.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(right-arrow)
(lquo) (node-get-name next) (rquo)))
(set! node (get-next-child node))
))))
;; else, this node is determined
(begin
(if (passed? node)
(when (>= %verbosity 2)
;; FIXME-TRANSLATE(Krey)
(format #t "~A~a~A~a: ~APASS~A~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)
(green) (default)))
(when (>= %verbosity 2)
;; FIXME-TRANSLATE(Krey)
(format #t "~A~a~A~a: ~AFAIL~A~%~!"
(node-depth-string node) (lquo) (node-get-name node) (rquo)
(red) (default))))
(if (has-parent? node)
(begin
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~AAscending node ~a~A~a ~a ~a~A~a.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(right-arrow)
(lquo) (node-get-name (node-get-parent node)) (rquo)))
(set! node (get-parent node)))
;; else, there is no parent to this node
(begin
(when (>= %verbosity 3)
;; FIXME-TRANSLATE(Krey)
(format #t "~ATarget file ~a~A~a has no parent.~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)))
(if (passed? node)
(when (>= %verbosity 1)
;; FIXME-TRANSLATE(Krey)
(format #t "~A~a~A~a: ~ACOMPLETE~A~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(green) (default)))
(when (>= %verbosity 1)
;; FIXME-TRANSLATE(Krey)
(format #t "~A~a~A~a: ~ACOMPLETE~A~%~!"
(node-depth-string node)
(lquo) (node-get-name node) (rquo)
(red) (default))))
(break)))))))
;; Return the command output of the root node
(passed? tree)))
;;; rules.scm ends here

148
src/potato/text.scm Normal file

@ -0,0 +1,148 @@
;;; The Project Manager ("pman") -- GNU Guile-based solution for project management
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute 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 file 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 project. If not, see <http://www.gnu.org/licenses>
;;;
;;; This file incorporates work covered by the following copyright and permission notice:
;;;
;;; Copyright (C) 2017-2021 Mike Gran <spk121@yahoo.com>
;;;
;;; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
(define-module (potato text)
#:export (underline
default
right-arrow
left-arrow
ellipses
C0
red green
lquo
rquo
initialize-text))
;;; Commentary:
;;;
;;; File handling the text formatting in the repository
;;;
;;; Code:
(define %fancy #t)
(define (initialize-text ascii)
"FIXME-DOCS"
(set! %fancy (not ascii)))
(define (default)
"FIXME-DOCS"
(if %fancy
(string #\escape #\[ #\0 #\m)
""))
(define (bold)
"FIXME-DOCS"
(if %fancy
(string #\escape #\[ #\1 #\m)
""))
(define (underline)
"FIXME-DOCS"
(if %fancy
(string #\escape #\[ #\4 #\m)
""))
(define (red)
"FIXME-DOCS"
(if %fancy
(string #\escape #\[ #\3 #\1 #\m)
""))
(define (green)
"FIXME-DOCS"
(if %fancy
(string #\escape #\[ #\3 #\2 #\m)
""))
(define (blue)
"FIXME-DOCS"
(if %fancy
(string #\escape #\[ #\3 #\4 #\m)
""))
(define (important)
"FIXME-DOCS"
(if %fancy
"⚠" ; U+26A0 WARNING SIGN
"!!!"))
(define (stop)
"FIXME-DOCS"
(if %fancy
"🛑" ; U+26A0 WARNING SIGN
"XXX"))
(define (right-arrow)
"FIXME-DOCS"
(if %fancy
"→" "->"))
(define (left-arrow)
"FIXME-DOCS"
(if %fancy
"←" "<-"))
(define (ellipses)
"FIXME-DOCS"
(if %fancy "…" "..."))
(define (QED)
"FIXME-DOCS"
(if %fancy "∎" "QED")) ; U+220E END OF PROOF
(define (C0 c)
"FIXME-DOCS"
(if %fancy
;; Replace control codes with control pictures
(string (integer->char (+ #x2400 (char->integer c))))
(list-ref '("<NUL>" "<SOH>" "<STX>" "<ETX>" "<EOT>" "<ENQ>"
"<ACK>" "<BEL>" "<BS>" "<HT>" "<LF>"
"<VT>" "<FF>" "<CR>" "<SO>" "<SI>"
"<DLE>" "<DC1>" "<DC2>" "<DC3>" "<DC4>"
"<NAK>" "<SYN>" "<ETB>" "<CAN>" "<EM>"
"<SUB>" "<ESC>" "<FS>" "<GS>" "<RS>"
"<US>")
(char->integer c))))
(define (lquo)
"FIXME-DOCS"
(if %fancy (string #\“) (string #\")))
(define (rquo)
"FIXME-DOCS"
(if %fancy (string #\”) (string #\")))
(define (BOL)
"go to beginning of line"
(if %fancy (string #\escape #\[ #\G) "\n"))
#|
in quiet mode it is just
target -> parent (when building)
target -> parent (on pass)
target -> parent (on fail but continue)
🛑 target -> parent (on stop)
(on successful completion)
in normal mode it is
? target -> parent
recipe truncated to 70 cols, using C0 control pics
etc
then
target -> parent (on pass)
|#
;; text.scm ends here

1
src/potato/zz-README.org Normal file

@ -0,0 +1 @@
The main directory of the project storing the invidual declarations used for processing

1
src/zz-README.org Normal file

@ -0,0 +1 @@
Source code of the project

4
tests/zz-README.org Normal file

@ -0,0 +1,4 @@
Directory storing tests
NOTE-QA(Krey): Tests were ignored in the QA, decided that they should be rewritten once we finish refactor of the project