mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Update oss scripts
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I57a29ead382a00c048ee5f26c1fc242c7dac1e2d
This commit is contained in:
Executable
+17
@@ -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
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user