Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

druntime: replaces top level version(..) branching by tags #24

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bff6baa
druntime, DMD: replaces top level version(..) branching by tags
denizzzka Jan 12, 2024
338888b
CMake: initial tags support, not works
denizzzka Jan 12, 2024
48403cf
ldc2, CMake: druntime compilation directory is druntime/
denizzzka Jan 12, 2024
da2703b
druntime: tags import/ copying works
denizzzka Jan 12, 2024
fd31374
Unnecessary copy_tagged.sh removed
denizzzka Jan 12, 2024
26d461b
commented code removed (Windows slashes is deprecated)
denizzzka Jan 12, 2024
a3d727f
druntime: parse_tagged_hier.sh args rearranged for future use
denizzzka Jan 12, 2024
38c0f60
cmake: debug echo output removed, error messages output enabled
denizzzka Jan 12, 2024
4a54eec
CMake: install tagged imports added
denizzzka Jan 13, 2024
87fdcfe
files paths replaced by variables
denizzzka Jan 13, 2024
a48090a
Merge branch 'master' into druntime_tagged_branches
denizzzka Jan 30, 2024
0fc4768
test module moved: core.internal.event_tests -> core.sync.event_tests
denizzzka Jan 30, 2024
60f7430
Merge branch 'master' into druntime_tagged_branches
denizzzka Feb 1, 2024
9e9a278
event.d + event_tests.d -> event.d + event_impl.d
denizzzka Feb 1, 2024
d5b3ef2
Arch tag isn't make sense for official targets
denizzzka Feb 1, 2024
ac7f242
ldc2.conf: target-specific lines moved out to the separate file
denizzzka Feb 2, 2024
b481182
DRUNTIME_TARGET_NAME contains target name for druntime import/
denizzzka Feb 2, 2024
86dbd77
DRUNTIME_TARGET_NAME: description added
denizzzka Feb 2, 2024
61e5e4f
platforms dir changed
denizzzka Feb 2, 2024
3cf394c
CONF_IMPORTS creation for ldc2.conf and for ldc2_install.conf
denizzzka Feb 2, 2024
da9cad5
@CONF_IMPORTS@/platforms/linux added
denizzzka Feb 2, 2024
ff2c0d5
druntime unittest build fix
denizzzka Feb 2, 2024
f1e6972
All other official platforms added to ldc2.conf
denizzzka Feb 2, 2024
4c32a76
common.conf.in lines rearranged for better perception
denizzzka Feb 3, 2024
fb0db35
set TAGS moved
denizzzka Feb 3, 2024
dd7fed1
Tagged lists generator moved to dedicated function "produce_tagged_hier"
denizzzka Feb 3, 2024
0b4ad80
Targets matrix added, imports are generated for all of them
denizzzka Feb 3, 2024
bd4dc04
Appropriate copying of all official imports
denizzzka Feb 3, 2024
fda4c0c
Remaining platforms added
denizzzka Feb 3, 2024
93a49dd
typo
denizzzka Feb 3, 2024
f508117
Skip import/ creation for the current platform
denizzzka Feb 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions druntime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,47 @@ DRUNTIMESOLIB=$(DRUNTIMESO)$(DOTLIB)

STDDOC=

###############

TAGGED_COPY_LIST_FILE:=mak/TAGGED_COPY
TAGGED_SRCS_FILE:=$(ROOT)/GEN_SRCS
TAGGED_COPY_FILE:=$(ROOT)/GEN_COPY

ifeq (windows,$(OS))
# Tags order doesn't matter
TAGS:=windows
else
TAGS:=$(OS),posix_threads
endif

TGEN_CMD:=./parse_tagged_hier.sh $(TAGGED_SRCS_FILE) $(TAGGED_COPY_LIST_FILE) $(TAGGED_COPY_FILE) $(IMPDIR) $(TAGS) config > /dev/null

TAGGED_SRCS:=$(shell $(TGEN_CMD) && cat $(TAGGED_SRCS_FILE))

# MacOS doesn't support .SHELLSTATUS
ifneq ($(.SHELLSTATUS),)
ifneq ($(.SHELLSTATUS),0)
$(error Tagged sources list generation failed)
endif
endif

TAGGED_COPY:=$(shell $(TGEN_CMD) && cat $(TAGGED_COPY_FILE))
ifneq ($(.SHELLSTATUS),)
ifneq ($(.SHELLSTATUS),0)
$(error Tagged copy list generation failed)
endif
endif

###############

include mak/COPY
COPY:=$(subst \,/,$(COPY))
COPY:=$(subst \,/,$(COPY)) $(subst \,/,$(TAGGED_COPY))

include mak/DOCS
DOCS:=$(subst \,/,$(DOCS))

