Commit Graph

181 Commits

Author SHA1 Message Date
rillig 730db1a03f make: rename a few functions to be more descriptive
No functional change.
2021-04-04 10:05:08 +00:00
rillig 244fd9f4c4 make: use C99 bool type instead of defining its own
No functional change.
2021-04-03 11:08:40 +00:00
rillig 2f8026b0e5 make: replace enum bit-field with struct bit-field for VarEvalFlags
This makes the code easier to read, especially in var.c.  It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases.  Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly.  This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
2021-03-15 12:15:03 +00:00
rillig 49c1680d06 make: remove freestanding freeIt variables
These variables all belong to a string variable.  Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
2021-02-22 23:21:33 +00:00
sjg 2b67d42e71 Avoid strdup in mkTempFile
Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
2021-02-05 19:19:17 +00:00
rillig 835b4db442 make: in the Var_ functions, move the scope to the front
This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
2021-02-05 05:15:12 +00:00
rillig 5980c2c341 make: rename some VAR constants to SCOPE
The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less.  Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments.  These are:

	GNode.vars (because of line breaks)
	GNode_Free (dito)
	varname-make_print_var_on_error.mk
	varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
2021-02-04 21:33:13 +00:00
rillig b3cadd8df0 make: rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete
The function names now follow the naming scheme from the other functions
that handle variables.

There are several calls that remain syntactically unchanged but that
omit the call to strchr('$') now.  Since all these calls use constant
variable names, there is no functional change.
2021-02-03 15:08:17 +00:00
rillig a1bc5ad8cf make: replace Global_AppendExpand with Global_Append
All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand.  After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
2021-02-03 13:53:12 +00:00
rillig 87686000da make: replace Global_SetExpand with Global_Set for constant names 2021-02-03 08:08:18 +00:00
rillig 3ec10f8db6 make: use shortcut functions Global_SetExpand and Global_AppendExpand
There are many places where global variables are set or appended to.  To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded.  In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
2021-02-03 08:00:36 +00:00
rillig 1baad74e75 make: clean up comments 2021-02-01 21:32:54 +00:00
rillig e820145aad make(1): fix a few inconsistencies for lint's strict bool mode 2021-01-16 20:49:31 +00:00
rillig 31940a95cd make(1): consistently use boolean expressions in conditions
Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set.  If Boolean is an ordinary
integer type (the default), some high bits may get lost.  But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
2021-01-10 21:20:46 +00:00
rillig 462cbdfa37 make(1): fix lint warnings 2021-01-09 16:06:09 +00:00
rillig 71c58e78f7 make(1): replace pointers in controlling conditions with booleans 2020-12-31 17:39:36 +00:00
rillig 82632c2fd8 make(1): fix return type of macro DEBUG
This macro was supposed to return a boolean expression all the time, it
just hadn't been implemented this way.  This resulted in wrong output
for the test sh-flags, in compilation modes -DUSE_UCHAR_BOOLEAN and
-DUSE_CHAR_BOOLEAN, since in ParseCommandFlags, the expression
DEBUG(LOUD) didn't fit into a boolean.
2020-12-22 22:31:50 +00:00
rillig 94f06ed7ea make(1): fix undefined behavior in meta_oodate
Do not increment a null pointer.

