use of com.google.copybara.config.ConfigFile in project copybara by google.
the class PatchTransformation method patch.
public void patch(Console console, Path checkoutDir, @Nullable Path gitDir) throws ValidationException, InsideGitDirException {
try {
for (int i = 0; i < patches.size(); i++) {
ConfigFile patch = patches.get(i);
console.infoFmt("Applying patch %d/%d: '%s'.", i + 1, patches.size(), patch.path());
options.patch(checkoutDir, patch.readContentBytes(), excludedPaths, strip, reverse, gitDir);
}
} catch (IOException ioException) {
console.errorFmt("Error applying patch: %s", ioException.getMessage());
throw new ValidationException("Error applying patch.", ioException);
}
}
use of com.google.copybara.config.ConfigFile in project copybara by google.
the class QuiltTransformation method copyPatchConfigsToTmpDir.
private ImmutableList<Path> copyPatchConfigsToTmpDir() throws IOException {
ImmutableList.Builder<Path> builder = ImmutableList.builder();
Path patchDir = options.getGeneralOptions().getDirFactory().newTempDir("inputpatches");
for (ConfigFile patch : patchConfigs) {
// Uses String instead of Path for baseName, because patchDir's FileSystem may not match
// the default FileSystem from Paths.get().
String baseName = Paths.get(patch.path()).getFileName().toString();
Path patchFile = patchDir.resolve(baseName);
builder.add(patchFile);
try {
Files.write(patchFile, patch.readContentBytes());
} catch (CannotResolveLabel e) {
throw new IOException("Error reading input patch", e);
}
}
return builder.build();
}
use of com.google.copybara.config.ConfigFile in project copybara by google.
the class PatchModule method quiltApply.
@SuppressWarnings("unused")
@StarlarkMethod(name = "quilt_apply", doc = "A transformation that applies and updates patch files using Quilt. Compared to" + " `patch.apply`, this transformation supports updating the content of patch files" + " if they can be successfully applied with fuzz. The patch files must be included" + " in the destination_files glob in order to get updated. Underneath, Copybara" + " runs `quilt import; quilt push; quilt refresh` for each patch file in the" + " `series` file in order. Currently, all patch files and the `series` file must" + " reside in a \"patches\" sub-directory under the root directory containing the" + " migrated code. This means it has the limitation that the migrated code itself" + " cannot contain a directory with the name \"patches\".", parameters = { @Param(name = "series", named = true, positional = false, doc = "A file which contains a list of patches to apply. It is similar to the `series`" + " parameter in `patch.apply` transformation, and is required for Quilt." + " Patches listed in this file will be applied relative to the checkout dir," + " and the leading path component is stripped via the `-p1` flag. Currently" + " this file should be the `patches/series` file in the root directory" + " of the migrated code.") }, useStarlarkThread = true)
@Example(title = "Workflow to apply and update patches", before = "Suppose the destination repository's directory structure looks like:\n" + "```\n" + "source_root/BUILD\n" + "source_root/copy.bara.sky\n" + "source_root/migrated_file1\n" + "source_root/migrated_file2\n" + "source_root/patches/series\n" + "source_root/patches/patch1.patch\n" + "```\n" + "Then the transformations in `source_root/copy.bara.sky` should look like:", code = "[\n" + " patch.quilt_apply(series = \"patches/series\"),\n" + " core.move(\"\", \"source_root\"),\n" + "]", after = "In this example, `patch1.patch` is applied to `migrated_file1` and/or `migrated_file2`." + " `patch1.patch` itself will be updated during the migration if it is applied with" + " fuzz.")
@UsesFlags(PatchingOptions.class)
public QuiltTransformation quiltApply(String series, StarlarkThread thread) throws EvalException {
ImmutableList.Builder<ConfigFile> builder = ImmutableList.builder();
ConfigFile seriesFile = parseSeries(series, builder);
return new QuiltTransformation(seriesFile, builder.build(), patchingOptions, /*reverse=*/
false, thread.getCallerLocation());
}
Aggregations