Skip to content

Commit

Permalink
Merge pull request #144 from tudortimi/handle-systemverilog-private-i…
Browse files Browse the repository at this point in the history
…ncdirs-in-published-hdvl-sources-archives

Handle SystemVerilog private incdirs in published HDVL sources archives
  • Loading branch information
tudortimi committed May 12, 2024
2 parents c165a17 + bbd4793 commit fca973e
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module some_project;
import some_published_dependency::*;

initial
do_stuff();

function automatic void do_stuff();
some_class o = new();
endfunction
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class some_class;
endclass
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package some_published_dependency;
`include "some_class.svh"
endpackage
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,27 @@ class SystemVerilogPluginSpec extends Specification {
entries[1].name == 'src/main/sv/main.sv'
}

def "can produce archive with private header"() {
File mainSv = testProjectDir.newFolder('src', 'main', 'sv')
new File(mainSv, "main.sv").createNewFile()
new File(mainSv, "private_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() == 3
entries[1].name == 'src/main/sv/main.sv'
entries[2].name == 'src/main/sv/private_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 @@ -1018,4 +1039,61 @@ class SystemVerilogPluginSpec extends Specification {
}
}

def "can consume source archive with private include 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 dependencyProjectPrivateHeader = new File(dependencyProjectBuildFile.parentFile, 'src/main/sv/dependency-project-private-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')
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

public interface HDVLCompileSpec {
Set<File> getSvSourceFiles();
Set<File> getSvPrivateIncludeDirs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@ public class DefaultHDVLCompileSpec implements HDVLCompileSpec {
@XmlJavaTypeAdapter(value=FileAdapter.class)
private final File[] svSourceFiles;

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

public DefaultHDVLCompileSpec(Set<File> svSourceFiles, Set<File> svPrivateIncludeDirs) {
this.svSourceFiles = svSourceFiles.toArray(new File[0]);
this.svPrivateIncludeDirs = svPrivateIncludeDirs.toArray(new File[0]);
}

// Needed for JAXB
@SuppressWarnings("unused")
private DefaultHDVLCompileSpec() {
this.svSourceFiles = new File[0];
this.svPrivateIncludeDirs = new File[0];
}

@Override
public Set<File> getSvSourceFiles() {
return new HashSet<>(Arrays.asList(svSourceFiles));
}

@Override
public Set<File> getSvPrivateIncludeDirs() {
return new HashSet<>(Arrays.asList(svPrivateIncludeDirs));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public class WriteCompileSpecFile extends DefaultTask {
private final RegularFileProperty destination;

private final ConfigurableFileCollection svSourceFiles;
private final ConfigurableFileCollection svSPrivateIncludeDirs;

public WriteCompileSpecFile() {
destination = getProject().getObjects().fileProperty();
svSourceFiles = getProject().getObjects().fileCollection();
svSPrivateIncludeDirs = getProject().getObjects().fileCollection();
}

@OutputFile
Expand All @@ -30,9 +32,17 @@ public ConfigurableFileCollection getSvSource() {
return svSourceFiles;
}

@InputFiles
@SkipWhenEmpty
@PathSensitive(PathSensitivity.ABSOLUTE)
public ConfigurableFileCollection getSvSPrivateIncludeDirs() {
return svSPrivateIncludeDirs;
}

@TaskAction
protected void generate() {
DefaultHDVLCompileSpec compileSpec = new DefaultHDVLCompileSpec(getSvSource().getFiles());
DefaultHDVLCompileSpec compileSpec = new DefaultHDVLCompileSpec(getSvSource().getFiles(),
svSPrivateIncludeDirs.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 @@ -42,6 +42,10 @@ private static DefaultHDVLCompileSpec getCompileSpec(File input) {
assert svSourceFile.isAbsolute() : "not absolute: " + svSourceFile;
assert svSourceFile.exists() : "doesn't exist: " + svSourceFile;
}
for (File svPrivateIncludeDir : result.getSvPrivateIncludeDirs()) {
assert svPrivateIncludeDir.isAbsolute() : "not absolute: " + svPrivateIncludeDir;
assert svPrivateIncludeDir.exists() : "doesn't exist: " + svPrivateIncludeDir;
}

return result;
} catch (JAXBException e) {
Expand All @@ -52,6 +56,8 @@ private static DefaultHDVLCompileSpec getCompileSpec(File input) {
private static void writeXrunArgsFile(File xrunArgsFile, HDVLCompileSpec compileSpec) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(xrunArgsFile, true))) {
writer.write("-makelib worklib\n");
for (File svPrivateIncludeDir: compileSpec.getSvPrivateIncludeDirs())
writer.write(" -incdir " + svPrivateIncludeDir + "\n");
for (File svSourceFile : compileSpec.getSvSourceFiles())
writer.write(" " + svSourceFile + "\n");
writer.write("-endlib\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.file.DuplicatesStrategy;
import org.gradle.api.internal.plugins.DslObject;
import org.gradle.api.tasks.bundling.Zip;

Expand Down Expand Up @@ -51,12 +52,19 @@ public void execute(SourceSet sourceSet) {
if (sourceSet.getName() == "main") {
project.getTasks().withType(WriteCompileSpecFile.class, task -> {
task.getSvSource().from(svSourceSet.getSv());
task.getSvSPrivateIncludeDirs().from(svSourceSet.getSv().getSourceDirectories());
});
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
});

// 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
});
});
}
}
Expand Down

0 comments on commit fca973e

Please sign in to comment.