Skip to content

Commit

Permalink
Merge pull request #145 from tudortimi/handle-systemverilog-exported-…
Browse files Browse the repository at this point in the history
…header-dirs-in-published-hdvl-sources-archives

Handle SystemVerilog exported header dirs in published HDVL sources archives
  • Loading branch information
tudortimi authored May 26, 2024
2 parents fca973e + 21dca8a commit 0b66a18
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`define some_published_dependency_macro \
$display("Hello from macro");
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
public interface HDVLCompileSpec {
Set<File> getSvSourceFiles();
Set<File> getSvPrivateIncludeDirs();
Set<File> getSvExportedHeaderDirs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ public class DefaultHDVLCompileSpec implements HDVLCompileSpec {
@XmlJavaTypeAdapter(value=FileAdapter.class)
private final File[] svPrivateIncludeDirs;

public DefaultHDVLCompileSpec(Set<File> svSourceFiles, Set<File> svPrivateIncludeDirs) {
@XmlElementWrapper
@XmlElement(name="svExportedHeaderDir")
@XmlJavaTypeAdapter(value=FileAdapter.class)
private final File[] svExportedHeaderDirs;

public DefaultHDVLCompileSpec(Set<File> svSourceFiles, Set<File> svPrivateIncludeDirs, Set<File> 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
@SuppressWarnings("unused")
private DefaultHDVLCompileSpec() {
this.svSourceFiles = new File[0];
this.svPrivateIncludeDirs = new File[0];
this.svExportedHeaderDirs = new File[0];
}

@Override
Expand All @@ -44,4 +51,9 @@ public Set<File> getSvSourceFiles() {
public Set<File> getSvPrivateIncludeDirs() {
return new HashSet<>(Arrays.asList(svPrivateIncludeDirs));
}

@Override
public Set<File> getSvExportedHeaderDirs() {
return new HashSet<>(Arrays.asList(svExportedHeaderDirs));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {

@Override
Expand Down Expand Up @@ -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;
Expand All @@ -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
});
});
}
}
Expand Down

0 comments on commit 0b66a18

Please sign in to comment.