Skip to content

Commit

Permalink
MISC: extract canonicalize
Browse files Browse the repository at this point in the history
Signed-off-by: imkiva <imkiva@islovely.icu>
  • Loading branch information
imkiva committed Dec 1, 2021
1 parent 25ec642 commit ce306c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
9 changes: 4 additions & 5 deletions cli/src/main/java/org/aya/cli/library/LibraryCompiler.java
Expand Up @@ -32,9 +32,8 @@
* @author kiva
*/
public class LibraryCompiler {
final @NotNull LibraryOwner owner;
final @NotNull CachedModuleLoader<LibraryModuleLoader> moduleLoader;

private final @NotNull LibraryOwner owner;
private final @NotNull CachedModuleLoader<LibraryModuleLoader> moduleLoader;
private final @NotNull CountingReporter reporter;
private final @NotNull CompilerFlags flags;

Expand All @@ -50,8 +49,8 @@ public static int compile(@NotNull Reporter reporter, @NotNull CompilerFlags fla
reporter.reportString("Specified library root does not exist: " + libraryRoot);
return 1;
}
var config = LibraryConfigData.fromLibraryRoot(LibrarySource.canonicalize(libraryRoot));
var compiler = new LibraryCompiler(flags, DiskLibraryOwner.from(reporter,config), new LibraryModuleLoader.United());
var config = LibraryConfigData.fromLibraryRoot(FileUtil.canonicalize(libraryRoot));
var compiler = new LibraryCompiler(flags, DiskLibraryOwner.from(reporter, config), new LibraryModuleLoader.United());
return compiler.start();
}

Expand Down
11 changes: 1 addition & 10 deletions cli/src/main/java/org/aya/cli/library/source/LibrarySource.java
Expand Up @@ -12,7 +12,6 @@
import org.jetbrains.annotations.Debug;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects;
import java.util.stream.IntStream;
Expand All @@ -32,7 +31,7 @@ public record LibrarySource(
@NotNull Ref<ResolveInfo> resolveInfo
) {
public LibrarySource(@NotNull LibraryOwner owner, @NotNull Path file) {
this(owner, canonicalize(file), DynamicSeq.create(), new Ref<>(), new Ref<>());
this(owner, FileUtil.canonicalize(file), DynamicSeq.create(), new Ref<>(), new Ref<>());
}

public @NotNull ImmutableSeq<String> moduleName() {
Expand Down Expand Up @@ -63,12 +62,4 @@ public LibrarySource(@NotNull LibraryOwner owner, @NotNull Path file) {
@Override public int hashCode() {
return Objects.hash(owner.underlyingLibrary(), file);
}

public static @NotNull Path canonicalize(@NotNull Path path) {
try {
return path.toRealPath();
} catch (IOException ignored) {
return path.toAbsolutePath().normalize();
}
}
}
8 changes: 8 additions & 0 deletions tools/src/main/java/org/aya/util/FileUtil.java
Expand Up @@ -15,6 +15,14 @@
import java.util.Comparator;

public interface FileUtil {
static @NotNull Path canonicalize(@NotNull Path path) {
try {
return path.toRealPath();
} catch (IOException ignored) {
return path.toAbsolutePath().normalize();
}
}

static void deleteRecursively(@NotNull Path path) throws IOException {
if (!Files.exists(path)) return;
try (var walk = Files.walk(path)) {
Expand Down

0 comments on commit ce306c8

Please sign in to comment.