include mak/SRCS
SRCS:=$(subst \,/,$(SRCS))
SRCS:=$(subst \,/,$(SRCS)) $(subst \,/,$(TAGGED_SRCS))

# NOTE: trace.d and cover.d are not necessary for a successful build
# as both are used for debugging features (profiling and coverage)
Expand Down Expand Up @@ -353,6 +386,13 @@ import: copy

copy: $(COPY)

strip_first_dirs:=cut -d '/' -f4-
IMP_PATH=$(IMPDIR)/$(shell echo $@ | $(strip_first_dirs))

$(IMPDIR)/config/%.d : config/%.d
@mkdir -p $(dir $(IMP_PATH))
@cp $< $(IMP_PATH)

$(IMPDIR)/%.di : src/%.di
@mkdir -p $(dir $@)
@cp $< $@
Expand Down Expand Up @@ -403,6 +443,11 @@ $(ROOT)/valgrind$(DOTOBJ) : src/etc/valgrind/valgrind.c src/etc/valgrind/valgrin
@mkdir -p `dirname $@`
$(CC) -c $(CFLAGS) $< -o$@

################################################

gen_tagged_srcs_clean:
rm -f $(TAGGED_SRCS_FILE) $(TAGGED_SRCS_FILE).disabled $(TAGGED_COPY_FILE)

######################## Create a shared library ##############################

