From 56c0819b70ee17f8f8f1f5d27d2f905ee34bb726 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 25 Jul 2020 21:25:55 +0800 Subject: improve dlang tests and template projects --- tests/projects/dlang/console/xmake.lua | 8 +--- tests/projects/dlang/console_with_pkgs/src/main.d | 6 +++ tests/projects/dlang/console_with_pkgs/xmake.lua | 6 +++ tests/projects/dlang/shared_library/xmake.lua | 24 +--------- tests/projects/dlang/static_library/xmake.lua | 23 +-------- tests/projects/go/console_with_deps/src/main.go | 9 ---- tests/projects/go/console_with_deps/xmake.lua | 15 ------ tests/projects/go/console_with_pkgs/src/main.go | 9 ++++ tests/projects/go/console_with_pkgs/xmake.lua | 15 ++++++ .../go/static_library_with_deps/src/main.go | 7 --- .../go/static_library_with_deps/src/test.go | 12 ----- .../go/static_library_with_deps/src/test/add.go | 11 ----- .../go/static_library_with_deps/src/test/sub.go | 6 --- .../projects/go/static_library_with_deps/xmake.lua | 19 -------- .../go/static_library_with_pkgs/src/main.go | 7 +++ .../go/static_library_with_pkgs/src/test.go | 12 +++++ .../go/static_library_with_pkgs/src/test/add.go | 11 +++++ .../go/static_library_with_pkgs/src/test/sub.go | 6 +++ .../projects/go/static_library_with_pkgs/xmake.lua | 19 ++++++++ xmake/modules/detect/tools/find_dub.lua | 54 ++++++++++++++++++++++ xmake/templates/dlang/console/project/xmake.lua | 6 --- xmake/templates/dlang/shared/project/xmake.lua | 14 +----- xmake/templates/dlang/static/project/xmake.lua | 14 +----- 23 files changed, 150 insertions(+), 163 deletions(-) create mode 100644 tests/projects/dlang/console_with_pkgs/src/main.d create mode 100644 tests/projects/dlang/console_with_pkgs/xmake.lua delete mode 100644 tests/projects/go/console_with_deps/src/main.go delete mode 100644 tests/projects/go/console_with_deps/xmake.lua create mode 100644 tests/projects/go/console_with_pkgs/src/main.go create mode 100644 tests/projects/go/console_with_pkgs/xmake.lua delete mode 100644 tests/projects/go/static_library_with_deps/src/main.go delete mode 100644 tests/projects/go/static_library_with_deps/src/test.go delete mode 100644 tests/projects/go/static_library_with_deps/src/test/add.go delete mode 100644 tests/projects/go/static_library_with_deps/src/test/sub.go delete mode 100644 tests/projects/go/static_library_with_deps/xmake.lua create mode 100644 tests/projects/go/static_library_with_pkgs/src/main.go create mode 100644 tests/projects/go/static_library_with_pkgs/src/test.go create mode 100644 tests/projects/go/static_library_with_pkgs/src/test/add.go create mode 100644 tests/projects/go/static_library_with_pkgs/src/test/sub.go create mode 100644 tests/projects/go/static_library_with_pkgs/xmake.lua create mode 100644 xmake/modules/detect/tools/find_dub.lua diff --git a/tests/projects/dlang/console/xmake.lua b/tests/projects/dlang/console/xmake.lua index 374a6826a..b1b8e0bfb 100644 --- a/tests/projects/dlang/console/xmake.lua +++ b/tests/projects/dlang/console/xmake.lua @@ -1,12 +1,6 @@ --- add rules add_rules("mode.debug", "mode.release") --- add target -target("console_dlang") - - -- set kind +target("test") set_kind("binary") - - -- add files add_files("src/*.d") diff --git a/tests/projects/dlang/console_with_pkgs/src/main.d b/tests/projects/dlang/console_with_pkgs/src/main.d new file mode 100644 index 000000000..524c4f94c --- /dev/null +++ b/tests/projects/dlang/console_with_pkgs/src/main.d @@ -0,0 +1,6 @@ +import std.stdio; + +void main() +{ + writeln("hello world!"); +} diff --git a/tests/projects/dlang/console_with_pkgs/xmake.lua b/tests/projects/dlang/console_with_pkgs/xmake.lua new file mode 100644 index 000000000..b1b8e0bfb --- /dev/null +++ b/tests/projects/dlang/console_with_pkgs/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("test") + set_kind("binary") + add_files("src/*.d") + diff --git a/tests/projects/dlang/shared_library/xmake.lua b/tests/projects/dlang/shared_library/xmake.lua index 7fa8b3b8a..9535bf1d3 100644 --- a/tests/projects/dlang/shared_library/xmake.lua +++ b/tests/projects/dlang/shared_library/xmake.lua @@ -1,34 +1,12 @@ --- add rules add_rules("mode.debug", "mode.release") --- add target target("interfaces") - - -- set kind set_kind("shared") - - -- add files add_files("src/interfaces.d") + add_includedirs("src", {public = true}) --- add target target("test") - - -- set kind set_kind("binary") - - -- add deps add_deps("interfaces") - - -- add files add_files("src/main.d") - -- add links - add_links("interfaces") - - -- add link directory - add_linkdirs("$(buildir)") - add_rpathdirs("$(buildir)") - - -- add include directory - add_includedirs("$(projectdir)/src") - diff --git a/tests/projects/dlang/static_library/xmake.lua b/tests/projects/dlang/static_library/xmake.lua index 74699bb04..273462475 100644 --- a/tests/projects/dlang/static_library/xmake.lua +++ b/tests/projects/dlang/static_library/xmake.lua @@ -1,33 +1,12 @@ --- add rules add_rules("mode.debug", "mode.release") --- add target target("interfaces") - - -- set kind set_kind("static") - - -- add files add_files("src/interfaces.d") + add_includedirs("src", {public = true}) --- add target target("test") - - -- set kind set_kind("binary") - - -- add deps add_deps("interfaces") - - -- add files add_files("src/main.d") - -- add links - add_links("interfaces") - - -- add link directory - add_linkdirs("$(buildir)") - - -- add include directory - add_includedirs("$(projectdir)/src") - diff --git a/tests/projects/go/console_with_deps/src/main.go b/tests/projects/go/console_with_deps/src/main.go deleted file mode 100644 index 194d6ac86..000000000 --- a/tests/projects/go/console_with_deps/src/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - log "github.com/sirupsen/logrus" -) - -func main() { - log.WithFields(log.Fields{"animal": "walrus"}).Info("A walrus appears") -} diff --git a/tests/projects/go/console_with_deps/xmake.lua b/tests/projects/go/console_with_deps/xmake.lua deleted file mode 100644 index d3324d855..000000000 --- a/tests/projects/go/console_with_deps/xmake.lua +++ /dev/null @@ -1,15 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_requires("go::github.com/sirupsen/logrus", {alias = "logrus"}) -add_requires("go::golang.org/x/sys/internal/unsafeheader", {alias = "unsafeheader"}) -if is_plat("windows") then - add_requires("go::golang.org/x/sys/windows", {alias = "syshost"}) -else - add_requires("go::golang.org/x/sys/unix", {alias = "syshost"}) -end - -target("test") - set_kind("binary") - add_files("src/*.go") - add_packages("logrus", "syshost", "unsafeheader") - diff --git a/tests/projects/go/console_with_pkgs/src/main.go b/tests/projects/go/console_with_pkgs/src/main.go new file mode 100644 index 000000000..194d6ac86 --- /dev/null +++ b/tests/projects/go/console_with_pkgs/src/main.go @@ -0,0 +1,9 @@ +package main + +import ( + log "github.com/sirupsen/logrus" +) + +func main() { + log.WithFields(log.Fields{"animal": "walrus"}).Info("A walrus appears") +} diff --git a/tests/projects/go/console_with_pkgs/xmake.lua b/tests/projects/go/console_with_pkgs/xmake.lua new file mode 100644 index 000000000..d3324d855 --- /dev/null +++ b/tests/projects/go/console_with_pkgs/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +add_requires("go::github.com/sirupsen/logrus", {alias = "logrus"}) +add_requires("go::golang.org/x/sys/internal/unsafeheader", {alias = "unsafeheader"}) +if is_plat("windows") then + add_requires("go::golang.org/x/sys/windows", {alias = "syshost"}) +else + add_requires("go::golang.org/x/sys/unix", {alias = "syshost"}) +end + +target("test") + set_kind("binary") + add_files("src/*.go") + add_packages("logrus", "syshost", "unsafeheader") + diff --git a/tests/projects/go/static_library_with_deps/src/main.go b/tests/projects/go/static_library_with_deps/src/main.go deleted file mode 100644 index f2b477453..000000000 --- a/tests/projects/go/static_library_with_deps/src/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -func main() { - - Run() -} - diff --git a/tests/projects/go/static_library_with_deps/src/test.go b/tests/projects/go/static_library_with_deps/src/test.go deleted file mode 100644 index cf10523f9..000000000 --- a/tests/projects/go/static_library_with_deps/src/test.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "fmt" - "module" -) - -func Run() { - - fmt.Printf("add: %d\n", module.Add(1, 2)); - fmt.Printf("sub: %d\n", module.Sub(1, 2)); -} diff --git a/tests/projects/go/static_library_with_deps/src/test/add.go b/tests/projects/go/static_library_with_deps/src/test/add.go deleted file mode 100644 index b87b21138..000000000 --- a/tests/projects/go/static_library_with_deps/src/test/add.go +++ /dev/null @@ -1,11 +0,0 @@ -package module - -import ( - log "github.com/sirupsen/logrus" -) - -func Add(a int, b int) int { - log.WithFields(log.Fields{"animal": "walrus"}).Info("A walrus appears") - return a + b; -} - diff --git a/tests/projects/go/static_library_with_deps/src/test/sub.go b/tests/projects/go/static_library_with_deps/src/test/sub.go deleted file mode 100644 index a24a9abb7..000000000 --- a/tests/projects/go/static_library_with_deps/src/test/sub.go +++ /dev/null @@ -1,6 +0,0 @@ -package module - -func Sub(a int, b int) int { - return a - b; -} - diff --git a/tests/projects/go/static_library_with_deps/xmake.lua b/tests/projects/go/static_library_with_deps/xmake.lua deleted file mode 100644 index 6943a29aa..000000000 --- a/tests/projects/go/static_library_with_deps/xmake.lua +++ /dev/null @@ -1,19 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_requires("go::github.com/sirupsen/logrus", {alias = "logrus"}) -add_requires("go::golang.org/x/sys/internal/unsafeheader", {alias = "unsafeheader"}) -if is_plat("windows") then - add_requires("go::golang.org/x/sys/windows", {alias = "syshost"}) -else - add_requires("go::golang.org/x/sys/unix", {alias = "syshost"}) -end - -target("module") - set_kind("static") - add_files("src/test/*.go") - add_packages("logrus", "syshost", "unsafeheader") - -target("test") - set_kind("binary") - add_deps("module") - add_files("src/*.go") diff --git a/tests/projects/go/static_library_with_pkgs/src/main.go b/tests/projects/go/static_library_with_pkgs/src/main.go new file mode 100644 index 000000000..f2b477453 --- /dev/null +++ b/tests/projects/go/static_library_with_pkgs/src/main.go @@ -0,0 +1,7 @@ +package main + +func main() { + + Run() +} + diff --git a/tests/projects/go/static_library_with_pkgs/src/test.go b/tests/projects/go/static_library_with_pkgs/src/test.go new file mode 100644 index 000000000..cf10523f9 --- /dev/null +++ b/tests/projects/go/static_library_with_pkgs/src/test.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" + "module" +) + +func Run() { + + fmt.Printf("add: %d\n", module.Add(1, 2)); + fmt.Printf("sub: %d\n", module.Sub(1, 2)); +} diff --git a/tests/projects/go/static_library_with_pkgs/src/test/add.go b/tests/projects/go/static_library_with_pkgs/src/test/add.go new file mode 100644 index 000000000..b87b21138 --- /dev/null +++ b/tests/projects/go/static_library_with_pkgs/src/test/add.go @@ -0,0 +1,11 @@ +package module + +import ( + log "github.com/sirupsen/logrus" +) + +func Add(a int, b int) int { + log.WithFields(log.Fields{"animal": "walrus"}).Info("A walrus appears") + return a + b; +} + diff --git a/tests/projects/go/static_library_with_pkgs/src/test/sub.go b/tests/projects/go/static_library_with_pkgs/src/test/sub.go new file mode 100644 index 000000000..a24a9abb7 --- /dev/null +++ b/tests/projects/go/static_library_with_pkgs/src/test/sub.go @@ -0,0 +1,6 @@ +package module + +func Sub(a int, b int) int { + return a - b; +} + diff --git a/tests/projects/go/static_library_with_pkgs/xmake.lua b/tests/projects/go/static_library_with_pkgs/xmake.lua new file mode 100644 index 000000000..6943a29aa --- /dev/null +++ b/tests/projects/go/static_library_with_pkgs/xmake.lua @@ -0,0 +1,19 @@ +add_rules("mode.debug", "mode.release") + +add_requires("go::github.com/sirupsen/logrus", {alias = "logrus"}) +add_requires("go::golang.org/x/sys/internal/unsafeheader", {alias = "unsafeheader"}) +if is_plat("windows") then + add_requires("go::golang.org/x/sys/windows", {alias = "syshost"}) +else + add_requires("go::golang.org/x/sys/unix", {alias = "syshost"}) +end + +target("module") + set_kind("static") + add_files("src/test/*.go") + add_packages("logrus", "syshost", "unsafeheader") + +target("test") + set_kind("binary") + add_deps("module") + add_files("src/*.go") diff --git a/xmake/modules/detect/tools/find_dub.lua b/xmake/modules/detect/tools/find_dub.lua new file mode 100644 index 000000000..9b66795fe --- /dev/null +++ b/xmake/modules/detect/tools/find_dub.lua @@ -0,0 +1,54 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_dub.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find dub +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local dub = find_dub() +-- local dub, version = find_dub({version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "dub", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/templates/dlang/console/project/xmake.lua b/xmake/templates/dlang/console/project/xmake.lua index 5f522baf8..86ace289d 100644 --- a/xmake/templates/dlang/console/project/xmake.lua +++ b/xmake/templates/dlang/console/project/xmake.lua @@ -1,13 +1,7 @@ --- add modes: debug and release add_rules("mode.debug", "mode.release") --- add target target("${TARGETNAME}") - - -- set kind set_kind("binary") - - -- add files add_files("src/*.d") ${FAQ} diff --git a/xmake/templates/dlang/shared/project/xmake.lua b/xmake/templates/dlang/shared/project/xmake.lua index 23fe35a70..277b2e611 100644 --- a/xmake/templates/dlang/shared/project/xmake.lua +++ b/xmake/templates/dlang/shared/project/xmake.lua @@ -1,25 +1,13 @@ --- add modes: debug and release add_rules("mode.debug", "mode.release") --- add target target("${TARGETNAME}") - - -- set kind set_kind("shared") - - -- add files add_files("src/interfaces.d") + add_includedirs("src", {public = true}) --- add target target("${TARGETNAME}_demo") - - -- set kind set_kind("binary") - - -- add deps add_deps("${TARGETNAME}") - - -- add files add_files("src/main.d") ${FAQ} diff --git a/xmake/templates/dlang/static/project/xmake.lua b/xmake/templates/dlang/static/project/xmake.lua index 281c63734..ba4d99e77 100644 --- a/xmake/templates/dlang/static/project/xmake.lua +++ b/xmake/templates/dlang/static/project/xmake.lua @@ -1,25 +1,13 @@ --- add modes: debug and release add_rules("mode.debug", "mode.release") --- add target target("${TARGETNAME}") - - -- set kind set_kind("static") - - -- add files add_files("src/interfaces.d") + add_includedirs("src", {public = true}) --- add target target("${TARGETNAME}_demo") - - -- set kind set_kind("binary") - - -- add deps add_deps("${TARGETNAME}") - - -- add files add_files("src/main.d") ${FAQ} -- cgit v1.3.1