Skip to content

Commit

Permalink
API for set of enabled targets (#53)
Browse files Browse the repository at this point in the history
Provide API for restricting the set of targets where the source set or component is enabled.

The empty set has the special meaning of permitting everything.
  • Loading branch information
pedrolamarao authored Oct 13, 2023
1 parent cddb1db commit 4afa361
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 296 deletions.
40 changes: 22 additions & 18 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ primarily design to support project link:https://github.com/pedrolamarao/metal[M

Features:

* multiple languages (assembler, c and c++)
* multiple components (static archives, shared libraries and executables)
* compile commands database (for clang-check, CLion etc.)
* dependency on included (sub)project, included build and external prebuilt components
* compile assembler, c and c++ (including c++ module interfaces)
* assemble archives and executables
* build target support (e.g. `x86_64-elf`)
* generate compilation commands database
* source dependency on included project
* binary dependency on prebuilt external project
* LLVM tools
[WARNING]
Expand All @@ -25,7 +27,7 @@ Current requirements:
To use the development version, you may install from source with `./gradlew publishToMavenLocal` and configure your project's settings like this:

[source,kotlin]
[source]
----
pluginManagement {
repositories {
Expand All @@ -34,7 +36,7 @@ pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.id.startsWith("br.dev.pedrolamarao.metal.")) {
useModule("br.dev.pedrolamarao.gradle.metal:plugins:[0.2,0.3)")
useModule("br.dev.pedrolamarao.gradle.metal:plugins:0.3+")
}
}
}
Expand All @@ -45,20 +47,22 @@ Check the link:samples[] for a variety of use-cases.

Plugins:

* `br.dev.pedrolamarao.metal.base`: adds the `metal` extension
* `br.dev.pedrolamarao.metal.application`: creates a conventional "main" application with tasks
* `br.dev.pedrolamarao.metal.archive`: creates a conventional "main" archive with tasks
* `br.dev.pedrolamarao.metal.asm`: adds assembler sources to "main" component (at `src/main/asm`) with tasks
* `br.dev.pedrolamarao.metal.c`: adds C sources to "main" component (at `src/main/c`) with tasks
* `br.dev.pedrolamarao.metal.cpp`: adds CPP sources to "main" component (at `src/main/cxx`) with tasks
* `br.dev.pedrolamarao.metal.cxx`: adds C++ module implementation sources to "main" component (at `src/main/cxx`) with tasks
* `br.dev.pedrolamarao.metal.ixx`: adds C++ module interface sources to "main" component (at `src/main/cxx`) with tasks
* `br.dev.pedrolamarao.metal.base`: adds the Gradle Metal service and extension
* `br.dev.pedrolamarao.metal.application`: conventional application project
* `br.dev.pedrolamarao.metal.archive`: conventional archive project
* `br.dev.pedrolamarao.metal.asm`: adds assembler source sets
* `br.dev.pedrolamarao.metal.c`: adds C sources sets
* `br.dev.pedrolamarao.metal.cpp`: adds C preprocessor source sets
* `br.dev.pedrolamarao.metal.cxx`: adds C++ module implementation source sets
* `br.dev.pedrolamarao.metal.ixx`: adds C++ module interface source sets
Under construction:

* dependencies on external cmake project, maven repository
* GCC and MSVC tools
* variant flavours (release, debug)
* variant target machines (any "triple")
* build flavour support (e.g. `debug`, `release`)
* shared library component
* source dependencies on cmake project
* binary dependencies on maven repository
* GCC tools
* MSVC tools
For development status, see Github issues at link:https://github.com/pedrolamarao/gradle-metal/issues[].
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,66 @@ public void language (String language) throws IOException
.withProjectDir(projectDir.toFile())
.build();
}

@Test
public void languageC () throws IOException
{
final var languageDir = projectDir.resolve("src/main/c");

Files.createDirectories(languageDir);

Files.writeString(languageDir.resolve("main.c"),
"""
int main (int argc, char * argv[])
{
return 0;
}
""");

Files.writeString(projectDir.resolve("build.gradle.kts"),
"""
plugins {
id("br.dev.pedrolamarao.metal.application")
id("br.dev.pedrolamarao.metal.c")
}
"""
);

GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectDir.toFile())
.withArguments("run-main")
.build();
}

@Test
public void languageCxx () throws IOException
{
final var languageDir = projectDir.resolve("src/main/cxx");

Files.createDirectories(languageDir);

Files.writeString(languageDir.resolve("main.cxx"),
"""
int main (int argc, char * argv[])
{
return 0;
}
""");

Files.writeString(projectDir.resolve("build.gradle.kts"),
"""
plugins {
id("br.dev.pedrolamarao.metal.application")
id("br.dev.pedrolamarao.metal.cxx")
}
"""
);

GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectDir.toFile())
.withArguments("run-main")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