$(DRUNTIMESO) $(DRUNTIMESOLIB) dll: DFLAGS+=-version=Shared $(SHAREDFLAGS)
Expand Down Expand Up @@ -562,7 +607,7 @@ install: target
cp -r import/* '$(INSTALL_DIR)'/src/druntime/import/
endif

clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS))
clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS)) gen_tagged_srcs_clean
rm -rf $(ROOT_OF_THEM_ALL) $(IMPDIR) $(DOC_OUTPUT_DIR) druntime.zip

test/%/.clean: test/%/Makefile
Expand Down
115 changes: 115 additions & 0 deletions druntime/config/posix_threads/core/sync/event_impl.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
module core.sync.event_impl;

import core.internal.abort : abort;
import core.sys.posix.pthread;
import core.sys.posix.sys.types;
import core.sys.posix.time;
import core.time;

package:

nothrow @nogc:

struct EventHandler
{
pthread_mutex_t m_mutex;
pthread_cond_t m_cond;
bool initalized;
bool m_state;
bool m_manualReset;
}

EventHandler create(bool manualReset, bool initialState)
{
EventHandler h;

pthread_mutex_init(cast(pthread_mutex_t*) &(h.m_mutex), null) == 0 ||
abort("Error: pthread_mutex_init failed.");

static if ( is( typeof( pthread_condattr_setclock ) ) )
{
pthread_condattr_t attr = void;
pthread_condattr_init(&attr) == 0 ||
abort("Error: pthread_condattr_init failed.");
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 ||
abort("Error: pthread_condattr_setclock failed.");
pthread_cond_init(&(h.m_cond), &attr) == 0 ||
abort("Error: pthread_cond_init failed.");
pthread_condattr_destroy(&attr) == 0 ||
abort("Error: pthread_condattr_destroy failed.");
}
else
{
pthread_cond_init(&(h.m_cond), null) == 0 ||
abort("Error: pthread_cond_init failed.");
}

h.m_state = initialState;
h.m_manualReset = manualReset;
h.initalized = true;

return h;
}

void destroy(ref EventHandler h)
{
pthread_mutex_destroy(&(h.m_mutex)) == 0 ||
abort("Error: pthread_mutex_destroy failed.");

pthread_cond_destroy(&(h.m_cond)) == 0 ||
abort("Error: pthread_cond_destroy failed.");

h.initalized = false;
}

void set(ref EventHandler h)
{
h.mutexLock;
h.m_state = true;
pthread_cond_broadcast(&(h.m_cond));
h.mutexUnlock;
}

void reset(ref EventHandler h)
{
h.mutexLock;
h.m_state = false;
h.mutexUnlock;
}

bool wait(ref EventHandler h)
{
return h.wait(Duration.max);
}

bool wait(ref EventHandler h, Duration tmout)
{
h.mutexLock;

int result = 0;
if (!h.m_state)
{
if (tmout == Duration.max)
{
result = pthread_cond_wait(&(h.m_cond), &(h.m_mutex));
}
else
{
import core.sync.config;

timespec t = void;
mktspec(t, tmout);

result = pthread_cond_timedwait(&(h.m_cond), &(h.m_mutex), &t);
}
}
if (result == 0 && !h.m_manualReset)
h.m_state = false;

h.mutexUnlock;

return result == 0;
}

private void mutexLock(ref EventHandler h) { pthread_mutex_lock(&(h.m_mutex)); }
private void mutexUnlock(ref EventHandler h) { pthread_mutex_unlock(&(h.m_mutex)); }
60 changes: 60 additions & 0 deletions druntime/config/windows/core/sync/event_impl.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module core.sync.event_impl;

import core.internal.abort : abort;
import core.sys.windows.basetsd /+: HANDLE +/;
import core.sys.windows.winerror /+: WAIT_TIMEOUT +/;
import core.sys.windows.winbase /+: CreateEvent, CloseHandle, SetEvent, ResetEvent,
WaitForSingleObject, INFINITE, WAIT_OBJECT_0+/;
import core.time;

package:

nothrow @nogc:

alias EventHandler = HANDLE;

bool initalized(in EventHandler h) { return h !is null; }

EventHandler create(bool manualReset, bool initialState)
{
HANDLE m_event = CreateEvent(null, manualReset, initialState, null);
m_event || abort("Error: CreateEvent failed.");

return m_event;
}

void destroy(ref EventHandler m_event)
{
CloseHandle(m_event);
m_event = null;
}

void set(EventHandler m_event)
{
SetEvent(m_event);
}

void reset(EventHandler m_event)
{
ResetEvent(m_event);
}

bool wait(EventHandler m_event)
{
return m_event && WaitForSingleObject(m_event, INFINITE) == WAIT_OBJECT_0;
}

bool wait(EventHandler m_event, Duration tmout)
{
auto maxWaitMillis = dur!("msecs")(uint.max - 1);

while (tmout > maxWaitMillis)
{
auto res = WaitForSingleObject(m_event, uint.max - 1);
if (res != WAIT_TIMEOUT)
return res == WAIT_OBJECT_0;
tmout -= maxWaitMillis;
}
auto ms = cast(uint)(tmout.total!"msecs");
return WaitForSingleObject(m_event, ms) == WAIT_OBJECT_0;
}
1 change: 1 addition & 0 deletions druntime/mak/TAGGED_COPY
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
core\sync\event_impl.d
81 changes: 81 additions & 0 deletions druntime/parse_tagged_hier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

set -euo pipefail

DST_FILE=$1
SRC_COPY_FILE=$2
DST_COPY_FILE=$3
IMPDIR=$4
TAGS=$5
SRC_DIR=$6

if [[ ! -d ${SRC_DIR} ]]; then
echo "Tags dir '${SRC_DIR}' not found" >&2
exit 1
fi

if [[ -f ${DST_FILE} ]]; then
echo "Tagged sources list already generated"
exit 0
fi

TAGS_LIST=($(echo "$TAGS" | tr "," "\n"))

echo -e "\nTags will be applied: $TAGS"

APPLIED=""

function applyTaggedFiles {
TAG=$1
SRC_TAG_DIR=${SRC_DIR}/${TAG}

if [[ ! -d ${SRC_TAG_DIR} ]]; then
echo "Warning: tag '${TAG}' doesn't corresponds to any subdirectory inside of '${SRC_DIR}', skip" >&2
else
SRC_FILES_LIST+=($(find ${SRC_TAG_DIR} -type f ))

pushd ${SRC_TAG_DIR} > /dev/null
MAYBE_COPY_LIST+=($(find * -type f ))
popd > /dev/null
fi

APPLIED+=" $TAG"

echo "Currently applied tags:$APPLIED"
}

for tag in "${TAGS_LIST[@]}"
do
applyTaggedFiles ${tag}
done

LINES_TO_COPY=$(grep -v '^$' ${SRC_COPY_FILE} | sort | uniq | wc -l)
COPIED=0

mkdir -p $(dirname ${DST_FILE})
mkdir -p $(dirname ${DST_COPY_FILE})
echo -ne > ${DST_FILE}
echo -ne > ${DST_COPY_FILE}

for i in "${!SRC_FILES_LIST[@]}"
do
echo ${SRC_FILES_LIST[$i]} >> ${DST_FILE}

maybe_copy=$(echo ${MAYBE_COPY_LIST[$i]} | tr '/' '\\')

# Adds copy entry if file mentioned in the list
grep -F "$maybe_copy" ${SRC_COPY_FILE} > /dev/null && {
echo ${IMPDIR}'/'${SRC_FILES_LIST[$i]} >> ${DST_COPY_FILE}
COPIED=$((COPIED+1))
}
done

if [ $COPIED -ne $LINES_TO_COPY ]; then
echo "File '$SRC_COPY_FILE' contains $LINES_TO_COPY meaningful line(s), but to '$DST_COPY_FILE' added $COPIED line(s)" >&2

mv ${DST_FILE} "$DST_FILE.disabled"
echo "File '$DST_FILE' to '$DST_FILE.disabled' to avoid considering that tags parsing process was sucessfully done" >&2
exit 1
fi

echo "All tags applied"
Loading