Exemple #1
0
 private StepExecutionResult executeMLBytecodeCompilation(
     ExecutionContext context,
     Path workingDirectory,
     ImmutableList<Path> sortedInput,
     ImmutableList.Builder<Path> linkerInputs)
     throws IOException, InterruptedException {
   MakeCleanDirectoryStep mkDir =
       new MakeCleanDirectoryStep(filesystem, ocamlContext.getCompileBytecodeOutputDir());
   StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
   if (!mkDirExecutionResult.isSuccess()) {
     return mkDirExecutionResult;
   }
   for (Path inputOutput : sortedInput) {
     String inputFileName = inputOutput.getFileName().toString();
     String outputFileName =
         inputFileName
             .replaceFirst(OCamlCompilables.OCAML_ML_REGEX, OCamlCompilables.OCAML_CMO)
             .replaceFirst(OCamlCompilables.OCAML_RE_REGEX, OCamlCompilables.OCAML_CMO)
             .replaceFirst(OCamlCompilables.OCAML_MLI_REGEX, OCamlCompilables.OCAML_CMI)
             .replaceFirst(OCamlCompilables.OCAML_REI_REGEX, OCamlCompilables.OCAML_CMI);
     Path outputPath = ocamlContext.getCompileBytecodeOutputDir().resolve(outputFileName);
     if (!outputFileName.endsWith(OCamlCompilables.OCAML_CMI)) {
       linkerInputs.add(outputPath);
     }
     final ImmutableList<String> compileFlags =
         getCompileFlags(/* isBytecode */ true, /* excludeDeps */ false);
     Step compileBytecodeStep =
         new OCamlMLCompileStep(
             workingDirectory,
             resolver,
             new OCamlMLCompileStep.Args(
                 filesystem.getAbsolutifier(),
                 cCompilerEnvironment,
                 cCompiler,
                 ocamlContext.getOcamlBytecodeCompiler().get(),
                 ocamlContext.getOCamlInteropIncludesDir(),
                 outputPath,
                 inputOutput,
                 compileFlags));
     StepExecutionResult compileExecutionResult = compileBytecodeStep.execute(context);
     if (!compileExecutionResult.isSuccess()) {
       return compileExecutionResult;
     }
   }
   return StepExecutionResult.SUCCESS;
 }
Exemple #2
0
 private int generateSources(ExecutionContext context, Path workingDirectory)
     throws IOException, InterruptedException {
   MakeCleanDirectoryStep mkDir =
       new MakeCleanDirectoryStep(filesystem, ocamlContext.getGeneratedSourceDir());
   int mkDirExitCode = mkDir.execute(context);
   if (mkDirExitCode != 0) {
     return mkDirExitCode;
   }
   for (SourcePath yaccSource : ocamlContext.getYaccInput()) {
     SourcePath output = ocamlContext.getYaccOutput(ImmutableSet.of(yaccSource)).get(0);
     OCamlYaccStep yaccStep =
         new OCamlYaccStep(
             workingDirectory,
             resolver,
             new OCamlYaccStep.Args(
                 ocamlContext.getYaccCompiler().get(),
                 resolver.getAbsolutePath(output),
                 resolver.getAbsolutePath(yaccSource)));
     int yaccExitCode = yaccStep.execute(context);
     if (yaccExitCode != 0) {
       return yaccExitCode;
     }
   }
   for (SourcePath lexSource : ocamlContext.getLexInput()) {
     SourcePath output = ocamlContext.getLexOutput(ImmutableSet.of(lexSource)).get(0);
     OCamlLexStep lexStep =
         new OCamlLexStep(
             workingDirectory,
             resolver,
             new OCamlLexStep.Args(
                 ocamlContext.getLexCompiler().get(),
                 resolver.getAbsolutePath(output),
                 resolver.getAbsolutePath(lexSource)));
     int lexExitCode = lexStep.execute(context);
     if (lexExitCode != 0) {
       return lexExitCode;
     }
   }
   return 0;
 }