Exemplo n.º 1
0
  /* input defaults to reading the Fakefile, cwd to "." */
  public void make(InputStream input, File cwd, String[] args) {
    try {
      Parser parser = parse(input, cwd);

      // filter out variable definitions
      int firstArg = 0;
      while (firstArg < args.length && args[firstArg].indexOf('=') >= 0) firstArg++;

      List<String> list = null;
      if (args.length > firstArg) {
        list = new ArrayList<String>();
        for (int i = firstArg; i < args.length; i++) list.add(args[i]);
      }
      Rule all = parser.parseRules(list);

      for (int i = 0; i < firstArg; i++) {
        int equal = args[i].indexOf('=');
        parser.setVariable(args[i].substring(0, equal), args[i].substring(equal + 1));
      }

      for (Rule rule : all.getDependenciesRecursively())
        if (rule.getVarBool("rebuild")) rule.clean(false);

      String parallel = all.getVar("parallel");
      if (parallel != null) all.makeParallel(Integer.parseInt(parallel));
      else all.make();
    } catch (FakeException e) {
      System.err.println(e);
      System.exit(1);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
Exemplo n.º 2
0
  protected void fakeOrMake(
      File cwd,
      String directory,
      boolean verbose,
      boolean ignoreMissingFakefiles,
      String toolsPath,
      String classPath,
      String fallBackFakefile,
      File buildDir,
      String defaultTarget)
      throws FakeException {
    String[] files = new File(directory).list();
    if (files == null || files.length == 0) return;
    files = null;

    String fakeFile = cwd.getPath() + '/' + directory + '/' + Parser.path;
    boolean tryFake = new File(fakeFile).exists();
    if (!tryFake) {
      fakeFile = fallBackFakefile;
      tryFake = new File(fakeFile).exists();
    }
    if (ignoreMissingFakefiles && !tryFake && !(new File(directory + "/Makefile").exists())) {
      if (verbose) err.println("Ignore " + directory);
      return;
    }
    err.println(
        (tryFake ? "Build" : "Mak") + "ing in " + directory + (directory.endsWith("/") ? "" : "/"));

    try {
      if (tryFake) {
        // Try "Fake"
        Parser parser =
            parseFakefile(
                new File(cwd, directory),
                new File(fakeFile),
                verbose,
                toolsPath,
                classPath,
                buildDir);
        Rule all = parser.parseRules(null);
        if (defaultTarget != null) {
          Rule rule = all.getRule(defaultTarget);
          if (rule != null) all = rule;
        }
        all.make();
      } else
        // Try "make"
        execute(new String[] {"make"}, new File(directory), verbose);
    } catch (Exception e) {
      if (!(e instanceof FakeException)) e.printStackTrace();
      throw new FakeException((tryFake ? "Fake" : "make") + " failed: " + e);
    }
    err.println("Leaving " + directory);
  }