From bf2ed768ca7c94af3394634eaa798d9ffecacf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Lamar=C3=A3o?= Date: Mon, 23 Oct 2023 20:54:19 -0300 Subject: [PATCH] Improve source sets (#59) * Rewire source sets and tasks via intermediate file collections. Add "compile", "import", "include" and "link" collections to consume the corresponding type. Rename the resolvable providers to "compilables", ""importables", "includables" and "linkables". * Update nomenclature and remove obsolete properties. * Remove MetalApplication.archive --- .../gradle/metal/cxx/CxxFunctionalTest.java | 2 +- .../gradle/metal/ixx/IxxFunctionalTest.java | 2 +- .../gradle/metal/asm/MetalAsmPlugin.java | 15 ++- .../gradle/metal/asm/MetalAsmSourceSet.java | 75 +++++++++++++ .../gradle/metal/asm/MetalAsmSources.java | 79 ------------- .../gradle/metal/base/MetalApplication.java | 27 +---- .../gradle/metal/base/MetalArchive.java | 19 +--- .../gradle/metal/base/MetalBasePlugin.java | 12 +- .../gradle/metal/base/MetalComponent.java | 14 +-- .../metal/base/MetalComponentPlugin.java | 80 ++++++------- .../gradle/metal/base/MetalLinkTask.java | 17 +-- ...{MetalSources.java => MetalSourceSet.java} | 8 +- .../gradle/metal/c/MetalCPlugin.java | 15 ++- .../gradle/metal/c/MetalCSourceSet.java | 75 +++++++++++++ .../gradle/metal/c/MetalCSources.java | 81 ------------- .../gradle/metal/cpp/MetalCppPlugin.java | 6 +- ...CppSources.java => MetalCppSourceSet.java} | 26 ++++- .../metal/cxx/MetalCxxCompileBaseTask.java | 8 +- .../gradle/metal/cxx/MetalCxxPlugin.java | 25 +++-- .../gradle/metal/cxx/MetalCxxSourceSet.java | 89 +++++++++++++++ .../gradle/metal/cxx/MetalCxxSources.java | 85 -------------- .../metal/ixx/MetalIxxCommandsTask.java | 4 +- .../metal/ixx/MetalIxxCompileBaseTask.java | 2 +- .../gradle/metal/ixx/MetalIxxCompileTask.java | 4 +- .../gradle/metal/ixx/MetalIxxPlugin.java | 24 ++-- .../gradle/metal/ixx/MetalIxxSourceSet.java | 106 ++++++++++++++++++ .../gradle/metal/ixx/MetalIxxSources.java | 102 ----------------- 27 files changed, 492 insertions(+), 510 deletions(-) create mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSourceSet.java delete mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSources.java rename plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/{MetalSources.java => MetalSourceSet.java} (75%) create mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSourceSet.java delete mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSources.java rename plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/{MetalCppSources.java => MetalCppSourceSet.java} (60%) create mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSourceSet.java delete mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSources.java create mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSourceSet.java delete mode 100644 plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSources.java diff --git a/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/cxx/CxxFunctionalTest.java b/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/cxx/CxxFunctionalTest.java index e1a94d8..e8df063 100644 --- a/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/cxx/CxxFunctionalTest.java +++ b/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/cxx/CxxFunctionalTest.java @@ -124,7 +124,7 @@ int main (int argc, char * argv []) } cxx { create("main") { - includes.from( cpp.named("main").map { it.sources } ) + include.from( cpp.named("main").map { it.includables } ) } } } diff --git a/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/ixx/IxxFunctionalTest.java b/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/ixx/IxxFunctionalTest.java index 89312cd..86b9c60 100644 --- a/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/ixx/IxxFunctionalTest.java +++ b/plugins/src/functionalTest/java/br/dev/pedrolamarao/gradle/metal/ixx/IxxFunctionalTest.java @@ -200,7 +200,7 @@ int greet (int argc, char * argv[]) ixx { create("main") { compileOptions = listOf("-std=c++20") - includes.from( cpp.named("main").map { it.sources } ) + include.from( cpp.named("main").map { it.includables } ) } } } diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmPlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmPlugin.java index 9e039c5..48cecc9 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmPlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmPlugin.java @@ -24,11 +24,11 @@ public void apply (Project project) final var metal = project.getExtensions().getByType(MetalExtension.class); - final var asm = project.getObjects().domainObjectContainer(MetalAsmSources.class, name -> createSources(project,name)); + final var asm = project.getObjects().domainObjectContainer(MetalAsmSourceSet.class, name -> createSourceSet(project,name)); metal.getExtensions().add("asm", asm); } - static MetalAsmSources createSources (Project project, String name) + static MetalAsmSourceSet createSourceSet (Project project, String name) { final var configurations = project.getConfigurations(); final var layout = project.getLayout(); @@ -36,11 +36,14 @@ static MetalAsmSources createSources (Project project, String name) final var objects = project.getObjects(); final var tasks = project.getTasks(); + final var linkables = objects.fileCollection(); + final var commandsTask = tasks.register("commands-%s-asm".formatted(name),MetalAsmCommandsTask.class); final var compileTask = tasks.register("compile-%s-asm".formatted(name),MetalAsmCompileTask.class); - final var sourceSet = objects.newInstance(MetalAsmSources.class,commandsTask,compileTask,name); + linkables.from(compileTask); + final var sourceSet = objects.newInstance(MetalAsmSourceSet.class,linkables,name); sourceSet.getCompileOptions().convention(metal.getCompileOptions()); - sourceSet.getIncludes().from(configurations.named(INCLUDABLE_DEPENDENCIES)); + sourceSet.getInclude().from(configurations.named(INCLUDABLE_DEPENDENCIES)); sourceSet.getSources().from(layout.getProjectDirectory().dir("src/%s/asm".formatted(name))); sourceSet.getTargets().convention(metal.getTargets()); @@ -50,7 +53,7 @@ static MetalAsmSources createSources (Project project, String name) commandsTask.configure(task -> { task.getCompileOptions().convention(sourceSet.getCompileOptions()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getIncludables().from(sourceSet.getInclude()); task.getObjectDirectory().convention(objectDirectory.map(Directory::getAsFile)); task.getOutputDirectory().convention(commandsDirectory); task.setSource(sourceSet.getSources()); @@ -61,7 +64,7 @@ static MetalAsmSources createSources (Project project, String name) { task.onlyIf("target is enabled",it -> sourceSet.getTargets().zip(task.getTarget(),(targets,target) -> targets.isEmpty() || targets.contains(target)).get()); task.getCompileOptions().convention(sourceSet.getCompileOptions()); - task.getIncludables().from(sourceSet.getSources()); + task.getIncludables().from(sourceSet.getInclude()); task.getOutputDirectory().convention(objectDirectory); task.setSource(sourceSet.getSources()); task.getTarget().convention(metal.getTarget()); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSourceSet.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSourceSet.java new file mode 100644 index 0000000..91abf62 --- /dev/null +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSourceSet.java @@ -0,0 +1,75 @@ +package br.dev.pedrolamarao.gradle.metal.asm; + +import br.dev.pedrolamarao.gradle.metal.base.MetalSourceSet; +import org.gradle.api.NonNullApi; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileCollection; +import org.gradle.api.provider.ListProperty; + +import javax.inject.Inject; + +/** + * Assembler source set. + */ +@NonNullApi +public abstract class MetalAsmSourceSet extends MetalSourceSet +{ + private final FileCollection linkables; + + private final String name; + + /** + * Constructor. + * + * @param linkables linkable elements + * @param name source set name + */ + @Inject + public MetalAsmSourceSet (FileCollection linkables, String name) + { + this.linkables = linkables; + this.name = name; + } + + /** + * Compile options. + * + * @return property + */ + public abstract ListProperty getCompileOptions (); + + /** + * Include dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getInclude (); + + /** + * {@inheritDoc} + */ + @Override + public String getName () + { + return name; + } + + /** + * Link elements. + * + * @return collection + */ + public FileCollection getLinkables () + { + return linkables; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString () + { + return "MetalAsmSourceSet[%s]".formatted(name); + } +} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSources.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSources.java deleted file mode 100644 index 08e96ee..0000000 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/asm/MetalAsmSources.java +++ /dev/null @@ -1,79 +0,0 @@ -package br.dev.pedrolamarao.gradle.metal.asm; - -import br.dev.pedrolamarao.gradle.metal.base.MetalSources; -import org.gradle.api.DefaultTask; -import org.gradle.api.NonNullApi; -import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.provider.ListProperty; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.TaskOutputs; -import org.gradle.api.tasks.TaskProvider; - -import javax.inject.Inject; - -/** - * Assembler sources. - */ -@NonNullApi -public abstract class MetalAsmSources extends MetalSources -{ - private final TaskProvider commandsTask; - - private final TaskProvider compileTask; - - private final String name; - - /** - * Constructor. - * - * @param commandsTask commands task - * @param compileTask compile task - * @param name name - */ - @Inject - public MetalAsmSources (TaskProvider commandsTask, TaskProvider compileTask, String name) - { - this.commandsTask = commandsTask; - this.compileTask = compileTask; - this.name = name; - } - - /** - * Compile options. - * - * @return property - */ - public abstract ListProperty getCompileOptions (); - - /** - * Preprocessor includes. - * - * @return collection - */ - public abstract ConfigurableFileCollection getIncludes (); - - /** - * {@inheritDoc} - */ - @Override - public String getName () - { - return name; - } - - /** - * Compilation outputs. - * - * @return provider - */ - public Provider getOutputs () - { - return compileTask.map(DefaultTask::getOutputs); - } - - @Override - public String toString () - { - return "MetalAsmSources[%s]".formatted(name); - } -} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalApplication.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalApplication.java index edb9809..2210ed0 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalApplication.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalApplication.java @@ -4,9 +4,7 @@ import org.gradle.api.Named; import org.gradle.api.NonNullApi; -import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.provider.ListProperty; -import org.gradle.api.tasks.TaskProvider; import javax.inject.Inject; @@ -16,30 +14,19 @@ @NonNullApi public abstract class MetalApplication extends MetalComponent implements Named { - private final TaskProvider linkTask; - private final String name; /** * Constructor. * - * @param linkTask link task - * @param name name + * @param name component name */ @Inject - public MetalApplication (TaskProvider linkTask, String name) + public MetalApplication (String name) { - this.linkTask = linkTask; this.name = name; } - /** - * Archives. - * - * @return collection - */ - public abstract ConfigurableFileCollection getArchives (); - /** * Link options. * @@ -47,16 +34,6 @@ public MetalApplication (TaskProvider linkTask, String name) */ public abstract ListProperty getLinkOptions (); - /** - * Link task. - * - * @return provider - */ - public TaskProvider getLinkTask () - { - return linkTask; - } - /** * {@inheritDoc} */ diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalArchive.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalArchive.java index 4a480e8..b4773ce 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalArchive.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalArchive.java @@ -5,7 +5,6 @@ import org.gradle.api.Named; import org.gradle.api.NonNullApi; import org.gradle.api.provider.ListProperty; -import org.gradle.api.tasks.TaskProvider; import javax.inject.Inject; @@ -15,20 +14,16 @@ @NonNullApi public abstract class MetalArchive extends MetalComponent implements Named { - private final TaskProvider archiveTask; - private final String name; /** * Constructor. * - * @param archiveTask archive task - * @param name name + * @param name component name */ @Inject - public MetalArchive (TaskProvider archiveTask, String name) + public MetalArchive (String name) { - this.archiveTask = archiveTask; this.name = name; } @@ -39,16 +34,6 @@ public MetalArchive (TaskProvider archiveTask, String name) */ public abstract ListProperty getArchiveOptions (); - /** - * Archive task. - * - * @return provider - */ - public TaskProvider getArchiveTask () - { - return archiveTask; - } - /** * {@inheritDoc} */ diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalBasePlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalBasePlugin.java index 1521435..5c93209 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalBasePlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalBasePlugin.java @@ -185,18 +185,18 @@ static MetalApplication createApplication (Project project, String name) final var tasks = project.getTasks(); final var linkTask = tasks.register("link-%s".formatted(name),MetalLinkTask.class); - final var component = objects.newInstance(MetalApplication.class,linkTask,name); + final var component = objects.newInstance(MetalApplication.class,name); + component.getLink().from(configurations.named(Metal.LINKABLE_DEPENDENCIES)); component.getLinkOptions().convention(metal.getLinkOptions()); component.getTargets().convention(metal.getTargets()); - component.getArchives().from(configurations.named(Metal.LINKABLE_DEPENDENCIES)); linkTask.configure(task -> { task.onlyIf("target is enabled",it -> component.getTargets().zip(task.getTarget(),(targets,target) -> targets.isEmpty() || targets.contains(target)).get()); - task.getArchives().from(component.getArchives()); + task.getLink().from(component.getLink()); task.getLinkOptions().convention(component.getLinkOptions()); task.getOutputDirectory().convention(layout.getBuildDirectory().dir("exe/%s".formatted(name))); - task.setSource(component.getSources()); + task.setSource(component.getSource()); task.getTarget().convention(metal.getTarget()); }); @@ -224,7 +224,7 @@ static MetalArchive createArchive (Project project, String name) final var tasks = project.getTasks(); final var archiveTask = tasks.register("archive-%s".formatted(name),MetalArchiveTask.class); - final var component = objects.newInstance(MetalArchive.class,archiveTask,name); + final var component = objects.newInstance(MetalArchive.class,name); component.getArchiveOptions().convention(metal.getArchiveOptions()); component.getTargets().convention(metal.getTargets()); @@ -233,7 +233,7 @@ static MetalArchive createArchive (Project project, String name) task.onlyIf("target is enabled",it -> component.getTargets().zip(task.getTarget(),(targets,target) -> targets.isEmpty() || targets.contains(target)).get()); task.getArchiveOptions().convention(component.getArchiveOptions()); task.getOutputDirectory().convention(layout.getBuildDirectory().dir("lib/%s".formatted(name))); - task.setSource(component.getSources()); + task.setSource(component.getSource()); task.getTarget().convention(metal.getTarget()); }); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponent.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponent.java index 703a9e2..9f72fc0 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponent.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponent.java @@ -10,21 +10,21 @@ public abstract class MetalComponent implements Named { /** - * Internal source file collection. + * Link dependencies. * - * @return collection + * @return configurable collection */ - protected abstract ConfigurableFileCollection getInternalSources (); + protected abstract ConfigurableFileCollection getLink (); /** - * Source file collection. + * Component source. * - * @return collection + * @return configurable collection */ - public abstract ConfigurableFileCollection getSources (); + public abstract ConfigurableFileCollection getSource (); /** - * Target set. + * Component target. * * @return property */ diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponentPlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponentPlugin.java index 0d2fd7a..28e2022 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponentPlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalComponentPlugin.java @@ -1,13 +1,15 @@ package br.dev.pedrolamarao.gradle.metal.base; -import br.dev.pedrolamarao.gradle.metal.asm.MetalAsmSources; -import br.dev.pedrolamarao.gradle.metal.c.MetalCSources; -import br.dev.pedrolamarao.gradle.metal.cpp.MetalCppSources; -import br.dev.pedrolamarao.gradle.metal.cxx.MetalCxxSources; -import br.dev.pedrolamarao.gradle.metal.ixx.MetalIxxSources; +import br.dev.pedrolamarao.gradle.metal.asm.MetalAsmSourceSet; +import br.dev.pedrolamarao.gradle.metal.c.MetalCSourceSet; +import br.dev.pedrolamarao.gradle.metal.cpp.MetalCppSourceSet; +import br.dev.pedrolamarao.gradle.metal.cxx.MetalCxxSourceSet; +import br.dev.pedrolamarao.gradle.metal.ixx.MetalIxxSourceSet; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; +import java.io.File; + /** * Component project plugin. */ @@ -33,7 +35,7 @@ protected void configure (Project project, MetalComponent component) { final var metal = project.getExtensions().getByType(MetalExtension.class); final var cpp = (NamedDomainObjectContainer) metal.getExtensions().getByName("cpp"); - final var sources = (MetalCppSources) cpp.create(name); + final var sources = (MetalCppSourceSet) cpp.create(name); sources.getTargets().convention(component.getTargets()); project.getLogger().info("gradle-metal: creating main sources: {}",sources); }); @@ -44,9 +46,9 @@ protected void configure (Project project, MetalComponent component) { final var metal = project.getExtensions().getByType(MetalExtension.class); final var asm = (NamedDomainObjectContainer) metal.getExtensions().getByName("asm"); - final var sources = (MetalAsmSources) asm.create(name); + final var sources = (MetalAsmSourceSet) asm.create(name); sources.getTargets().convention(component.getTargets()); - component.getSources().from(sources.getOutputs()); + component.getSource().from(sources.getLinkables()); project.getLogger().info("gradle-metal: creating main sources: {}",sources); }); @@ -56,9 +58,9 @@ protected void configure (Project project, MetalComponent component) { final var metal = project.getExtensions().getByType(MetalExtension.class); final var c = (NamedDomainObjectContainer) metal.getExtensions().getByName("c"); - final var sources = (MetalCSources) c.create(name); + final var sources = (MetalCSourceSet) c.create(name); sources.getTargets().convention(component.getTargets()); - component.getSources().from(sources.getOutputs()); + component.getSource().from(sources.getLinkables()); project.getLogger().info("gradle-metal: creating main sources: {}",sources); }); @@ -68,9 +70,9 @@ protected void configure (Project project, MetalComponent component) { final var metal = project.getExtensions().getByType(MetalExtension.class); final var cxx = (NamedDomainObjectContainer) metal.getExtensions().getByName("cxx"); - final var sources = (MetalCxxSources) cxx.create(name); + final var sources = (MetalCxxSourceSet) cxx.create(name); sources.getTargets().convention(component.getTargets()); - component.getSources().from(sources.getOutputs()); + component.getSource().from(sources.getLinkables()); project.getLogger().info("gradle-metal: creating main sources: {}",sources); }); @@ -80,12 +82,12 @@ protected void configure (Project project, MetalComponent component) { final var metal = project.getExtensions().getByType(MetalExtension.class); final var ixx = (NamedDomainObjectContainer) metal.getExtensions().getByName("ixx"); - final var sources = (MetalIxxSources) ixx.create(name); + final var sources = (MetalIxxSourceSet) ixx.create(name); sources.getTargets().convention(component.getTargets()); project.getLogger().info("gradle-metal: creating main sources: {}",sources); }); - // if cpp sources then wire to other sources' includables + // if cpp sources then wire to other sources' includes project.afterEvaluate(it -> { @@ -93,33 +95,33 @@ protected void configure (Project project, MetalComponent component) final var cppContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("cpp"); if (cppContainer == null) return; - final var cpp = (MetalCppSources) cppContainer.getByName(name); + final var cpp = (MetalCppSourceSet) cppContainer.getByName(name); final var asmContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("asm"); if (asmContainer != null) { - final var asm = (MetalAsmSources) asmContainer.getByName(name); - asm.getIncludes().from( cpp.getSources() ); + final var asm = (MetalAsmSourceSet) asmContainer.getByName(name); + asm.getInclude().from( cpp.getSources() ); project.getLogger().info("gradle-metal: wiring sources: {} -> {}",cpp,asm); } final var cContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("c"); if (cContainer != null) { - final var c = (MetalCSources) cContainer.getByName(name); - c.getIncludes().from( cpp.getSources() ); + final var c = (MetalCSourceSet) cContainer.getByName(name); + c.getInclude().from( cpp.getSources() ); project.getLogger().info("gradle-metal: wiring sources: {} -> {}",cpp,c); } final var cxxContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("cxx"); if (cxxContainer != null) { - final var cxx = (MetalCxxSources) cxxContainer.getByName(name); - cxx.getIncludes().from( cpp.getSources() ); + final var cxx = (MetalCxxSourceSet) cxxContainer.getByName(name); + cxx.getInclude().from( cpp.getSources() ); project.getLogger().info("gradle-metal: wiring sources: {} -> {}",cpp,cxx); } final var ixxContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("ixx"); if (ixxContainer != null) { - final var ixx = (MetalIxxSources) ixxContainer.getByName(name); - ixx.getIncludes().from( cpp.getSources() ); + final var ixx = (MetalIxxSourceSet) ixxContainer.getByName(name); + ixx.getInclude().from( cpp.getSources() ); project.getLogger().info("gradle-metal: wiring sources: {} -> {}",cpp,ixx); } }); @@ -132,13 +134,13 @@ protected void configure (Project project, MetalComponent component) final var ixxContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("ixx"); if (ixxContainer == null) return; - final var ixx = (MetalIxxSources) ixxContainer.getByName(name); + final var ixx = (MetalIxxSourceSet) ixxContainer.getByName(name); final var cxxContainer = (NamedDomainObjectContainer) metal.getExtensions().findByName("cxx"); if (cxxContainer != null) { - final var cxx = (MetalCxxSources) cxxContainer.getByName(name); - cxx.getImports().from( ixx.getOutputDirectory() ); - cxx.getSources().from( ixx.getOutputs() ); + final var cxx = (MetalCxxSourceSet) cxxContainer.getByName(name); + cxx.getCompile().from( ixx.getCompilables() ); + cxx.getImport().from( ixx.getImportables() ); project.getLogger().info("gradle-metal: wiring sources: {} -> {}",ixx,cxx); } }); @@ -161,8 +163,8 @@ protected void wire (Project project, MetalComponent dependent, MetalComponent d { final var metal = extensions.getByType(MetalExtension.class); final var container = (NamedDomainObjectContainer) metal.getExtensions().getByName("asm"); - final var sources = (MetalAsmSources) container.getByName(dependency.getName()); - dependent.getInternalSources().from(sources.getOutputs()); + final var sources = (MetalAsmSourceSet) container.getByName(dependency.getName()); + dependent.getLink().from(sources.getLinkables().filter(File::isFile)); logger.info("gradle-metal: wiring: {} -> {}", sources, dependent); }); @@ -170,8 +172,8 @@ protected void wire (Project project, MetalComponent dependent, MetalComponent d { final var metal = extensions.getByType(MetalExtension.class); final var container = (NamedDomainObjectContainer) metal.getExtensions().getByName("c"); - final var sources = (MetalCSources) container.getByName(dependency.getName()); - dependent.getInternalSources().from(sources.getOutputs()); + final var sources = (MetalCSourceSet) container.getByName(dependency.getName()); + dependent.getLink().from(sources.getLinkables().filter(File::isFile)); logger.info("gradle-metal: wiring: {} -> {}", sources, dependent); }); @@ -179,8 +181,8 @@ protected void wire (Project project, MetalComponent dependent, MetalComponent d { final var metal = extensions.getByType(MetalExtension.class); final var container = (NamedDomainObjectContainer) metal.getExtensions().getByName("cxx"); - final var sources = (MetalCxxSources) container.getByName(dependency.getName()); - dependent.getInternalSources().from(sources.getOutputs()); + final var sources = (MetalCxxSourceSet) container.getByName(dependency.getName()); + dependent.getLink().from(sources.getLinkables().filter(File::isFile)); logger.info("gradle-metal: wiring: {} -> {}", sources, dependent); }); @@ -188,9 +190,9 @@ protected void wire (Project project, MetalComponent dependent, MetalComponent d { final var metal = extensions.getByType(MetalExtension.class); final var container = (NamedDomainObjectContainer) metal.getExtensions().getByName("ixx"); - final var dependentIxx = (MetalIxxSources) container.getByName(dependent.getName()); - final var dependencyIxx = (MetalIxxSources) container.getByName(dependency.getName()); - dependentIxx.getImports().from(dependencyIxx.getOutputDirectory()); + final var dependentIxx = (MetalIxxSourceSet) container.getByName(dependent.getName()); + final var dependencyIxx = (MetalIxxSourceSet) container.getByName(dependency.getName()); + dependentIxx.getImport().from(dependencyIxx.getImportables()); logger.info("gradle-metal: wiring: {} -> {}", dependencyIxx, dependentIxx); }); @@ -213,9 +215,9 @@ protected void wire (Project project, MetalComponent dependent, MetalComponent d if (ixx != null) { if (cxx != null) { - final var dependentCxx = (MetalCxxSources) cxx.getByName(dependent.getName()); - final var dependencyIxx = (MetalIxxSources) ixx.getByName(dependency.getName()); - dependentCxx.getImports().from( dependencyIxx.getOutputDirectory() ); + final var dependentCxx = (MetalCxxSourceSet) cxx.getByName(dependent.getName()); + final var dependencyIxx = (MetalIxxSourceSet) ixx.getByName(dependency.getName()); + dependentCxx.getImport().from( dependencyIxx.getImportables() ); // TODO: wire inputs and outputs, not tasks tasks.named("commands-test-cxx").configure(task -> task.dependsOn("compile-main-ixx")); tasks.named("compile-test-cxx").configure(task -> task.dependsOn("compile-main-ixx")); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalLinkTask.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalLinkTask.java index 5908f1f..5d55c76 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalLinkTask.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalLinkTask.java @@ -20,12 +20,12 @@ public abstract class MetalLinkTask extends MetalSourceTask { /** - * Archives. + * Link dependencies. * - * @return collection + * @return configurable collection */ @InputFiles - public abstract ConfigurableFileCollection getArchives (); + public abstract ConfigurableFileCollection getLink (); /** * Linker executable path. @@ -69,14 +69,6 @@ public Provider getOutput () @Internal public abstract DirectoryProperty getOutputDirectory (); - /** - * Internal source file collection. - * - * @return collection - */ - @InputFiles - protected abstract ConfigurableFileCollection getInternalSources (); - /** * Exec operations service. * @@ -106,9 +98,8 @@ public void link () linkArgs.add("-fuse-ld=lld"); linkArgs.addAll(getLinkOptions().get()); linkArgs.add("--output=%s".formatted(output)); - getArchives().forEach(file -> linkArgs.add(file.toString())); getSource().forEach(file -> linkArgs.add(file.toString())); - getInternalSources().forEach(file -> linkArgs.add(file.toString())); + getLink().forEach(file -> linkArgs.add(file.toString())); getExec().exec(it -> { diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalSources.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalSourceSet.java similarity index 75% rename from plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalSources.java rename to plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalSourceSet.java index 05cb058..eefe450 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalSources.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/base/MetalSourceSet.java @@ -7,17 +7,17 @@ /** * Gradle Metal sources. */ -public abstract class MetalSources implements Named +public abstract class MetalSourceSet implements Named { /** - * Source file collection. + * Sources. * - * @return collection + * @return configurable collection */ public abstract ConfigurableFileCollection getSources (); /** - * Target set. + * Targets. * * @return property */ diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCPlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCPlugin.java index 3fedf9f..9d8b86e 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCPlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCPlugin.java @@ -24,11 +24,11 @@ public void apply (Project project) final var metal = project.getExtensions().getByType(MetalExtension.class); - final var c = project.getObjects().domainObjectContainer(MetalCSources.class, name -> createSources(project,name)); + final var c = project.getObjects().domainObjectContainer(MetalCSourceSet.class, name -> createSourceSet(project,name)); metal.getExtensions().add("c", c); } - static MetalCSources createSources (Project project, String name) + static MetalCSourceSet createSourceSet (Project project, String name) { final var configurations = project.getConfigurations(); final var layout = project.getLayout(); @@ -36,11 +36,14 @@ static MetalCSources createSources (Project project, String name) final var objects = project.getObjects(); final var tasks = project.getTasks(); + final var linkables = objects.fileCollection(); + final var commandsTask = tasks.register("commands-%s-c".formatted(name),MetalCCommandsTask.class); final var compileTask = tasks.register("compile-%s-c".formatted(name),MetalCCompileTask.class); - final var sourceSet = objects.newInstance(MetalCSources.class,commandsTask,compileTask,name); + linkables.from(compileTask); + final var sourceSet = objects.newInstance(MetalCSourceSet.class,linkables,name); sourceSet.getCompileOptions().convention(metal.getCompileOptions()); - sourceSet.getIncludes().from(configurations.named(INCLUDABLE_DEPENDENCIES)); + sourceSet.getInclude().from(configurations.named(INCLUDABLE_DEPENDENCIES)); sourceSet.getSources().from(layout.getProjectDirectory().dir("src/%s/c".formatted(name))); sourceSet.getTargets().convention(metal.getTargets()); @@ -50,7 +53,7 @@ static MetalCSources createSources (Project project, String name) commandsTask.configure(task -> { task.getCompileOptions().convention(sourceSet.getCompileOptions()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getIncludables().from(sourceSet.getInclude()); task.getObjectDirectory().set(objectDirectory.map(Directory::getAsFile)); task.getOutputDirectory().set(commandsDirectory); task.setSource(sourceSet.getSources()); @@ -61,7 +64,7 @@ static MetalCSources createSources (Project project, String name) { task.onlyIf("target is enabled",it -> sourceSet.getTargets().zip(task.getTarget(),(targets,target) -> targets.isEmpty() || targets.contains(target)).get()); task.getCompileOptions().convention(sourceSet.getCompileOptions()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getIncludables().from(sourceSet.getInclude()); task.getOutputDirectory().set(objectDirectory); task.setSource(sourceSet.getSources()); task.getTarget().convention(metal.getTarget()); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSourceSet.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSourceSet.java new file mode 100644 index 0000000..30e3bed --- /dev/null +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSourceSet.java @@ -0,0 +1,75 @@ +package br.dev.pedrolamarao.gradle.metal.c; + +import br.dev.pedrolamarao.gradle.metal.base.MetalSourceSet; +import org.gradle.api.NonNullApi; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileCollection; +import org.gradle.api.provider.ListProperty; + +import javax.inject.Inject; + +/** + * C sources. + */ +@NonNullApi +public abstract class MetalCSourceSet extends MetalSourceSet +{ + private final FileCollection linkables; + + private final String name; + + /** + * Constructor. + * + * @param linkables linkable elements + * @param name source set name + */ + @Inject + public MetalCSourceSet (FileCollection linkables, String name) + { + this.linkables = linkables; + this.name = name; + } + + /** + * Compile options. + * + * @return property + */ + public abstract ListProperty getCompileOptions (); + + /** + * Include dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getInclude (); + + /** + * {@inheritDoc} + */ + @Override + public String getName () + { + return name; + } + + /** + * Link elements. + * + * @return collection + */ + public FileCollection getLinkables () + { + return linkables; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString () + { + return "MetalCSourceSet[%s]".formatted(name); + } +} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSources.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSources.java deleted file mode 100644 index f4f397a..0000000 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/c/MetalCSources.java +++ /dev/null @@ -1,81 +0,0 @@ -package br.dev.pedrolamarao.gradle.metal.c; - -import br.dev.pedrolamarao.gradle.metal.base.MetalSources; -import org.gradle.api.DefaultTask; -import org.gradle.api.NonNullApi; -import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.provider.ListProperty; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.TaskOutputs; -import org.gradle.api.tasks.TaskProvider; - -import javax.inject.Inject; - -/** - * C sources. - */ -@NonNullApi -public abstract class MetalCSources extends MetalSources -{ - private final TaskProvider commandsTask; - - private final TaskProvider compileTask; - - private final String name; - - /** - * Constructor. - * - * @param commandsTask commands task - * @param compileTask compile task - * @param name name - */ - @Inject - public MetalCSources (TaskProvider commandsTask, TaskProvider compileTask, String name) - { - this.commandsTask = commandsTask; - this.compileTask = compileTask; - this.name = name; - } - - /** - * Compile options. - * - * @return property - */ - public abstract ListProperty getCompileOptions (); - - /** - * Preprocessor includes. - * - * @return collection - */ - public abstract ConfigurableFileCollection getIncludes (); - - /** - * Sources name. - * - * @return value - */ - @Override - public String getName () - { - return name; - } - - /** - * Compilation outputs. - * - * @return provider - */ - public Provider getOutputs () - { - return compileTask.map(DefaultTask::getOutputs); - } - - @Override - public String toString () - { - return "MetalCSources[%s]".formatted(name); - } -} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppPlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppPlugin.java index 4636ec9..8f035a0 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppPlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppPlugin.java @@ -21,18 +21,18 @@ public void apply (Project project) final var metal = project.getExtensions().getByType(MetalExtension.class); - final var cpp = project.getObjects().domainObjectContainer(MetalCppSources.class, name -> createCppSources(project,name)); + final var cpp = project.getObjects().domainObjectContainer(MetalCppSourceSet.class, name -> createCppSources(project,name)); metal.getExtensions().add("cpp", cpp); } - static MetalCppSources createCppSources (Project project, String name) + static MetalCppSourceSet createCppSources (Project project, String name) { final var configurations = project.getConfigurations(); final var layout = project.getLayout(); final var objects = project.getObjects(); final var providers = project.getProviders(); - final var sourceSet = objects.newInstance(MetalCppSources.class,name); + final var sourceSet = objects.newInstance(MetalCppSourceSet.class,name); sourceSet.getSources().from( layout.getProjectDirectory().dir("src/%s/cpp".formatted(name)) ); project.afterEvaluate(it -> diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppSources.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppSourceSet.java similarity index 60% rename from plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppSources.java rename to plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppSourceSet.java index fb248de..ea082be 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppSources.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cpp/MetalCppSourceSet.java @@ -1,7 +1,8 @@ package br.dev.pedrolamarao.gradle.metal.cpp; -import br.dev.pedrolamarao.gradle.metal.base.MetalSources; +import br.dev.pedrolamarao.gradle.metal.base.MetalSourceSet; import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileCollection; import org.gradle.api.provider.Property; import javax.inject.Inject; @@ -9,7 +10,7 @@ /** * C preprocessor sources. */ -public abstract class MetalCppSources extends MetalSources +public abstract class MetalCppSourceSet extends MetalSourceSet { private final String name; @@ -19,13 +20,23 @@ public abstract class MetalCppSources extends MetalSources * @param name name */ @Inject - public MetalCppSources (String name) + public MetalCppSourceSet (String name) { this.name = name; getPublic().convention(false); } + /** + * Include elements. + * + * @return collection + */ + public FileCollection getIncludables () + { + return getSources(); + } + /** * {@inheritDoc} */ @@ -36,19 +47,22 @@ public String getName () } /** - * If these sources a public and must be published. + * If these sources a public and publishes its include elements. * * @return true if public */ public abstract Property getPublic (); /** - * Source directory set. + * Sources. * - * @return value + * @return configurable collection */ public abstract ConfigurableFileCollection getSources (); + /** + * {@inheritDoc} + */ @Override public String toString () { diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxCompileBaseTask.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxCompileBaseTask.java index 46718ec..a8abbfa 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxCompileBaseTask.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxCompileBaseTask.java @@ -35,7 +35,7 @@ public Provider getCompiler () * @return collection */ @InputFiles - public abstract ConfigurableFileCollection getIncludables (); + public abstract ConfigurableFileCollection getInclude (); /** * Import path. @@ -43,7 +43,7 @@ public Provider getCompiler () * @return collection */ @InputFiles - public abstract ConfigurableFileCollection getImportables (); + public abstract ConfigurableFileCollection getImport (); /** * Generate compiler arguments. @@ -56,8 +56,8 @@ protected List toCompileArguments (Function formatter) final var arguments = new ArrayList(); arguments.add("--target=%s".formatted(getTarget().get())); arguments.addAll(getCompileOptions().get()); - getImportables().forEach(file -> arguments.add("-fprebuilt-module-path=%s".formatted(formatter.apply(file)))); - getIncludables().forEach(file -> arguments.add("--include-directory=%s".formatted(formatter.apply(file)))); + getImport().forEach(file -> arguments.add("-fprebuilt-module-path=%s".formatted(formatter.apply(file)))); + getInclude().forEach(file -> arguments.add("--include-directory=%s".formatted(formatter.apply(file)))); arguments.add("--compile"); return arguments; } diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxPlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxPlugin.java index 6c0cb61..975f070 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxPlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxPlugin.java @@ -25,11 +25,11 @@ public void apply (Project project) final var metal = project.getExtensions().getByType(MetalExtension.class); - final var cxx = project.getObjects().domainObjectContainer(MetalCxxSources.class, name -> createSources(project,name)); + final var cxx = project.getObjects().domainObjectContainer(MetalCxxSourceSet.class, name -> createSources(project,name)); metal.getExtensions().add("cxx", cxx); } - static MetalCxxSources createSources (Project project, String name) + static MetalCxxSourceSet createSources (Project project, String name) { final var configurations = project.getConfigurations(); final var layout = project.getLayout(); @@ -37,12 +37,15 @@ static MetalCxxSources createSources (Project project, String name) final var objects = project.getObjects(); final var tasks = project.getTasks(); + final var linkables = objects.fileCollection(); + final var commandsTask = tasks.register("commands-%s-cxx".formatted(name),MetalCxxCommandsTask.class); final var compileTask = tasks.register("compile-%s-cxx".formatted(name),MetalCxxCompileTask.class); - final var sourceSet = objects.newInstance(MetalCxxSources.class,commandsTask,compileTask,name); + linkables.from(compileTask); + final var sourceSet = objects.newInstance(MetalCxxSourceSet.class,linkables,name); sourceSet.getCompileOptions().convention(metal.getCompileOptions()); - sourceSet.getImports().from(configurations.named(IMPORTABLE_DEPENDENCIES)); - sourceSet.getIncludes().from(configurations.named(INCLUDABLE_DEPENDENCIES)); + sourceSet.getImport().from(configurations.named(IMPORTABLE_DEPENDENCIES)); + sourceSet.getInclude().from(configurations.named(INCLUDABLE_DEPENDENCIES)); sourceSet.getSources().from(layout.getProjectDirectory().dir("src/%s/cxx".formatted(name))); sourceSet.getTargets().convention(metal.getTargets()); @@ -52,11 +55,11 @@ static MetalCxxSources createSources (Project project, String name) commandsTask.configure(task -> { task.getCompileOptions().set(sourceSet.getCompileOptions()); - task.getImportables().from(sourceSet.getImports()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getImport().from(sourceSet.getImport()); + task.getInclude().from(sourceSet.getInclude()); task.getObjectDirectory().set(objectDirectory.map(Directory::getAsFile)); task.getOutputDirectory().set(commandsDirectory); - task.setSource(sourceSet.getSources()); + task.setSource(sourceSet.getSources().plus(sourceSet.getCompile())); task.getTarget().convention(metal.getTarget()); }); @@ -64,10 +67,10 @@ static MetalCxxSources createSources (Project project, String name) { task.onlyIf("target is enabled",it -> sourceSet.getTargets().zip(task.getTarget(),(targets,target) -> targets.isEmpty() || targets.contains(target)).get()); task.getCompileOptions().set(sourceSet.getCompileOptions()); - task.getImportables().from(sourceSet.getImports()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getImport().from(sourceSet.getImport()); + task.getInclude().from(sourceSet.getInclude()); task.getOutputDirectory().set(objectDirectory); - task.setSource(sourceSet.getSources()); + task.setSource(sourceSet.getSources().plus(sourceSet.getCompile())); task.getTarget().convention(metal.getTarget()); }); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSourceSet.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSourceSet.java new file mode 100644 index 0000000..d19cb25 --- /dev/null +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSourceSet.java @@ -0,0 +1,89 @@ +package br.dev.pedrolamarao.gradle.metal.cxx; + +import br.dev.pedrolamarao.gradle.metal.base.MetalSourceSet; +import org.gradle.api.NonNullApi; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileCollection; +import org.gradle.api.provider.ListProperty; + +import javax.inject.Inject; + +/** + * C++ sources. + */ +@NonNullApi +public abstract class MetalCxxSourceSet extends MetalSourceSet +{ + private final FileCollection linkables; + + private final String name; + + /** + * Constructor. + * + * @param linkables linkable elements + * @param name source set name + */ + @Inject + public MetalCxxSourceSet (FileCollection linkables, String name) + { + this.linkables = linkables; + this.name = name; + } + + /** + * Compile dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getCompile (); + + /** + * Compile options. + * + * @return property + */ + public abstract ListProperty getCompileOptions (); + + /** + * Import dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getImport (); + + /** + * Include dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getInclude (); + + /** + * {@inheritDoc} + */ + @Override + public String getName () + { + return name; + } + + /** + * Linkable elements. + * + * @return collection + */ + public FileCollection getLinkables () + { + return linkables; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString () + { + return "MetalCxxSourceSet[%s]".formatted(name); + } +} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSources.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSources.java deleted file mode 100644 index 3eab34b..0000000 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/cxx/MetalCxxSources.java +++ /dev/null @@ -1,85 +0,0 @@ -package br.dev.pedrolamarao.gradle.metal.cxx; - -import br.dev.pedrolamarao.gradle.metal.base.MetalSources; -import org.gradle.api.NonNullApi; -import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.provider.ListProperty; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.TaskOutputs; -import org.gradle.api.tasks.TaskProvider; - -import javax.inject.Inject; - -/** - * C++ sources. - */ -@NonNullApi -public abstract class MetalCxxSources extends MetalSources -{ - private final TaskProvider commandsTask; - - private final TaskProvider compileTask; - - private final String name; - - /** - * Constructor. - * - * @param commandsTask commands task - * @param compileTask compile task - * @param name name - */ - @Inject - public MetalCxxSources (TaskProvider commandsTask, TaskProvider compileTask, String name) - { - this.commandsTask = commandsTask; - this.compileTask = compileTask; - this.name = name; - } - - /** - * Compile options. - * - * @return property - */ - public abstract ListProperty getCompileOptions (); - - /** - * Preprocessor includes. - * - * @return collection - */ - public abstract ConfigurableFileCollection getIncludes (); - - /** - * C++ imports. - * - * @return collection - */ - public abstract ConfigurableFileCollection getImports (); - - /** - * {@inheritDoc} - */ - @Override - public String getName () - { - return name; - } - - /** - * Compilation outputs. - * - * @return provider - */ - public Provider getOutputs () - { - return compileTask.map(MetalCxxCompileTask::getOutputs); - } - - @Override - public String toString () - { - return "MetalCxxSources[%s]".formatted(name); - } -} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCommandsTask.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCommandsTask.java index 47ba89b..1ae556a 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCommandsTask.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCommandsTask.java @@ -56,8 +56,8 @@ public void generate () throws Exception baseArgs.add(getCompiler().get().toString().replace("\\","\\\\")); baseArgs.add("--target=%s".formatted(getTarget().get())); baseArgs.addAll(getCompileOptions().get()); - getIncludables().forEach(file -> baseArgs.add("--include-directory=%s".formatted(file).replace("\\","\\\\"))); - getImportables().forEach(file -> baseArgs.add("-fprebuilt-module-path=%s".formatted(file).replace("\\","\\\\"))); + getInclude().forEach(file -> baseArgs.add("--include-directory=%s".formatted(file).replace("\\","\\\\"))); + getImport().forEach(file -> baseArgs.add("-fprebuilt-module-path=%s".formatted(file).replace("\\","\\\\"))); baseArgs.add("-fprebuilt-module-path=%s".formatted(getObjectDirectory().get()).replace("\\","\\\\")); baseArgs.add("--precompile"); baseArgs.add("--language=c++-module"); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileBaseTask.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileBaseTask.java index 9b68a96..75fd9c0 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileBaseTask.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileBaseTask.java @@ -174,7 +174,7 @@ List scan () throws IOException, ClassNotFoundException final var scanArgs = new ArrayList(); scanArgs.add(getCompiler().get().toString()); scanArgs.addAll(getCompileOptions().get()); - getIncludables().forEach(file -> scanArgs.add("--include-directory=%s".formatted(file))); + getInclude().forEach(file -> scanArgs.add("--include-directory=%s".formatted(file))); scanArgs.add("--language=c++-module"); scanArgs.add("--precompile"); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileTask.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileTask.java index 8cc090c..616eed5 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileTask.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxCompileTask.java @@ -29,8 +29,8 @@ public void compile () throws ClassNotFoundException, IOException final var baseArgs = new ArrayList(); baseArgs.add("--target=%s".formatted(getTarget().get())); baseArgs.addAll(getCompileOptions().get()); - getIncludables().forEach(file -> baseArgs.add("--include-directory=%s".formatted(file))); - getImportables().forEach(file -> baseArgs.add("-fprebuilt-module-path=%s".formatted(file))); + getInclude().forEach(file -> baseArgs.add("--include-directory=%s".formatted(file))); + getImport().forEach(file -> baseArgs.add("-fprebuilt-module-path=%s".formatted(file))); baseArgs.add("-fprebuilt-module-path=%s".formatted(getTargetDirectory().get())); baseArgs.add("--precompile"); baseArgs.add("--language=c++-module"); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxPlugin.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxPlugin.java index 4f3153f..49392b9 100644 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxPlugin.java +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxPlugin.java @@ -2,6 +2,7 @@ import br.dev.pedrolamarao.gradle.metal.base.Metal; import br.dev.pedrolamarao.gradle.metal.base.MetalBasePlugin; +import br.dev.pedrolamarao.gradle.metal.base.MetalCompileTask; import br.dev.pedrolamarao.gradle.metal.base.MetalExtension; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -22,11 +23,11 @@ public void apply (Project project) final var metal = project.getExtensions().getByType(MetalExtension.class); - final var ixx = project.getObjects().domainObjectContainer(MetalIxxSources.class, name -> createSources(project,name)); + final var ixx = project.getObjects().domainObjectContainer(MetalIxxSourceSet.class, name -> createSources(project,name)); metal.getExtensions().add("ixx", ixx); } - static MetalIxxSources createSources (Project project, String name) + static MetalIxxSourceSet createSources (Project project, String name) { final var configurations = project.getConfigurations(); final var layout = project.getLayout(); @@ -34,12 +35,17 @@ static MetalIxxSources createSources (Project project, String name) final var objects = project.getObjects(); final var tasks = project.getTasks(); + final var compilables = objects.fileCollection(); + final var importables = objects.fileCollection(); + final var commandsTask = tasks.register("commands-%s-ixx".formatted(name), MetalIxxCommandsTask.class); final var compileTask = tasks.register("compile-%s-ixx".formatted(name), MetalIxxCompileTask.class); - final var sourceSet = objects.newInstance(MetalIxxSources.class,compileTask,name); + compilables.from(compileTask.map(MetalCompileTask::getOutputs)); + importables.from(compileTask.flatMap(MetalCompileTask::getTargetDirectory)); + final var sourceSet = objects.newInstance(MetalIxxSourceSet.class,compilables,importables,name); sourceSet.getCompileOptions().convention(metal.getCompileOptions()); - sourceSet.getImports().from(configurations.named(Metal.IMPORTABLE_DEPENDENCIES)); - sourceSet.getIncludes().from(configurations.named(Metal.INCLUDABLE_DEPENDENCIES)); + sourceSet.getImport().from(configurations.named(Metal.IMPORTABLE_DEPENDENCIES)); + sourceSet.getInclude().from(configurations.named(Metal.INCLUDABLE_DEPENDENCIES)); sourceSet.getSources().from(layout.getProjectDirectory().dir("src/%s/ixx".formatted(name))); sourceSet.getTargets().convention(metal.getTargets()); @@ -49,8 +55,8 @@ static MetalIxxSources createSources (Project project, String name) commandsTask.configure(task -> { task.getCompileOptions().convention(sourceSet.getCompileOptions()); - task.getImportables().from(sourceSet.getImports()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getImport().from(sourceSet.getImport()); + task.getInclude().from(sourceSet.getInclude()); task.getObjectDirectory().convention(objectDirectory.map(Directory::getAsFile)); task.getOutputDirectory().convention(commandsDirectory); task.setSource(sourceSet.getSources()); @@ -61,8 +67,8 @@ static MetalIxxSources createSources (Project project, String name) { task.onlyIf("target is enabled",it -> sourceSet.getTargets().zip(task.getTarget(),(targets,target) -> targets.isEmpty() || targets.contains(target)).get()); task.getCompileOptions().convention(sourceSet.getCompileOptions()); - task.getImportables().from(sourceSet.getImports()); - task.getIncludables().from(sourceSet.getIncludes()); + task.getImport().from(sourceSet.getImport()); + task.getInclude().from(sourceSet.getInclude()); task.getOutputDirectory().convention(objectDirectory); task.setSource(sourceSet.getSources()); task.getTarget().convention(metal.getTarget()); diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSourceSet.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSourceSet.java new file mode 100644 index 0000000..fa0924a --- /dev/null +++ b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSourceSet.java @@ -0,0 +1,106 @@ +package br.dev.pedrolamarao.gradle.metal.ixx; + +import br.dev.pedrolamarao.gradle.metal.base.MetalSourceSet; +import org.gradle.api.NonNullApi; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileCollection; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.Property; + +import javax.inject.Inject; + +/** + * C++ module implementation sources. + */ +@NonNullApi +public abstract class MetalIxxSourceSet extends MetalSourceSet +{ + private final FileCollection compilables; + + private final FileCollection importables; + + private final String name; + + /** + * Constructor. + * + * @param compilables compilable elements + * @param importables importable elements + * @param name source set name + */ + @Inject + public MetalIxxSourceSet (FileCollection compilables, FileCollection importables, String name) + { + this.compilables = compilables; + this.importables = importables; + this.name = name; + + getPublic().convention(false); + } + + /** + * Compile elements. + * + * @return collection + */ + public FileCollection getCompilables () + { + return compilables; + } + + /** + * Compile options. + * + * @return property + */ + public abstract ListProperty getCompileOptions (); + + /** + * Import elements. + * + * @return collection + */ + public FileCollection getImportables () + { + return importables; + } + + /** + * Import dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getImport (); + + /** + * Include dependencies. + * + * @return configurable collection + */ + public abstract ConfigurableFileCollection getInclude (); + + /** + * {@inheritDoc} + */ + @Override + public String getName () + { + return name; + } + + /** + * If this source set is public and publishes its import elements. + * + * @return property + */ + public abstract Property getPublic (); + + /** + * {@inheritDoc} + */ + @Override + public String toString () + { + return "MetalIxxSourceSet[%s]".formatted(name); + } +} diff --git a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSources.java b/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSources.java deleted file mode 100644 index 240b8de..0000000 --- a/plugins/src/main/java/br/dev/pedrolamarao/gradle/metal/ixx/MetalIxxSources.java +++ /dev/null @@ -1,102 +0,0 @@ -package br.dev.pedrolamarao.gradle.metal.ixx; - -import br.dev.pedrolamarao.gradle.metal.base.MetalSources; -import org.gradle.api.NonNullApi; -import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.file.Directory; -import org.gradle.api.provider.ListProperty; -import org.gradle.api.provider.Property; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.TaskOutputs; -import org.gradle.api.tasks.TaskProvider; - -import javax.inject.Inject; - -/** - * C++ module implementation sources. - */ -@NonNullApi -public abstract class MetalIxxSources extends MetalSources -{ - private final TaskProvider compileTask; - - private final String name; - - /** - * Constructor. - * - * @param compileTask compile task - * @param name source set name - */ - @Inject - public MetalIxxSources (TaskProvider compileTask, String name) - { - this.compileTask = compileTask; - this.name = name; - - getPublic().convention(false); - } - - /** - * Compile options. - * - * @return property - */ - public abstract ListProperty getCompileOptions (); - - /** - * Imports. - * - * @return collection - */ - public abstract ConfigurableFileCollection getImports (); - - /** - * Includes. - * - * @return collection - */ - public abstract ConfigurableFileCollection getIncludes (); - - /** - * {@inheritDoc} - */ - @Override - public String getName () - { - return name; - } - - /** - * Compilation output base directory. - * - * @return provider - */ - public Provider getOutputDirectory () - { - return compileTask.flatMap(MetalIxxCompileTask::getTargetDirectory); - } - - /** - * Compilation outputs. - * - * @return provider - */ - public Provider getOutputs () - { - return compileTask.map(MetalIxxCompileTask::getOutputs); - } - - /** - * If this source set is public and must be published. - * - * @return property - */ - public abstract Property getPublic (); - - @Override - public String toString () - { - return "MetalIxxSources[%s]".formatted(name); - } -}