-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mixed-mode rework, allign flags with javabuilder, don't use temp dir …
…- declare class dir, reorganize source.
- Loading branch information
Showing
28 changed files
with
917 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
kotlin/workers/src/io/bazel/ruleskotlin/workers/CompileResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2018 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.bazel.ruleskotlin.workers; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
@FunctionalInterface | ||
public interface CompileResult { | ||
/** | ||
* The status of this operation. | ||
*/ | ||
default int status() { | ||
return 0; | ||
} | ||
|
||
default Optional<Exception> error() { | ||
return Optional.empty(); | ||
} | ||
|
||
default void propogateError(String message) throws RuntimeException { | ||
error().ifPresent(e -> { | ||
throw new RuntimeException(message, e); | ||
}); | ||
} | ||
|
||
static CompileResult just(final int status) { | ||
return new CompileResult() { | ||
@Override | ||
public int status() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public Integer render(Context ctx) { | ||
return status; | ||
} | ||
}; | ||
} | ||
|
||
static CompileResult error(final Exception error) { | ||
return new CompileResult() { | ||
@Override | ||
public int status() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public Optional<Exception> error() { | ||
return Optional.of(error); | ||
} | ||
|
||
@Override | ||
public Integer render(Context ctx) { | ||
throw new RuntimeException(error); | ||
} | ||
}; | ||
} | ||
|
||
static CompileResult deferred(final int status, Function<Context, Integer> renderer) { | ||
return new CompileResult() { | ||
@Override | ||
public int status() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public Integer render(Context ctx) { | ||
return renderer.apply(ctx); | ||
} | ||
}; | ||
} | ||
|
||
final class Meta extends io.bazel.ruleskotlin.workers.Meta<CompileResult> { | ||
public Meta(String id) { | ||
super(id); | ||
} | ||
|
||
public CompileResult run(final Context ctx, Function<Context, Integer> op) { | ||
CompileResult result; | ||
try { | ||
result = CompileResult.just(op.apply(ctx)); | ||
} catch (Exception e) { | ||
result = CompileResult.error(e); | ||
} | ||
return result; | ||
} | ||
|
||
public CompileResult runAndBind(final Context ctx, Function<Context, Integer> op) { | ||
CompileResult res = run(ctx, op); | ||
bind(ctx, res); | ||
return res; | ||
} | ||
|
||
public CompileResult runAndBind(final Context ctx, Supplier<Integer> op) { | ||
return runAndBind(ctx, (c) -> op.get()); | ||
} | ||
} | ||
|
||
/** | ||
* Materialise the output of the compile result. | ||
* | ||
* @return the new status of the compile operation, this shouldn't make a failing status pass, but it could fail a compile operation. | ||
*/ | ||
Integer render(Context ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
kotlin/workers/src/io/bazel/ruleskotlin/workers/JavaBuilderFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2018 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.bazel.ruleskotlin.workers; | ||
|
||
/** | ||
* Flags used by the java builder. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public enum JavaBuilderFlags { | ||
TARGET_LABEL("--target_label"), | ||
CLASSPATH("--classpath"), | ||
JAVAC_OPTS("--javacopts"), | ||
DEPENDENCIES("--dependencies"), | ||
DIRECT_DEPENDENCIES("--direct_dependencies"), | ||
DIRECT_DEPENDENCY("--direct_dependency"), | ||
INDIRECT_DEPENDENCY("--indirect_dependency"), | ||
STRICT_JAVA_DEPS("--strict_java_deps"), | ||
OUTPUT_DEPS_PROTO("--output_deps_proto"), | ||
DEPS_ARTIFACTS("--deps_artifacts"), | ||
REDUCE_CLASSPATH("--reduce_classpath"), | ||
SOURCEGEN_DIR("--sourcegendir"), | ||
GENERATED_SOURCES_OUTPUT("--generated_sources_output"), | ||
OUTPUT_MANIFEST_PROTO("--output_manifest_proto"), | ||
SOURCES("--sources"), | ||
SOURCE_ROOTS("--source_roots"), | ||
SOURCE_JARS("--source_jars"), | ||
SOURCE_PATH("--sourcepath"), | ||
BOOT_CLASSPATH("--bootclasspath"), | ||
PROCESS_PATH("--processorpath"), | ||
PROCESSORS("--processors"), | ||
EXT_CLASSPATH("--extclasspath"), | ||
EXT_DIR("--extdir"), | ||
OUTPUT("--output"), | ||
NATIVE_HEADER_OUTPUT("--native_header_output"), | ||
CLASSDIR("--classdir"), | ||
TEMPDIR("--tempdir"), | ||
GENDIR("--gendir"), | ||
POST_PROCESSOR("--post_processor"), | ||
COMPRESS_JAR("--compress_jar"), | ||
RULE_KIND("--rule_kind"), | ||
TEST_ONLY("--testonly"); | ||
|
||
public final String flag; | ||
|
||
JavaBuilderFlags(String flag) { | ||
this.flag = flag; | ||
} | ||
} |
Oops, something went wrong.