Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] SymbolicLinkPreservingUntarTransform fails on Windows #1433

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@

import org.opensearch.gradle.EmptyDirTask;
import org.opensearch.gradle.tar.SymbolicLinkPreservingTar;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.AbstractCopyTask;
import org.gradle.api.tasks.Sync;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.api.tasks.bundling.Compression;
import org.gradle.api.tasks.bundling.Zip;

import org.gradle.internal.os.OperatingSystem;
import java.io.File;

import static org.opensearch.gradle.util.Util.capitalize;
Expand All @@ -66,6 +70,7 @@
* 4. Having per-distribution sub-projects means we can build them in parallel.
*/
public class InternalDistributionArchiveSetupPlugin implements Plugin<Project> {
private static final Logger LOGGER = Logging.getLogger(InternalDistributionArchiveSetupPlugin.class);

public static final String DEFAULT_CONFIGURATION_NAME = "default";
public static final String EXTRACTED_CONFIGURATION_NAME = "extracted";
Expand All @@ -80,16 +85,39 @@ public void apply(Project project) {
configureTarDefaults(project);
}

private Action<Task> configure(String name) {
return (Task task) -> task.onlyIf(s -> {
if (OperatingSystem.current().isWindows()) {
// On Windows, include only Windows distributions and integTestZip
final String nameLowerCased = name.toLowerCase();
final boolean skip = !(nameLowerCased.contains("windows") || nameLowerCased.contains("integtest"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gross, but I will take it

Copy link
Collaborator Author

@reta reta Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to handle it better, we have only compound name like freebsdTar, linuxArm64Tar, ... , to make it a bit cleaner we could skip integtestZip fe (I don't think this is a big deal), what do you think?

final boolean skip = !nameLowerCased.contains("windows");


if (skip) {
LOGGER.info("Skipping task " + name + " since it does not match current OS platform");
}

return !skip;
} else {
return true;
}
});
}

private void registerAndConfigureDistributionArchivesExtension(Project project) {
container = project.container(DistributionArchive.class, name -> {
var subProjectDir = archiveToSubprojectName(name);
var copyDistributionTaskName = "build" + capitalize(name.substring(0, name.length() - 3));
TaskContainer tasks = project.getTasks();
var explodedDist = tasks.register(copyDistributionTaskName, Sync.class, sync -> sync.into(subProjectDir + "/build/install/"));
explodedDist.configure(configure(name));
var archiveTaskName = "build" + capitalize(name);
return name.endsWith("Tar")
? new DistributionArchive(tasks.register(archiveTaskName, SymbolicLinkPreservingTar.class), explodedDist, name)
: new DistributionArchive(tasks.register(archiveTaskName, Zip.class), explodedDist, name);

var archiveTask = name.endsWith("Tar")
? tasks.register(archiveTaskName, SymbolicLinkPreservingTar.class)
: tasks.register(archiveTaskName, Zip.class);
archiveTask.configure(configure(name));

return new DistributionArchive(archiveTask, explodedDist, name);
});
// Each defined distribution archive is linked to a subproject.
// A distribution archive definition not matching a sub project will result in build failure.
Expand Down
6 changes: 4 additions & 2 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import org.opensearch.gradle.VersionProperties
import org.opensearch.gradle.docker.DockerBuildTask
import org.opensearch.gradle.info.BuildParams
import org.opensearch.gradle.testfixtures.TestFixturesPlugin
import org.gradle.internal.os.OperatingSystem

apply plugin: 'opensearch.standalone-rest-test'
apply plugin: 'opensearch.test.fixtures'
apply plugin: 'opensearch.internal-distribution-download'
Expand Down Expand Up @@ -183,7 +185,7 @@ void addBuildDockerImage(Architecture architecture, DockerBase base) {

final TaskProvider<DockerBuildTask> buildDockerImageTask =
tasks.register(taskName("build", architecture, base, "DockerImage"), DockerBuildTask) {
onlyIf { Architecture.current() == architecture }
onlyIf { Architecture.current() == architecture && !OperatingSystem.current().isWindows() }
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", architecture, base, "DockerContext"))
dependsOn(copyContextTask)
dockerContext.fileProvider(copyContextTask.map { it.destinationDir })
Expand Down Expand Up @@ -246,7 +248,7 @@ subprojects { Project subProject ->
"opensearch:test"

dependsOn(parent.path + ":" + buildTaskName)
onlyIf { Architecture.current() == architecture }
onlyIf { Architecture.current() == architecture && !OperatingSystem.current().isWindows()}
}

artifacts.add('default', file(tarFile)) {
Expand Down