Skip to content

Commit

Permalink
[#24] add make built-in toolchain
Browse files Browse the repository at this point in the history
Compatible with all languages, assuming the project has a Makefile at its root defining a build and a test targets
  • Loading branch information
mengdaming committed Jan 19, 2022
1 parent 9a20c91 commit 6b968ef
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ provided as built-in.

#### Built-in languages and toolchains

| Language | Toolchains | Default |
|----------|----------------------------------------------|----------------|
| java | gradle, gradle-wrapper, maven, maven-wrapper | gradle-wrapper |
| cpp | cmake | cmake |
| go | go-tools | go-tools |
| Language | Toolchains | Default |
|----------|----------------------------------------------------|----------------|
| java | gradle, gradle-wrapper, maven, maven-wrapper, make | gradle-wrapper |
| cpp | cmake, make | cmake |
| go | go-tools, make | go-tools |

### Base directory

Expand Down
2 changes: 1 addition & 1 deletion tcr-engine/language/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
name: "cpp",
toolchains: Toolchains{
Default: "cmake",
Compatible: []string{"cmake"},
Compatible: []string{"cmake", "make"},
},
srcFileFilter: FileTreeFilter{
Directories: []string{"src", "include"},
Expand Down
1 change: 1 addition & 0 deletions tcr-engine/language/cpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Test_cpp_default_toolchain(t *testing.T) {

func Test_cpp_compatible_toolchains(t *testing.T) {
assertCompatibleToolchains(t, []string{"cmake"}, cppLanguageName)
assertCompatibleToolchains(t, []string{"make"}, cppLanguageName)
}

func Test_cpp_incompatible_toolchains(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tcr-engine/language/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
name: "go",
toolchains: Toolchains{
Default: "go-tools",
Compatible: []string{"go-tools"},
Compatible: []string{"go-tools", "make"},
},
srcFileFilter: FileTreeFilter{
Directories: []string{"."},
Expand Down
1 change: 1 addition & 0 deletions tcr-engine/language/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func Test_go_default_toolchain(t *testing.T) {

func Test_go_compatible_toolchains(t *testing.T) {
assertCompatibleToolchains(t, []string{"go-tools"}, goLanguageName)
assertCompatibleToolchains(t, []string{"make"}, goLanguageName)
}

func Test_go_incompatible_toolchains(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tcr-engine/language/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
name: "java",
toolchains: Toolchains{
Default: "gradle-wrapper",
Compatible: []string{"gradle", "gradle-wrapper", "maven", "maven-wrapper"},
Compatible: []string{"gradle", "gradle-wrapper", "maven", "maven-wrapper", "make"},
},
srcFileFilter: FileTreeFilter{
Directories: []string{"src/main"},
Expand Down
1 change: 1 addition & 0 deletions tcr-engine/language/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func Test_java_default_toolchain(t *testing.T) {

func Test_java_compatible_toolchains(t *testing.T) {
assertCompatibleToolchains(t, []string{"gradle", "gradle-wrapper", "maven", "maven-wrapper"}, javaLanguageName)
assertCompatibleToolchains(t, []string{"make"}, javaLanguageName)
}

func Test_java_incompatible_toolchains(t *testing.T) {
Expand Down
32 changes: 32 additions & 0 deletions tcr-engine/testdata/go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Example Makefile for Go language
# ----------------------------------------------------------------------------

.PHONY: build
build:
@go build -v ./...

.PHONY: test
test:
@go test -v ./...


2 changes: 1 addition & 1 deletion tcr-engine/testdata/go/kata/dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ SOFTWARE.
package dummy

func doSomething() int {
return 40
return 42
}
2 changes: 1 addition & 1 deletion tcr-engine/testdata/go/kata/dummy/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ import (
)

func Test_acceptance_test(t *testing.T) {
assert.Equal(t, 40, doSomething())
assert.Equal(t, 42, doSomething())
}
101 changes: 101 additions & 0 deletions tcr-engine/testdata/java/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Example Makefile for Java language
# ----------------------------------------------------------------------------

junit.ver = 1.8.2
junit.jar = junit-platform-console-standalone-$(junit.ver).jar
maven.url = https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone
junit.url = $(maven.url)/$(junit.ver)/$(junit.jar)

src.dir = src
build.dir = build
build.lib.dir = $(build.dir)/lib

src.main.dir = $(src.dir)/main/java
src.test.dir = $(src.dir)/test/java

build.main.dir = $(build.dir)/classes
build.test.dir = $(build.dir)/test-classes

src.main.files := $(shell find $(src.main.dir) -type f -name '*.java')
src.test.files := $(shell find $(src.test.dir) -type f -name '*.java')

build.main.files = $(src.main.files:$(src.main.dir)/%.java=$(build.main.dir)/%.class)
build.test.files = $(src.test.files:$(src.test.dir)/%.java=$(build.test.dir)/%.class)

# Classpath separator is platform-dependant
os.kernel := $(shell uname -s)
ifeq ($(os.kernel),Darwin)
classpath.sep = ":"
else ifeq ($(os.kernel),Linux)
classpath.sep = ":"
else
classpath.sep = ";"
endif

.PHONY: build
build: build-main build-test

.PHONY: test
test: build-test
-@echo "Running tests"
-@java -jar $(build.lib.dir)/$(junit.jar) \
--class-path $(build.main.dir) \
--class-path $(build.test.dir) \
--scan-class-path --details=tree

.PHONY: clean
clean:
-@echo "Cleaning up"
-@rm -rf $(build.dir)

.PHONY: build-main
build-main: $(build.main.files)

$(build.main.files): | $(build.main.dir)

$(build.main.dir)/%.class: $(src.main.dir)/%.java
-@echo "Compiling $(<F)"
-@javac -d $(build.main.dir) $<

.PHONY: build-test
build-test: build-main download-junit $(build.test.files)

$(build.test.files): | $(build.test.dir)

$(build.test.dir)/%.class: $(src.test.dir)/%.java
-@echo "Compiling $(<F)"
-@javac -classpath $(build.lib.dir)/$(junit.jar)$(classpath.sep)$(build.main.dir) -d $(build.test.dir) $<

.PHONY: download-junit
download-junit: $(build.lib.dir)/$(junit.jar)

$(build.lib.dir)/$(junit.jar): | $(build.lib.dir)
-@echo "Downloading $(@F)"
-@curl --silent --fail \
--dump-header $(build.lib.dir)/$(junit.jar).header \
--output $(build.lib.dir)/$(junit.jar) \
--location $(junit.url)

$(build.lib.dir) $(build.main.dir) $(build.test.dir):
-@echo "Creating directory $@"
-@mkdir -p $@
43 changes: 43 additions & 0 deletions tcr-engine/toolchain/make.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright (c) 2022 Murex
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package toolchain

func init() {
_ = addBuiltIn(
Toolchain{
name: "make",
buildCommands: []Command{{
Os: GetAllOsNames(),
Arch: GetAllArchNames(),
Path: "make",
Arguments: []string{"build"},
}},
testCommands: []Command{{
Os: GetAllOsNames(),
Arch: GetAllArchNames(),
Path: "make",
Arguments: []string{"test"},
}},
},
)
}
71 changes: 71 additions & 0 deletions tcr-engine/toolchain/make_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright (c) 2022 Murex
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package toolchain

import (
"testing"
)

const (
makeToolchainName = "make"
)

func Test_make_is_a_built_in_toolchain(t *testing.T) {
assertIsABuiltInToolchain(t, makeToolchainName)
}

func Test_make_toolchain_is_supported(t *testing.T) {
assertIsSupported(t, makeToolchainName)
}

func Test_make_toolchain_name_is_case_insensitive(t *testing.T) {
assertNameIsNotCaseSensitive(t, makeToolchainName)
}

func Test_make_toolchain_initialization(t *testing.T) {
assertToolchainInitialization(t, makeToolchainName)
}

func Test_make_toolchain_name(t *testing.T) {
assertToolchainName(t, makeToolchainName)
}

func Test_make_toolchain_build_command_path(t *testing.T) {
assertBuildCommandPath(t, "make", makeToolchainName)
}

func Test_make_toolchain_build_command_args(t *testing.T) {
assertBuildCommandArgs(t, []string{"build"}, makeToolchainName)
}

func Test_make_toolchain_test_command_path(t *testing.T) {
assertTestCommandPath(t, "make", makeToolchainName)
}

func Test_make_toolchain_test_command_args(t *testing.T) {
assertTestCommandArgs(t, []string{"test"}, makeToolchainName)
}

func Test_make_toolchain_supported_platforms(t *testing.T) {
assertRunsOnAllOsWithAmd64(t, makeToolchainName)
}

0 comments on commit 6b968ef

Please sign in to comment.