Skip to content

Commit

Permalink
Use automatic versioning (#379)
Browse files Browse the repository at this point in the history
Use automatic versioning
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
  • Loading branch information
bbasile committed Sep 19, 2018
1 parent 647bb6d commit 7fb46c9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 51 deletions.
16 changes: 15 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ set STDXALLOCATOR=
set STDXALLOCATORBLOCKS=
set OBIN=bin\dfmt

:: git might not be installed, so we provide 0.0.0 as a fallback or use
:: the existing githash file if existent
if not exist "bin" mkdir bin
git describe --tags > bin\githash_.txt
for /f %%i in ("bin\githash_.txt") do set githashsize=%%~zi
if %githashsize% == 0 (
if not exist "bin\githash.txt" (
echo v0.0.0 > bin\githash.txt
)
) else (
move /y bin\githash_.txt bin\githash.txt
)


for %%x in (src\dfmt\*.d) do set CORE=!CORE! %%x
for %%x in (libdparse\src\std\experimental\*.d) do set STD=!STD! %%x
for %%x in (libdparse\src\dparse\*.d) do set STDD=!STDD! %%x
for %%x in (stdx-allocator\source\stdx\allocator\*.d) do set STDXALLOCATOR=!STDXALLOCATOR! %%x
for %%x in (stdx-allocator\source\stdx\allocator\building_blocks\*.d) do set STDXALLOCATORBLOCKS=!STDXALLOCATORBLOCKS! %%x

@echo on
%DC% %CORE% %STD% %STDD% %STDE% %STDXALLOCATOR% %STDXALLOCATORBLOCKS% -I"stdx-allocator\source" -I"libdparse\src" %DFLAGS% -of%OBIN%.exe
%DC% %CORE% %STD% %STDD% %STDE% %STDXALLOCATOR% %STDXALLOCATORBLOCKS% -I"stdx-allocator\source" -I"libdparse\src" -Jbin %DFLAGS% -of%OBIN%.exe

if exist %OBIN%.obj del %OBIN%.obj
9 changes: 9 additions & 0 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
},
"targetPath" : "bin/",
"targetName" : "dfmt",
"stringImportPaths" : [
"bin"
],
"versions" : [
"built_with_dub"
],
"preGenerateCommands" : [
"rdmd --eval=\"auto dir=environment.get(\\\"DUB_PACKAGE_DIR\\\"); dir.buildPath(\\\"bin\\\").mkdirRecurse; auto gitVer = (\\\"git -C \\\"~dir~\\\" describe --tags\\\").executeShell; (gitVer.status == 0 ? gitVer.output.strip : \\\"v\\\" ~ dir.dirName.baseName.findSplitAfter(environment.get(\\\"DUB_ROOT_PACKAGE\\\")~\\\"-\\\")[1]).ifThrown(\\\"0.0.0\\\").chain(newline).to!string.toFile(dir.buildPath(\\\"bin\\\", \\\"dubhash.txt\\\"));\""
]
}
25 changes: 13 additions & 12 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SRC := $(shell find src -name "*.d") \
$(shell find libdparse/src -name "*.d") \
$(shell find stdx-allocator/source -name "*.d")
INCLUDE_PATHS := -Ilibdparse/src -Istdx-allocator/source -Isrc
DMD_COMMON_FLAGS := -dip25 -w $(INCLUDE_PATHS) -Jviews
INCLUDE_PATHS := -Ilibdparse/src -Istdx-allocator/source -Isrc -Jbin
DMD_COMMON_FLAGS := -dip25 -w $(INCLUDE_PATHS)
DMD_DEBUG_FLAGS := -debug -g $(DMD_COMMON_FLAGS)
DMD_FLAGS := -O -inline $(DMD_COMMON_FLAGS)
DMD_TEST_FLAGS := -unittest -g $(DMD_COMMON_FLAGS)
Expand All @@ -16,27 +16,27 @@ GDC ?= gdc

dmd: bin/dfmt

views/VERSION : .git/refs/tags .git/HEAD
mkdir -p $(dir $@)
git describe --tags > $@
githash:
mkdir -p bin
git describe --tags > bin/githash.txt

ldc: $(SRC)
$(LDC) $(LDC_FLAGS) $^ -ofbin/dfmt
ldc: githash
$(LDC) $(SRC) $(LDC_FLAGS) -ofbin/dfmt
-rm -f *.o

gdc: $(SRC)
$(GDC) $(GDC_FLAGS) $^ -obin/dfmt
gdc:githash
$(GDC) $(SRC) $(GDC_FLAGS) -obin/dfmt

test: debug
cd tests && ./test.sh

bin/dfmt-test: $(SRC)
bin/dfmt-test: githash $(SRC)
$(DC) $(DMD_TEST_FLAGS) $^ -of$@

bin/dfmt: views/VERSION $(SRC)
bin/dfmt: githash $(SRC)
$(DC) $(DMD_FLAGS) $(filter %.d,$^) -of$@

debug: views/VERSION $(SRC)
debug: githash $(SRC)
$(DC) $(DMD_DEBUG_FLAGS) $(filter %.d,$^) -ofbin/dfmt

pkg: dmd
Expand All @@ -47,3 +47,4 @@ clean:

release:
./release.sh
githash
1 change: 1 addition & 0 deletions release-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fi
archiveName="dfmt-$VERSION-$OS-$ARCH_SUFFIX.zip"
echo "Building $archiveName"
mkdir -p bin
git describe --tags > bin/githash.txt # no git installed under Wine
DC="$DIR/dmd2/windows/bin/dmd.exe" wine cmd /C build.bat

cd bin
Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ esac
archiveName="dfmt-$VERSION-$OS-$ARCH_SUFFIX.tar.gz"

echo "Building $archiveName"
${MAKE:-make} ldc LDC_FLAGS="${LDC_FLAGS[*]}"
${MAKE:-make} ldc LDC_FLAGS="${LDC_FLAGS[*]} -Jbin"
tar cvfz "bin/$archiveName" -C bin dfmt
47 changes: 10 additions & 37 deletions src/dfmt/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// http://www.boost.org/LICENSE_1_0.txt)

module dfmt.main;

import std.string : strip;

static immutable VERSION = () {
debug
{
Expand All @@ -14,49 +17,19 @@ static immutable VERSION = () {
enum DEBUG_SUFFIX = "";
}

static if (is(typeof(import("VERSION"))))
version (built_with_dub)
{
// takes the `git describe --tags` output and removes the leading
// 'v' as well as any kind of newline
// if the tag is considered malformed it gets used verbatim

enum gitDescribeOutput = import("VERSION");

string result;

if (gitDescribeOutput[0] == 'v')
result = gitDescribeOutput[1 .. $];
else
result = null;

uint minusCount;

foreach (i, c; result)
{
if (c == '\n' || c == '\r')
{
result = result[0 .. i];
break;
}

if (c == '-')
{
++minusCount;
}
}

if (minusCount > 1)
result = null;

return result ? result ~ DEBUG_SUFFIX
: gitDescribeOutput ~ DEBUG_SUFFIX;

enum DFMT_VERSION = import("dubhash.txt").strip;
}
else
{
return "unknown" ~ DEBUG_SUFFIX ~ "-version";
/**
* Current build's Git commit hash
*/
enum DFMT_VERSION = import("githash.txt").strip;
}

return DFMT_VERSION ~ DEBUG_SUFFIX;
} ();


Expand Down

0 comments on commit 7fb46c9

Please sign in to comment.