summaryrefslogtreecommitdiffstats
path: root/tools/integrate/PushAndroidCode.java
blob: c0002f5c99aa9fc64956f35b67a8572d4b3de277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2009 Google Inc. All Rights Reserved.

import java.util.UUID;

/**
 * Copy the current Android sourcecode into Apache Harmony, where it can be
 * reviewed and submitted to their SVN. Only run this script after first merging
 * the latest harmony code into Android.
 */
public class PushAndroidCode {

    private final String androidPath;
    private final String harmonyPath;

    public PushAndroidCode(String androidPath, String harmonyPath) {
        this.androidPath = androidPath;
        this.harmonyPath = harmonyPath;
    }

    public void push(Module module) {
        Filesystem filesystem = new Filesystem();

        // copy android code to a temp directory that is laid out like Harmony
        String temp = "/tmp/" + UUID.randomUUID();
        filesystem.mkdir(temp);
        filesystem.copyContents(androidPath + "/" + module.path(),
                temp + "/" + module.path());
        for (MappedDirectory mappedDirectory : module.getMappedDirectories()) {
            filesystem.moveContents(
                    temp + "/" + mappedDirectory.gitPath(),
                    temp + "/" + mappedDirectory.svnPath());
        }

        // clobber files from harmony with their Android equivalents
        filesystem.copyContents(temp + "/" + module.path(),
                harmonyPath + "/" + module.path());
    }

    public static void main(String[] args) {
        if (args.length < 3) {
            printUsage();
            return;
        }

        String androidPath = args[0] + "/dalvik/libcore";
        String harmonyPath = args[1] + "/working_classlib/modules";

        // TODO: validate directories?
        
        Module[] modules = new Module[args.length - 2];
        for (int i = 0; i < modules.length; i++) {
            modules[i] = Module.VALUES.get(args[i+2]);
            if (modules[i] == null) {
                System.out.println("No such module: " + args[i+2]);
                return;
            }
        }

        PushAndroidCode pusher = new PushAndroidCode(androidPath, harmonyPath);
        for (Module module : modules) {
            pusher.push(module);
        }
    }

    private static void printUsage() {
        System.out.println("This tool will clobber Harmony's core libraries with Android's copy");
        System.out.println("so that a patch can be submitted upstream.");
        System.out.println();
        System.out.println("Usage: PushAndroidCode <android_root> <harmony_root> <module>...");
        System.out.println();
        System.out.println("  <android_root> is the android git client directory that contains dalvik");
        System.out.println("                 This should hold an up-to-date checkout of Android. The");
        System.out.println("                 target modules should also be up-to-date with respect to");
        System.out.println("                 Harmony; use the PullHarmonyCode tool first if necessary.");
        System.out.println();
        System.out.println("  <harmony_root> is the android client directory that contains working_classlib.");
        System.out.println("                 This should hold an up-to-date checkout of Harmony.");
        System.out.println();
        System.out.println("  <module> is one of " + Module.VALUES.keySet());
        System.out.println();
        System.out.println("Example usage:");
        System.out.println("  java -cp out/host/linux-x86/framework/integrate.jar PushAndroidCode \\");
        System.out.println("    /usr/local/google/jesse/clients/jessewilson_g1 \\");
        System.out.println("    /usr/local/google/jesse/clients/jessewilson_h0/trunk \\");
        System.out.println("    crypto");
    }
}