mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-16 05:46:25 +00:00
Add $(uniq token...) native function to Make
This reduces mono repo `make` latency from 336ms to 226ms.
This commit is contained in:
parent
14bf57180f
commit
6556dd2673
2 changed files with 46 additions and 3 deletions
7
third_party/make/README.cosmo
vendored
7
third_party/make/README.cosmo
vendored
|
@ -16,7 +16,10 @@ LICENSE
|
||||||
LOCAL CHANGES
|
LOCAL CHANGES
|
||||||
|
|
||||||
- Introduce $(uniq token...) native function
|
- Introduce $(uniq token...) native function
|
||||||
- .INTERNET variable to allow internet access
|
- Remove code that forces slow path if not using /bin/sh
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
- .PLEDGE variable which restricts system calls
|
- .PLEDGE variable which restricts system calls
|
||||||
- .UNVEIL variable which controls Landlock LSM
|
- .UNVEIL variable which controls Landlock LSM
|
||||||
- .STRICT variable to disable implicit unveiling
|
- .STRICT variable to disable implicit unveiling
|
||||||
|
@ -28,5 +31,3 @@ LOCAL CHANGES
|
||||||
- .NPROC variable which tunes fork() / clone() limit
|
- .NPROC variable which tunes fork() / clone() limit
|
||||||
- .NOFILE variable which tunes file descriptor limit
|
- .NOFILE variable which tunes file descriptor limit
|
||||||
- .MAXCORE variable to set upper limit on core dumps
|
- .MAXCORE variable to set upper limit on core dumps
|
||||||
- Do automatic setup and teardown of TMPDIR per rule
|
|
||||||
- Remove code that forces slow path if not using /bin/sh
|
|
||||||
|
|
42
third_party/make/function.c
vendored
42
third_party/make/function.c
vendored
|
@ -21,6 +21,8 @@ this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
#include "job.h"
|
#include "job.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "libc/mem/critbit0.h"
|
||||||
|
#include "libc/log/rop.internal.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1366,6 +1368,45 @@ func_intcmp (char *o, char **argv, const char *funcname UNUSED)
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
chop argv[0] into words, and remove duplicates.
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
func_uniq (char *o, char **argv, const char *funcname UNUSED)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
size_t len;
|
||||||
|
int mutated;
|
||||||
|
bool once = false;
|
||||||
|
const char *s = argv[0];
|
||||||
|
struct critbit0 t = {0};
|
||||||
|
|
||||||
|
while ((p = find_next_token (&s, &len)))
|
||||||
|
{
|
||||||
|
++s;
|
||||||
|
p[len] = 0;
|
||||||
|
RETURN_ON_ERROR ((mutated = critbit0_insert (&t, p)));
|
||||||
|
if (mutated)
|
||||||
|
{
|
||||||
|
if (once)
|
||||||
|
o = variable_buffer_output (o, " ", 1);
|
||||||
|
else
|
||||||
|
once = true;
|
||||||
|
o = variable_buffer_output (o, p, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
critbit0_clear (&t);
|
||||||
|
|
||||||
|
return o;
|
||||||
|
|
||||||
|
OnError:
|
||||||
|
critbit0_clear (&t);
|
||||||
|
OSS (error, NILF, "%s: function failed: %s",
|
||||||
|
"uniq", strerror (errno));
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$(if condition,true-part[,false-part])
|
$(if condition,true-part[,false-part])
|
||||||
|
|
||||||
|
@ -2522,6 +2563,7 @@ static struct function_table_entry function_table_init[] =
|
||||||
FT_ENTRY ("value", 0, 1, 1, func_value),
|
FT_ENTRY ("value", 0, 1, 1, func_value),
|
||||||
FT_ENTRY ("eval", 0, 1, 1, func_eval),
|
FT_ENTRY ("eval", 0, 1, 1, func_eval),
|
||||||
FT_ENTRY ("file", 1, 2, 1, func_file),
|
FT_ENTRY ("file", 1, 2, 1, func_file),
|
||||||
|
FT_ENTRY ("uniq", 0, 1, 1, func_uniq),
|
||||||
#ifdef EXPERIMENTAL
|
#ifdef EXPERIMENTAL
|
||||||
FT_ENTRY ("eq", 2, 2, 1, func_eq),
|
FT_ENTRY ("eq", 2, 2, 1, func_eq),
|
||||||
FT_ENTRY ("not", 0, 1, 1, func_not),
|
FT_ENTRY ("not", 0, 1, 1, func_not),
|
||||||
|
|
Loading…
Add table
Reference in a new issue