diff --git a/examples/using-published/some-project/src/main/sv/some_project.sv b/examples/using-published/some-project/src/main/sv/some_project.sv index 0dc52b3..a38db2d 100644 --- a/examples/using-published/some-project/src/main/sv/some_project.sv +++ b/examples/using-published/some-project/src/main/sv/some_project.sv @@ -1,10 +1,12 @@ module some_project; import some_published_dependency::*; + `include "some_published_dependency_macros.svh" initial do_stuff(); function automatic void do_stuff(); some_class o = new(); + `some_published_dependency_macro endfunction endmodule diff --git a/examples/using-published/some-published-dependency/src/main/sv_headers/some_published_dependency_macros.svh b/examples/using-published/some-published-dependency/src/main/sv_headers/some_published_dependency_macros.svh new file mode 100644 index 0000000..752a8ab --- /dev/null +++ b/examples/using-published/some-published-dependency/src/main/sv_headers/some_published_dependency_macros.svh @@ -0,0 +1,2 @@ +`define some_published_dependency_macro \ + $display("Hello from macro"); 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 602b5bc..bafa273 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginSpec.groovy @@ -945,6 +945,25 @@ class SystemVerilogPluginSpec extends Specification { entries[2].name == 'src/main/sv/private_header.svh' } + def "can produce archive with private header"() { + File mainSvHeaders = testProjectDir.newFolder('src', 'main', 'sv_headers') + new File(mainSvHeaders, "exported_header.svh").createNewFile() + + 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 == 'src/main/sv_headers/exported_header.svh' + } + def "can publishing metadata for archive"() { File mainSv = testProjectDir.newFolder('src', 'main', 'sv') new File(mainSv, "main.sv").createNewFile() @@ -1096,4 +1115,64 @@ class SystemVerilogPluginSpec extends Specification { line.contains('-incdir') && line.endsWith('src/main/sv') } } + + def "can consume source archive with exported header directory"() { + File dependencyProjectBuildFile = newStandardProject('dependency-project') + dependencyProjectBuildFile << """ + plugins { + id 'maven-publish' + } + + group = "org.example" + version = "1.0.0" + + publishing { + repositories { + maven { + name = 'dummy' + url = layout.buildDirectory.dir('dummy-repo') + } + } + } + """ + + File dependencyProjectExportedHeaderDir = new File(dependencyProjectBuildFile.parentFile, 'src/main/sv_headers') + dependencyProjectExportedHeaderDir.mkdir() + File dependencyProjectPrivateHeader = new File(dependencyProjectExportedHeaderDir, 'dependency-project-exported-header.svh') + dependencyProjectPrivateHeader.text = "dummy" + + GradleRunner.create() + .withProjectDir(dependencyProjectBuildFile.parentFile) + .withPluginClasspath() + .withArguments(':publish') + .build() + + File mainProjectBuildFile = newStandardProject('main-project') + mainProjectBuildFile << """ + dependencies { + compile 'org.example:dependency-project:1.0.0' + } + + repositories { + maven { + url = layout.projectDirectory.dir('../dependency-project/build/dummy-repo') + } + } + """ + + when: + def result = GradleRunner.create() + .withProjectDir(mainProjectBuildFile.parentFile) + .withPluginClasspath() + .withDebug(true) + .withArguments(':genFullXrunArgsFile') + .build() + + then: + def lines = new File(mainProjectBuildFile.parentFile, 'build/full_xrun_args.f').text.split("\n") + def xrunArgsForDependencyProject = new File(lines[0].split(/\s+/)[1]) + Files.lines(xrunArgsForDependencyProject.toPath()).anyMatch { line -> + line.contains('-incdir') && line.endsWith('src/main/sv_headers') + } + } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLCompileSpec.java b/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLCompileSpec.java index ae98bd9..d1aa451 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLCompileSpec.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLCompileSpec.java @@ -6,4 +6,5 @@ public interface HDVLCompileSpec { Set getSvSourceFiles(); Set getSvPrivateIncludeDirs(); + Set getSvExportedHeaderDirs(); } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/DefaultHDVLCompileSpec.java b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/DefaultHDVLCompileSpec.java index 88ab55c..d185774 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/DefaultHDVLCompileSpec.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/DefaultHDVLCompileSpec.java @@ -23,9 +23,15 @@ public class DefaultHDVLCompileSpec implements HDVLCompileSpec { @XmlJavaTypeAdapter(value=FileAdapter.class) private final File[] svPrivateIncludeDirs; - public DefaultHDVLCompileSpec(Set svSourceFiles, Set svPrivateIncludeDirs) { + @XmlElementWrapper + @XmlElement(name="svExportedHeaderDir") + @XmlJavaTypeAdapter(value=FileAdapter.class) + private final File[] svExportedHeaderDirs; + + public DefaultHDVLCompileSpec(Set svSourceFiles, Set svPrivateIncludeDirs, Set svExportedHeaderDirs) { this.svSourceFiles = svSourceFiles.toArray(new File[0]); this.svPrivateIncludeDirs = svPrivateIncludeDirs.toArray(new File[0]); + this.svExportedHeaderDirs = svExportedHeaderDirs.toArray(new File[0]); } // Needed for JAXB @@ -33,6 +39,7 @@ public DefaultHDVLCompileSpec(Set svSourceFiles, Set svPrivateInclud private DefaultHDVLCompileSpec() { this.svSourceFiles = new File[0]; this.svPrivateIncludeDirs = new File[0]; + this.svExportedHeaderDirs = new File[0]; } @Override @@ -44,4 +51,9 @@ public Set getSvSourceFiles() { public Set getSvPrivateIncludeDirs() { return new HashSet<>(Arrays.asList(svPrivateIncludeDirs)); } + + @Override + public Set getSvExportedHeaderDirs() { + return new HashSet<>(Arrays.asList(svExportedHeaderDirs)); + } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteCompileSpecFile.java b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteCompileSpecFile.java index 25cb135..2847c22 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteCompileSpecFile.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteCompileSpecFile.java @@ -13,11 +13,14 @@ public class WriteCompileSpecFile extends DefaultTask { private final ConfigurableFileCollection svSourceFiles; private final ConfigurableFileCollection svSPrivateIncludeDirs; + private final ConfigurableFileCollection svExportedHeaderDirs; + public WriteCompileSpecFile() { destination = getProject().getObjects().fileProperty(); svSourceFiles = getProject().getObjects().fileCollection(); svSPrivateIncludeDirs = getProject().getObjects().fileCollection(); + svExportedHeaderDirs = getProject().getObjects().fileCollection(); } @OutputFile @@ -39,10 +42,17 @@ public ConfigurableFileCollection getSvSPrivateIncludeDirs() { return svSPrivateIncludeDirs; } + @InputFiles + @SkipWhenEmpty + @PathSensitive(PathSensitivity.ABSOLUTE) + public ConfigurableFileCollection getSvExportedHeaderDirs() { + return svExportedHeaderDirs; + } + @TaskAction protected void generate() { DefaultHDVLCompileSpec compileSpec = new DefaultHDVLCompileSpec(getSvSource().getFiles(), - svSPrivateIncludeDirs.getFiles()); + svSPrivateIncludeDirs.getFiles(), svExportedHeaderDirs.getFiles()); try { JAXBContext jaxbContext = JAXBContext.newInstance(DefaultHDVLCompileSpec.class); Marshaller marshaller = jaxbContext.createMarshaller(); diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteXrunArgsFile.java b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteXrunArgsFile.java index 7608ebe..6aeebd7 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteXrunArgsFile.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/WriteXrunArgsFile.java @@ -46,6 +46,10 @@ private static DefaultHDVLCompileSpec getCompileSpec(File input) { assert svPrivateIncludeDir.isAbsolute() : "not absolute: " + svPrivateIncludeDir; assert svPrivateIncludeDir.exists() : "doesn't exist: " + svPrivateIncludeDir; } + for (File svExportedHeaderDir : result.getSvExportedHeaderDirs()) { + assert svExportedHeaderDir.isAbsolute() : "not absolute: " + svExportedHeaderDir; + assert svExportedHeaderDir.exists() : "doesn't exist: " + svExportedHeaderDir; + } return result; } catch (JAXBException e) { @@ -55,6 +59,8 @@ private static DefaultHDVLCompileSpec getCompileSpec(File input) { private static void writeXrunArgsFile(File xrunArgsFile, HDVLCompileSpec compileSpec) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(xrunArgsFile, true))) { + for (File svExportedHeaderDir: compileSpec.getSvExportedHeaderDirs()) + writer.write("-incdir " + svExportedHeaderDir + "\n"); writer.write("-makelib worklib\n"); for (File svPrivateIncludeDir: compileSpec.getSvPrivateIncludeDirs()) writer.write(" -incdir " + svPrivateIncludeDir + "\n"); 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 cb85ff1..c7ea562 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPlugin.java @@ -26,6 +26,8 @@ import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.tasks.bundling.Zip; +import java.io.File; + public class SystemVerilogPlugin implements Plugin { @Override @@ -53,6 +55,7 @@ public void execute(SourceSet sourceSet) { project.getTasks().withType(WriteCompileSpecFile.class, task -> { task.getSvSource().from(svSourceSet.getSv()); task.getSvSPrivateIncludeDirs().from(svSourceSet.getSv().getSourceDirectories()); + task.getSvExportedHeaderDirs().from(svSourceSet.getSvHeaders().getSourceDirectories().filter(File::exists)); }); project.getTasks().getByName("hdvlSourcesArchive", task -> { Zip hdvlSourcesArchive = (Zip) task; @@ -65,6 +68,11 @@ public void execute(SourceSet sourceSet) { 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 exported headers + hdvlSourcesArchive.from(project.files("src/main/sv_headers").getFiles(), it -> { + it.into("src/main/sv_headers"); // FIXME Assumes source in conventional location + }); }); } }