Do not assign to a variable twice in the same statement.  To be fair,
this may be safe because of the sequence point when the function is
called, but anyway, it looks too close to undefined behavior.
2020-12-20 22:36:40 +00:00
rillig 06ccd6ce96 make(1): reduce scope of cp in meta_oodate
That function is way too long (550 lines) and has too creative variable
names such as fname, fname1, fname2, fname3.
2020-12-20 22:12:36 +00:00
rillig 4b4d56707b make(1): fix declared variable type in printCMDs
No functional changes since StringListNode and GNodeListNode are both
typedefs of a simple generic ListNode.
2020-12-20 22:02:54 +00:00
rillig 0307413016 make(1): change return type of Var_Value to FStr 2020-12-20 14:32:13 +00:00
rillig ed7166493f make(1): replace %zu with %u in printf calls
This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
2020-12-13 21:27:45 +00:00
rillig 7f604d4793 make(1): add str_basename to reduce duplicate code
The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory.  This is too unreliable,
therefore this trivial own implementation.
2020-12-13 20:14:48 +00:00
rillig c2147f488d make(1): split JobFlags into separate fields
Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0.  Using individual names
just leaves the single memset, and that is only used during
initialization.
2020-12-10 20:49:11 +00:00
rillig 56cb5728d6 make(1): remove unused parameter from meta_needed 2020-12-05 17:46:41 +00:00
rillig 68212223a6 make(1): reduce memory allocation in meta_oodate 2020-11-29 21:31:55 +00:00
rillig 733418ce24 make(1): reduce memory allocation in meta mode 2020-11-29 21:28:06 +00:00
rillig 84085cca68 make(1): use space instead of tab for preprocessor directives 2020-11-29 09:27:40 +00:00
rillig e93d02d95f make(1): remove pointer indirection from GNode.commands
Just to save a few memory allocations.  No noticeable effect on the
performance though.
2020-11-28 18:55:52 +00:00
rillig 7fdaeb8c5f make(1): rename parameter in meta_needed and meta_create
It conflicts with the global variable in dir.c when make is built in
all-in-one mode.
2020-11-28 10:28:53 +00:00
rillig 6e1aae1731 make(1): fix local variable name in meta_create 2020-11-28 10:25:45 +00:00
rillig 357a62a61b make(1): inline meta_file_t for printCMD
This struct had only been necessary as long as printCMD was a callback
to Lst_ForEach or Lst_ForEachUntil.
2020-11-27 08:18:14 +00:00
rillig a41e5257d9 make(1): inline Lst_ForEachUntil in meta mode
This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list.  In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.
2020-11-27 08:07:26 +00:00
rillig a50b3dc0b0 make(1): remove redundant null check from meta_needed
The result of bmake_realloc can never be NULL.
2020-11-23 23:44:03 +00:00
rillig 4adbce360a make(1): use comparisons in boolean expressions
The generated code stays exactly the same.
2020-11-23 23:41:11 +00:00
rillig 69f9166fe8 make(1): use properly typed comparisons in boolean contexts 2020-11-23 20:52:59 +00:00
rillig 7179b788e7 make(1): align end-of-line comments with tabs 2020-11-23 20:41:20 +00:00
rillig 1c1f145671 make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.

Some local variables changed their names.

In ParseErrorInternal, the scope of va_start is now narrower.

In ParseDoDependency, the type of tOp has been fixed.

ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.

At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 12:02:44 +00:00
rillig 33ac710bcd make(1): remove redundant struct make_stat
In the cache for stat(2) and lstat(2), only one of the two timestamps
was ever used.  To prevent a result from stat(2) leaking into the cache
for lstat(2), there have been two completely separate caches all the
time.  Using different fields in the struct was therefore unnecessary.

By removing the redundant field, the internal struct in the cache is the
same as the external struct.  This makes one of them redundant, thus
struct make_stat has been renamed to cached_stat, which better describes
its purpose, and the internal struct cache_st has been removed.

Just as before, the cache prevents any direct access to its internal
data.  When passing it to the caller, it is copied.

Just as before, the field names of struct cached_stat cannot correspond
to those from struct stat, since the latter are often defined as macros.
Therefore they are prefixed with cst instead of st.

The redundancy had been added on 2020-06-05.
2020-11-14 19:24:24 +00:00
rillig 919a9a1235 make(1): remove redundant parameter from str2Lst_Append 2020-11-14 17:39:59 +00:00
rillig 2861b54efc make(1): use strict typing in conditions of the form !var 2020-11-08 15:07:37 +00:00
rillig f52baef877 make(1): fix inconsistent indentation after #ifdef
Combining #ifdef with regular if-then-else calls for trouble.
2020-11-07 21:26:43 +00:00
rillig a0c9252554 make(1): clean up code stylistically
* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
  beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
  stays the same.  (Assertions further down in the code would get
  different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
2020-11-07 10:16:18 +00:00
rillig 143a32671d make(1): remove redundant parentheses from sizeof operator
The parentheses are only needed if the argument is a type, not an
expression.
2020-11-05 17:27:16 +00:00
rillig f374fbd233 make(1): remove mistyped extern variable
Robust programs don't have extern variable declarations in .c files, as
that risks incomatible definitions that are not detected by the compiler
and invoke undefined behavior.  Make make a little more robust.
2020-11-04 13:27:00 +00:00
rillig ff78291f2d make(1): make memory allocation simpler in meta_create and meta_oodate
Since there is only a single variable left that needs to be freed at the
end (and probably never actually needs to be freed since nobody defines
an environment variable named .OBJDIR), there is no need to loop over
these variables.
2020-10-31 12:04:24 +00:00
rillig f015e31c48 make(1): do not look up local variables like .TARGET anywhere else
Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else.  This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter.  Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
2020-10-31 11:54:33 +00:00
rillig 59a15951ab make(1): fix indentation in source code 2020-10-31 09:57:47 +00:00
rillig e8b104bf6c make(1): change char * to void * in Var_Value
The only purpose of the parameter freeIt is to free the memory
associated with the return value.  To do this, no pointer arithmetic is
needed.  Therefore, change to a void pointer, to catch accidental use of
that pointer.
2020-10-30 20:30:44 +00:00
rillig 09c6b7ecfa make(1): fix indentation in source code 2020-10-30 15:39:17 +00:00