aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/packages/util/MockJ2ObjcSupport.java
blob: 54bb248c9ebbd6c2f2f7d224c8c32f1be022845d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2017 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 com.google.devtools.build.lib.packages.util;

import com.google.devtools.build.lib.testutil.TestConstants;
import java.io.IOException;

/**
 * Creates mock BUILD files required for J2Objc.
 */
public final class MockJ2ObjcSupport {
  /**
   * Setup the support for building with J2ObjC.
   */
  public static void setup(MockToolsConfig config) throws IOException {
    config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/jre_emul.jar");
    config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/jre.h");
    config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/jre.m");
    config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/runtime.h");
    config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/runtime.m");
    config.create(
        TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/proto_plugin_binary");
    config.create(
        TestConstants.TOOLS_REPOSITORY_SCRATCH + "third_party/java/j2objc/BUILD",
        "package(default_visibility=['//visibility:public'])",
        "licenses(['notice'])",
        "",
        "exports_files(['jre_emul.jar'])",
        "",
        "objc_library(",
        "    name = 'jre_emul_lib',",
        "    hdrs = ['jre_emul.h'],",
        "    srcs = ['jre_emul.m'],",
        "    deps = [':jre_core_lib', ':jre_io_lib'],",
        "    tags = ['j2objc_jre_lib'])",
        "",
        "objc_library(",
        "    name = 'jre_core_lib',",
        "    hdrs = ['jre_core.h'],",
        "    srcs = ['jre_core.m'],",
        "    tags = ['j2objc_jre_lib'])",
        "",
        "objc_library(",
        "    name = 'jre_io_lib',",
        "    hdrs = ['jre_io.h'],",
        "    srcs = ['jre_io.m'],",
        "    deps = [':jre_core_lib'],",
        "    tags = ['j2objc_jre_lib'])",
        "",
        "objc_library(",
        "    name = 'proto_runtime',",
        "    hdrs = ['runtime.h'],",
        "    srcs = ['runtime.m'])",
        "",
        "filegroup(",
        "    name = 'proto_plugin',",
        "    srcs = ['proto_plugin_binary'])");

    config.create(
        TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/BUILD",
        "package(default_visibility=['//visibility:public'])",
        "licenses(['notice'])",
        "filegroup(",
        "    name = 'j2objc_wrapper',",
        "    srcs = ['j2objc_wrapper.py'])",
        "filegroup(",
        "    name = 'j2objc_header_map',",
        "    srcs = ['j2objc_header_map.py'])",
        "proto_lang_toolchain(",
        "    name = 'j2objc_proto_toolchain',",
        "    blacklisted_protos = [':j2objc_proto_blacklist'],",
        "    command_line = '--PLUGIN_j2objc_out=file_dir_mapping,generate_class_mappings:$(OUT)',",
        "    visibility = ['//visibility:public'],",
        "    plugin = '//third_party/java/j2objc:proto_plugin',",
        "    runtime = '//third_party/java/j2objc:proto_runtime',",
        ")",
        "exports_files(['j2objc_deploy.jar'])",
        "filegroup(",
        "    name = 'j2objc_proto_blacklist',",
        "    srcs = [",
        "        '" + TestConstants.TOOLS_REPOSITORY + "//tools/j2objc/proto:blacklisted.proto'",
        "    ])");

    config.create(
        TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/proto/BUILD",
        "package(default_visibility=['//visibility:public'])",
        "proto_library(name = 'blacklisted',",
        "              srcs = ['blacklisted.proto'])");

    config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/proto/blacklisted.proto");

    if (config.isRealFileSystem()) {
      config.linkTool(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/j2objc_deploy.jar");
      config.linkTool(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/j2objc_wrapper.py");
      config.linkTool(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/j2objc_header_map.py");
    } else {
      config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/j2objc_deploy.jar");
      config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/j2objc_wrapper.py");
      config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/j2objc/j2objc_header_map.py");
    }
  }
}