public class AsmFunctionalTest
{
Expand Down Expand Up @@ -47,6 +47,8 @@ public void compile () throws IOException
.withArguments("compile-main-asm")
.build();

assertTrue( Files.exists(projectDir.resolve("build/obj")) );

try (var stream = Files.walk(projectDir.resolve("build/obj")).filter(Files::isRegularFile)) {
assertEquals( 1, stream.count() );
}
Expand Down Expand Up @@ -80,6 +82,87 @@ public void compileOptions () throws IOException
.withProjectDir(projectDir.toFile())
.withArguments("--quiet","compileOptions")
.build();

assertEquals("[--foo]",compileOptions.getOutput());
}

@Test
public void targetDisabled () throws IOException
{
Files.createDirectories(projectDir.resolve("src/main/asm"));

Files.writeString(projectDir.resolve("src/main/asm/bar.s"),
"""
.global foo
foo:
ret
"""
);

Files.writeString(projectDir.resolve("build.gradle.kts"),
"""
plugins {
id("br.dev.pedrolamarao.metal.asm")
}
metal {
asm {
create("main") {
targets = setOf("i686-elf")
}
}
}
"""
);

GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectDir.toFile())
.withArguments("compile-main-asm","-Pmetal.target=x86_64-elf")
.build();

assertFalse( Files.exists(projectDir.resolve("build/obj")) );
}

@Test
public void targetEnabled () throws IOException
{
Files.createDirectories(projectDir.resolve("src/main/asm"));

Files.writeString(projectDir.resolve("src/main/asm/bar.s"),
"""
.global foo
foo:
ret
"""
);

Files.writeString(projectDir.resolve("build.gradle.kts"),
"""
plugins {
id("br.dev.pedrolamarao.metal.asm")
}
metal {
asm {
create("main") {
targets = setOf("i686-elf")
}
}
}
"""
);

GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectDir.toFile())
.withArguments("compile-main-asm","-Pmetal.target=i686-elf")
.build();

assertTrue( Files.exists(projectDir.resolve("build/obj")) );

try (var stream = Files.walk(projectDir.resolve("build/obj")).filter(Files::isRegularFile)) {
assertEquals( 1, stream.count() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

public class CFunctionalTest
{
Expand Down Expand Up @@ -49,6 +49,8 @@ int main (int argc, char * argv [])
.withDebug(true)
.build();

assertTrue( Files.exists(projectDir.resolve("build/obj")) );

try (var stream = Files.walk(projectDir.resolve("build/obj")).filter(Files::isRegularFile)) {
assertEquals( 1, stream.count() );
}
Expand Down Expand Up @@ -82,6 +84,91 @@ public void compileOptions () throws IOException
.withProjectDir(projectDir.toFile())
.withArguments("--quiet","compileOptions")
.build();

assertEquals("[--foo]",compileOptions.getOutput());
}

@Test
public void targetDisabled () throws IOException
{
Files.createDirectories(projectDir.resolve("src/main/c"));

Files.writeString(projectDir.resolve("src/main/c/main.c"),
"""
int main (int argc, char * argv [])
{
return 0;
}
"""
);

Files.writeString(projectDir.resolve("build.gradle.kts"),
"""
plugins {
id("br.dev.pedrolamarao.metal.c")
}
metal {
c {
create("main") {
targets = setOf("i686-elf")
}
}
}
"""
);

GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectDir.toFile())
.withArguments("compile-main-c","-Pmetal.target=x86_64-elf")
.withDebug(true)
.build();

assertFalse( Files.exists(projectDir.resolve("build/obj")) );
}

@Test
public void targetEnabled () throws IOException
{
Files.createDirectories(projectDir.resolve("src/main/c"));

Files.writeString(projectDir.resolve("src/main/c/main.c"),
"""
int main (int argc, char * argv [])
{
return 0;
}
"""
);

Files.writeString(projectDir.resolve("build.gradle.kts"),
"""
plugins {
id("br.dev.pedrolamarao.metal.c")
}
metal {
c {
create("main") {
targets = setOf("i686-elf")
}
}
}
"""
);

GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectDir.toFile())
.withArguments("compile-main-c","-Pmetal.target=i686-elf")
.withDebug(true)
.build();

assertTrue( Files.exists(projectDir.resolve("build/obj")) );

try (var stream = Files.walk(projectDir.resolve("build/obj")).filter(Files::isRegularFile)) {
assertEquals( 1, stream.count() );
}
}
}
Loading

0 comments on commit 4afa361

Please sign in to comment.