Merge "Fix the tzdata update tools." into lmp-dev
This commit is contained in:
commit
6edf8985c1
@ -1,9 +1,6 @@
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import libcore.io.BufferIterator;
|
|
||||||
import libcore.util.ZoneInfo;
|
|
||||||
|
|
||||||
// usage: java ZoneCompiler <setup file> <data directory> <output directory> <tzdata version>
|
// usage: java ZoneCompiler <setup file> <data directory> <output directory> <tzdata version>
|
||||||
//
|
//
|
||||||
@ -27,66 +24,20 @@ import libcore.util.ZoneInfo;
|
|||||||
//
|
//
|
||||||
|
|
||||||
public class ZoneCompactor {
|
public class ZoneCompactor {
|
||||||
public static class ByteArrayBufferIteratorBE extends BufferIterator {
|
// Maximum number of characters in a zone name, including '\0' terminator.
|
||||||
private final byte[] bytes;
|
|
||||||
private int offset = 0;
|
|
||||||
|
|
||||||
public ByteArrayBufferIteratorBE(byte[] bytes) {
|
|
||||||
this.bytes = bytes;
|
|
||||||
this.offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void seek(int offset) {
|
|
||||||
this.offset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void skip(int byteCount) {
|
|
||||||
this.offset += byteCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readByteArray(byte[] dst, int dstOffset, int byteCount) {
|
|
||||||
System.arraycopy(bytes, offset, dst, dstOffset, byteCount);
|
|
||||||
offset += byteCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte readByte() {
|
|
||||||
return bytes[offset++];
|
|
||||||
}
|
|
||||||
|
|
||||||
public int readInt() {
|
|
||||||
return ((readByte() & 0xff) << 24) | ((readByte() & 0xff) << 16) | ((readByte() & 0xff) << 8) | (readByte() & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readIntArray(int[] dst, int dstOffset, int intCount) {
|
|
||||||
for (int i = 0; i < intCount; ++i) {
|
|
||||||
dst[dstOffset++] = readInt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public short readShort() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maximum number of characters in a zone name, including '\0' terminator
|
|
||||||
private static final int MAXNAME = 40;
|
private static final int MAXNAME = 40;
|
||||||
|
|
||||||
// Zone name synonyms
|
// Zone name synonyms.
|
||||||
private Map<String,String> links = new HashMap<String,String>();
|
private Map<String,String> links = new HashMap<String,String>();
|
||||||
|
|
||||||
// File starting bytes by zone name
|
// File offsets by zone name.
|
||||||
private Map<String,Integer> starts = new HashMap<String,Integer>();
|
private Map<String,Integer> offsets = new HashMap<String,Integer>();
|
||||||
|
|
||||||
// File lengths by zone name
|
// File lengths by zone name.
|
||||||
private Map<String,Integer> lengths = new HashMap<String,Integer>();
|
private Map<String,Integer> lengths = new HashMap<String,Integer>();
|
||||||
|
|
||||||
// Raw GMT offsets by zone name
|
// Concatenate the contents of 'inFile' onto 'out'.
|
||||||
private Map<String,Integer> offsets = new HashMap<String,Integer>();
|
private static void copyFile(File inFile, OutputStream out) throws Exception {
|
||||||
private int start = 0;
|
|
||||||
|
|
||||||
// Concatenate the contents of 'inFile' onto 'out'
|
|
||||||
// and return the contents as a byte array.
|
|
||||||
private static byte[] copyFile(File inFile, OutputStream out) throws Exception {
|
|
||||||
byte[] ret = new byte[0];
|
byte[] ret = new byte[0];
|
||||||
|
|
||||||
InputStream in = new FileInputStream(inFile);
|
InputStream in = new FileInputStream(inFile);
|
||||||
@ -104,14 +55,14 @@ public class ZoneCompactor {
|
|||||||
ret = nret;
|
ret = nret;
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZoneCompactor(String setupFile, String dataDirectory, String zoneTabFile, String outputDirectory, String version) throws Exception {
|
public ZoneCompactor(String setupFile, String dataDirectory, String zoneTabFile, String outputDirectory, String version) throws Exception {
|
||||||
// Read the setup file, and concatenate all the data.
|
// Read the setup file and concatenate all the data.
|
||||||
ByteArrayOutputStream allData = new ByteArrayOutputStream();
|
ByteArrayOutputStream allData = new ByteArrayOutputStream();
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(setupFile));
|
BufferedReader reader = new BufferedReader(new FileReader(setupFile));
|
||||||
String s;
|
String s;
|
||||||
|
int offset = 0;
|
||||||
while ((s = reader.readLine()) != null) {
|
while ((s = reader.readLine()) != null) {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
if (s.startsWith("Link")) {
|
if (s.startsWith("Link")) {
|
||||||
@ -125,16 +76,11 @@ public class ZoneCompactor {
|
|||||||
if (link == null) {
|
if (link == null) {
|
||||||
File sourceFile = new File(dataDirectory, s);
|
File sourceFile = new File(dataDirectory, s);
|
||||||
long length = sourceFile.length();
|
long length = sourceFile.length();
|
||||||
starts.put(s, start);
|
offsets.put(s, offset);
|
||||||
lengths.put(s, (int) length);
|
lengths.put(s, (int) length);
|
||||||
|
|
||||||
start += length;
|
offset += length;
|
||||||
byte[] data = copyFile(sourceFile, allData);
|
copyFile(sourceFile, allData);
|
||||||
|
|
||||||
BufferIterator it = new ByteArrayBufferIteratorBE(data);
|
|
||||||
TimeZone tz = ZoneInfo.makeTimeZone(s, it);
|
|
||||||
int gmtOffset = tz.getRawOffset();
|
|
||||||
offsets.put(s, gmtOffset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,9 +92,8 @@ public class ZoneCompactor {
|
|||||||
String from = it.next();
|
String from = it.next();
|
||||||
String to = links.get(from);
|
String to = links.get(from);
|
||||||
|
|
||||||
starts.put(from, starts.get(to));
|
|
||||||
lengths.put(from, lengths.get(to));
|
|
||||||
offsets.put(from, offsets.get(to));
|
offsets.put(from, offsets.get(to));
|
||||||
|
lengths.put(from, lengths.get(to));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create/truncate the destination file.
|
// Create/truncate the destination file.
|
||||||
@ -178,7 +123,7 @@ public class ZoneCompactor {
|
|||||||
|
|
||||||
// Write the index.
|
// Write the index.
|
||||||
ArrayList<String> sortedOlsonIds = new ArrayList<String>();
|
ArrayList<String> sortedOlsonIds = new ArrayList<String>();
|
||||||
sortedOlsonIds.addAll(starts.keySet());
|
sortedOlsonIds.addAll(offsets.keySet());
|
||||||
Collections.sort(sortedOlsonIds);
|
Collections.sort(sortedOlsonIds);
|
||||||
it = sortedOlsonIds.iterator();
|
it = sortedOlsonIds.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@ -188,9 +133,9 @@ public class ZoneCompactor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f.write(toAscii(new byte[MAXNAME], zoneName));
|
f.write(toAscii(new byte[MAXNAME], zoneName));
|
||||||
f.writeInt(starts.get(zoneName));
|
|
||||||
f.writeInt(lengths.get(zoneName));
|
|
||||||
f.writeInt(offsets.get(zoneName));
|
f.writeInt(offsets.get(zoneName));
|
||||||
|
f.writeInt(lengths.get(zoneName));
|
||||||
|
f.writeInt(0); // Used to be raw GMT offset. No longer used.
|
||||||
}
|
}
|
||||||
|
|
||||||
int data_offset = (int) f.getFilePointer();
|
int data_offset = (int) f.getFilePointer();
|
||||||
|
@ -115,7 +115,7 @@ def BuildIcuToolsAndData(data_filename):
|
|||||||
print 'Configuring ICU tools...'
|
print 'Configuring ICU tools...'
|
||||||
subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux'])
|
subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux'])
|
||||||
print 'Making ICU tools...'
|
print 'Making ICU tools...'
|
||||||
subprocess.check_call(['make', '-j6'])
|
subprocess.check_call(['make', '-j32'])
|
||||||
|
|
||||||
# Run the ICU tools.
|
# Run the ICU tools.
|
||||||
os.chdir('tools/tzcode')
|
os.chdir('tools/tzcode')
|
||||||
@ -169,11 +169,8 @@ def BuildBionicToolsAndData(data_filename):
|
|||||||
WriteSetupFile()
|
WriteSetupFile()
|
||||||
|
|
||||||
print 'Calling ZoneCompactor to update bionic to %s...' % new_version
|
print 'Calling ZoneCompactor to update bionic to %s...' % new_version
|
||||||
libcore_src_dir = '%s/../libcore/luni/src/main/java/' % bionic_dir
|
|
||||||
subprocess.check_call(['javac', '-d', '.',
|
subprocess.check_call(['javac', '-d', '.',
|
||||||
'%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir,
|
'%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir])
|
||||||
'%s/libcore/util/ZoneInfo.java' % libcore_src_dir,
|
|
||||||
'%s/libcore/io/BufferIterator.java' % libcore_src_dir])
|
|
||||||
subprocess.check_call(['java', 'ZoneCompactor',
|
subprocess.check_call(['java', 'ZoneCompactor',
|
||||||
'setup', 'data', 'extracted/zone.tab',
|
'setup', 'data', 'extracted/zone.tab',
|
||||||
bionic_libc_zoneinfo_dir, new_version])
|
bionic_libc_zoneinfo_dir, new_version])
|
||||||
|
@ -2210,7 +2210,7 @@ static int __bionic_open_tzdata_path(const char* path_prefix_variable, const cha
|
|||||||
char buf[NAME_LENGTH];
|
char buf[NAME_LENGTH];
|
||||||
int32_t start;
|
int32_t start;
|
||||||
int32_t length;
|
int32_t length;
|
||||||
int32_t raw_gmt_offset;
|
int32_t unused; // Was raw GMT offset; always 0 since tzdata2014f (L).
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t id_count = (ntohl(header.data_offset) - ntohl(header.index_offset)) / sizeof(struct index_entry_t);
|
size_t id_count = (ntohl(header.data_offset) - ntohl(header.index_offset)) / sizeof(struct index_entry_t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user