diff --git a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/c/CPluginSpec.groovy b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/c/CPluginSpec.groovy index 18e2c3a..b47463b 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/c/CPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/c/CPluginSpec.groovy @@ -246,6 +246,29 @@ class CPluginSpec extends Specification { entries[1].name == 'src/main/c/main.c' } + def "can produce archive with source file in custom location"() { + File mainSv = testProjectDir.newFolder('c') + new File(mainSv, "main.c").createNewFile() + + buildFile << """ + sourceSets.main.c.srcDirs = ['c'] + """ + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments(':hdvlSourcesArchive') + .build() + + then: + new File(testProjectDir.root, 'build/hdvl-sources.zip').exists() + def zipFile = new ZipFile(new File(testProjectDir.root, 'build/hdvl-sources.zip')) + def entries = zipFile.entries().findAll { !it.directory } + entries.size() == 2 + entries[1].name == 'c/main.c' + } + def "can consume source archive"() { File dependencyProjectBuildFile = newStandardProject('dependency-project') dependencyProjectBuildFile << """ diff --git a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginSpec.groovy b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginSpec.groovy index d410e2e..be60f9e 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginSpec.groovy @@ -924,6 +924,29 @@ class SystemVerilogPluginSpec extends Specification { entries[1].name == 'src/main/sv/main.sv' } + def "can produce archive with source file in custom location"() { + File mainSv = testProjectDir.newFolder('sv') + new File(mainSv, "main.sv").createNewFile() + + buildFile << """ + sourceSets.main.sv.srcDirs = ['sv'] + """ + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments(':hdvlSourcesArchive') + .build() + + then: + new File(testProjectDir.root, 'build/hdvl-sources.zip').exists() + def zipFile = new ZipFile(new File(testProjectDir.root, 'build/hdvl-sources.zip')) + def entries = zipFile.entries().findAll { !it.directory } + entries.size() == 2 + entries[1].name == 'sv/main.sv' + } + def "can produce archive with private header"() { File mainSv = testProjectDir.newFolder('src', 'main', 'sv') new File(mainSv, "main.sv").createNewFile() @@ -945,7 +968,32 @@ class SystemVerilogPluginSpec extends Specification { entries[2].name == 'src/main/sv/private_header.svh' } - def "can produce archive with private header"() { + def "can produce archive with private header in custom location"() { + File mainSv = testProjectDir.newFolder('sv') + new File(mainSv, "main.sv").createNewFile() + new File(mainSv, "private_header.svh").createNewFile() + + buildFile << """ + sourceSets.main.sv.srcDirs = ['sv'] + """ + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments(':hdvlSourcesArchive') + .build() + + then: + new File(testProjectDir.root, 'build/hdvl-sources.zip').exists() + def zipFile = new ZipFile(new File(testProjectDir.root, 'build/hdvl-sources.zip')) + def entries = zipFile.entries().findAll { !it.directory } + entries.size() == 3 + entries[1].name == 'sv/main.sv' + entries[2].name == 'sv/private_header.svh' + } + + def "can produce archive with exported header"() { File mainSvHeaders = testProjectDir.newFolder('src', 'main', 'sv_headers') new File(mainSvHeaders, "exported_header.svh").createNewFile() @@ -964,6 +1012,29 @@ class SystemVerilogPluginSpec extends Specification { entries[1].name == 'src/main/sv_headers/exported_header.svh' } + def "can produce archive with exported header in custom location"() { + File mainSvHeaders = testProjectDir.newFolder('sv') + new File(mainSvHeaders, "exported_header.svh").createNewFile() + + buildFile << """ + sourceSets.main.svHeaders.srcDirs = ['sv'] + """ + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments(':hdvlSourcesArchive') + .build() + + then: + new File(testProjectDir.root, 'build/hdvl-sources.zip').exists() + def zipFile = new ZipFile(new File(testProjectDir.root, 'build/hdvl-sources.zip')) + def entries = zipFile.entries().findAll { !it.directory } + entries.size() == 2 + entries[1].name == 'sv/exported_header.svh' + } + def "can publishing metadata for archive"() { File mainSv = testProjectDir.newFolder('src', 'main', 'sv') new File(mainSv, "main.sv").createNewFile() diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/c/CPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/c/CPlugin.java index 509f418..44e0644 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/c/CPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/c/CPlugin.java @@ -58,7 +58,9 @@ public void execute(SourceSet sourceSet) { project.getTasks().getByName("hdvlSourcesArchive", task -> { Zip hdvlSourcesArchive = (Zip) task; hdvlSourcesArchive.from(cSourceSet.getC(), it -> { - it.into("src/main/c"); // FIXME Assumes source in conventional location + it.eachFile(file -> { + file.setPath(project.relativePath(file.getFile())); + }); }); }); } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPlugin.java index a47e242..90c738f 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPlugin.java @@ -22,7 +22,9 @@ import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.DuplicatesStrategy; +import org.gradle.api.file.FileCollection; import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.tasks.bundling.Zip; @@ -60,18 +62,25 @@ public void execute(SourceSet sourceSet) { project.getTasks().getByName("hdvlSourcesArchive", task -> { Zip hdvlSourcesArchive = (Zip) task; hdvlSourcesArchive.from(svSourceSet.getSv(), it -> { - it.into("src/main/sv"); // FIXME Assumes source in conventional location + it.eachFile(file -> { + file.setPath(project.relativePath(file.getFile())); + }); }); - // FIXME Implement proper handling of SV private headers hdvlSourcesArchive.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE); - hdvlSourcesArchive.from(project.files("src/main/sv").getFiles(), it -> { - it.into("src/main/sv"); // FIXME Assumes source in conventional location + + // FIXME Implement proper handling of SV private headers + hdvlSourcesArchive.from(svSourceSet.getSv().getSourceDirectories().getElements().map(project::files), it -> { + it.eachFile(file -> { + file.setPath(project.relativePath(file.getFile())); + }); }); // FIXME Implement proper handling of SV exported headers - hdvlSourcesArchive.from(project.files("src/main/sv_headers").getFiles(), it -> { - it.into("src/main/sv_headers"); // FIXME Assumes source in conventional location + hdvlSourcesArchive.from(svSourceSet.getSvHeaders().getSourceDirectories().getElements().map(project::files), it -> { + it.eachFile(file -> { + file.setPath(project.relativePath(file.getFile())); + }); }); }); }