Update oss scripts

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I57a29ead382a00c048ee5f26c1fc242c7dac1e2d
This commit is contained in:
Alexey Polyudov
2020-06-23 18:45:34 -07:00
parent e2a07376f4
commit 32828732ff
2 changed files with 59 additions and 4 deletions
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
# Copyright 2020 Google LLC
#
# 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
#
# https://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.
./oss.py --google3-filter --proto-lite-runtime ..
+42 -4
View File
@@ -1,7 +1,23 @@
#!/usr/bin/python3
# Copyright 2020 Google LLC
#
# 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
#
# https://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.
import argparse
import os
import re
import shutil
import sys
@@ -19,6 +35,8 @@ 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("\n")
headline_match=".*Copyright [0-9,\- ]+ Google.*"
MISSING = 0
HEADLINE = 1
PARTIAL = 2
@@ -26,20 +44,24 @@ FULL = 3
def has_copyright(lines, max_lookup=3):
pos = 0
result = MISSING
headline = re.compile(headline_match)
for line in lines:
pos += 1 # points to the next line
if line.find(copy_header[0]) >= 0:
if headline.match(line) != None:
result = HEADLINE
break
if pos > max_lookup:
return MISSING
result = HEADLINE
return result
for line in copy_header[1:]:
if pos >= len(lines):
return result
if lines[pos].find(line) < 0:
return result
else:
result = PARTIAL
pos += 1
return FULL
@@ -88,6 +110,9 @@ def post_process_oss_files(path, args):
else:
top_dirs = ["cpp", "proto"]
transforms = (
("::google3_proto_compat::MessageLite", "::google::protobuf::MessageLite"),
("third_party/webrtc/files/stable/", ""),
("webrtc/files/stable/", ""),
("third_party/", ""),
("location/nearby/connections/core_v2", "core_v2"),
("location/nearby/connections/core", "core"),
@@ -105,6 +130,7 @@ def post_process_oss_files(path, args):
("_portable_proto.pb.h", ".pb.h"),
(".proto.h", ".pb.h"),
)
for root, dirs, files in os.walk(path):
if top_level and top_dirs:
# we must convert cpp/ and proto/ subtrees.
@@ -123,6 +149,8 @@ def post_process_oss_files(path, args):
lines=[]
google3_ignore = False
with open(fname, "r") as f:
add_proto_lite_runtime = args.proto_lite_runtime and fname.endswith(".proto")
for line in f:
orig = line
@@ -147,6 +175,14 @@ def post_process_oss_files(path, args):
if google3_ignore:
modified = True
continue
if add_proto_lite_runtime and line.startswith("option "):
if not line.startswith("option optimize_for = LITE_RUNTIME"):
lines.append("option optimize_for = LITE_RUNTIME;\n")
modified = True
# LITE_RUNTIME should be added only once per file.
add_proto_lite_runtime = False
lines.append(line)
if args.fix_oss_headers:
@@ -156,6 +192,7 @@ def post_process_oss_files(path, args):
prefix, offset = options
lines = add_copyright(lines, prefix, offset)
modified = True
if modified:
with open(fname, "w") as f:
for line in lines:
@@ -176,6 +213,7 @@ def main():
parser.add_argument('--no-copy', action='store_true', default=False)
parser.add_argument('--no-subst', action='store_true', default=False)
parser.add_argument('--no-recurse', action='store_true', default=False)
parser.add_argument('--proto-lite-runtime', action='store_true', default=False)
args = parser.parse_args()
if args.google3_filter:
print("google3-specific code will be removed")