Skip to content

Commit

Permalink
Merge pull request #148 from tudortimi/clean-up-usages-of-hard-coded-…
Browse files Browse the repository at this point in the history
…paths-for-source-conventions

Clean up usages of hard coded paths of source conventions
  • Loading branch information
tudortimi authored Jun 1, 2024
2 parents 464c772 + fc16435 commit 41a37e5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 << """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
});
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit 41a37e5

Please sign in to comment.