-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java 11 compilation works in rules_android
Should fix bazelbuild/bazel#17000 PiperOrigin-RevId: 693168450 Change-Id: Ib6b8cc922c793d5e0a31f138692e6f4d138731dd
- Loading branch information
1 parent
3f66a2d
commit 20c8e5b
Showing
16 changed files
with
647 additions
and
7 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
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
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,16 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_binary( | ||
name = "jar_to_module_info", | ||
embed = [":jar_to_module_info_lib"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_library( | ||
name = "jar_to_module_info_lib", | ||
importpath = "src/tools/jar_to_module_info/jar_to_module_info_lib", | ||
|
||
srcs = ["jar_to_module_info.go"], | ||
visibility = ["//visibility:private"], | ||
deps = ["@org_bitbucket_creachadair_stringset//:stringset"], | ||
) |
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,74 @@ | ||
// Copyright 2024 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. | ||
|
||
// Creates a module-info.java that exports all packages in the provided .jar file; see README.md | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"bitbucket.org/creachadair/stringset" | ||
"flag" | ||
"log" | ||
"os" | ||
) | ||
|
||
var ( | ||
inputPath = flag.String("input", "", "input jar path") | ||
outputPath = flag.String("output", "", "output modile-info path") | ||
) | ||
|
||
func writeFilePortable(ctx context.Context, filename string, data []byte) error { | ||
// A portable shim around the google-internal WriteFile() and the more commonly-used public version. | ||
// The Google-internal WriteFile() takes an additional Context object. | ||
return os.WriteFile(filename, data, 0o400) | ||
} | ||
|
||
func portableInit() { | ||
flag.Parse() | ||
} | ||
|
||
func main() { | ||
portableInit() | ||
reader, err := zip.OpenReader(*inputPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer reader.Close() | ||
packages := stringset.New() | ||
for _, f := range reader.File { | ||
if !strings.HasSuffix(f.Name, ".class") { | ||
continue | ||
} | ||
idx := strings.LastIndex(f.Name, "/") | ||
if idx == -1 { | ||
continue | ||
} | ||
packages.Add(f.Name[:idx]) | ||
} | ||
var output bytes.Buffer | ||
fmt.Fprintln(&output, "module java.base {") | ||
for _, p := range packages.Elements() { | ||
fmt.Fprintf(&output, " exports %s;\n", strings.Replace(p, "/", ".", -1)) | ||
} | ||
fmt.Fprintln(&output, "}") | ||
err = writeFilePortable(context.Background(), *outputPath, output.Bytes()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,16 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_binary( | ||
name = "split_core_jar", | ||
embed = [":split_core_jar_lib"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_library( | ||
name = "split_core_jar_lib", | ||
importpath = "src/tools/split_core_jar/split_core_jar_lib", | ||
|
||
srcs = ["split_core_jar.go"], | ||
visibility = ["//visibility:private"], | ||
deps = ["@org_bitbucket_creachadair_stringset//:stringset"], | ||
) |
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,168 @@ | ||
// Copyright 2024 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. | ||
|
||
// split_core_jar splits the given jar into a 'core' jar containing packages found in --core_jars, | ||
// and an 'auxiliary' jar containing the remaining packages | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"io" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"flag" | ||
"log" | ||
"bitbucket.org/creachadair/stringset" | ||
) | ||
|
||
var ( | ||
inputPath = flag.String("input", "", "input jar path") | ||
coreJarPathsStr = flag.String("core_jars", "", "input core jar paths, to filter against") | ||
outputCoreJarPath = flag.String("output_core_jar", "", "output core jar path") | ||
outputAuxiliaryJarPath = flag.String("output_auxiliary_jar", "", "output auxiliary jar path") | ||
exclusionsStr = flag.String("exclusions", "", "packages to skip in core jar") | ||
|
||
martinEpoch = parseTimeOrDie(time.RFC3339, "2010-01-01T00:00:00Z") | ||
) | ||
|
||
func parseTimeOrDie(layout, value string) time.Time { | ||
t, err := time.Parse(layout, value) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return t | ||
} | ||
|
||
type outputZip struct { | ||
f *os.File | ||
w *zip.Writer | ||
} | ||
|
||
func createOutputZip(p string) (*outputZip, error) { | ||
z := &outputZip{} | ||
var err error | ||
z.f, err = os.Create(p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
z.w = zip.NewWriter(z.f) | ||
return z, nil | ||
} | ||
|
||
func (z *outputZip) Close() error { | ||
err := z.w.Close() | ||
if err != nil { | ||
return err | ||
} | ||
err = z.f.Close() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (z *outputZip) Copy(f *zip.File) error { | ||
w, err := z.w.CreateHeader(&zip.FileHeader{Name: f.Name, Modified: martinEpoch}) | ||
if err != nil { | ||
return err | ||
} | ||
r, err := f.Open() | ||
if err != nil { | ||
return err | ||
} | ||
defer r.Close() | ||
_, err = io.Copy(w, r) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func portableInit() { | ||
flag.Parse() | ||
} | ||
|
||
func main() { | ||
portableInit() | ||
|
||
packages := stringset.New() | ||
coreJarPathsArr := strings.Split(*coreJarPathsStr, ",") | ||
coreJarPaths := &coreJarPathsArr | ||
exclusionsArr := strings.Split(*exclusionsStr, ",") | ||
exclusions := &exclusionsArr | ||
|
||
for _, coreJar := range *coreJarPaths { | ||
r, err := zip.OpenReader(coreJar) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer r.Close() | ||
for _, f := range r.File { | ||
if !strings.HasSuffix(f.Name, ".class") { | ||
continue | ||
} | ||
idx := strings.LastIndex(f.Name, "/") | ||
if idx == -1 { | ||
continue | ||
} | ||
packages.Add(f.Name[:idx]) | ||
} | ||
} | ||
|
||
packages.Discard(*exclusions...) | ||
|
||
reader, err := zip.OpenReader(*inputPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
coreJar, err := createOutputZip(*outputCoreJarPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
outputAuxiliaryJarPath, err := createOutputZip(*outputAuxiliaryJarPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
for _, f := range reader.File { | ||
if !strings.HasSuffix(f.Name, ".class") { | ||
continue | ||
} | ||
idx := strings.LastIndex(f.Name, "/") | ||
if idx == -1 { | ||
continue | ||
} | ||
if packages.Contains(f.Name[:idx]) { | ||
err := coreJar.Copy(f) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} else { | ||
err := outputAuxiliaryJarPath.Copy(f) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
} | ||
if err = coreJar.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
if err = outputAuxiliaryJarPath.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
if err = reader.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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
Oops, something went wrong.