Move google stuff to its own folder

This commit is contained in:
Christian Nieves
2022-08-15 17:06:33 +00:00
parent 8258bcc14c
commit 4cbe074ae0
11 changed files with 51 additions and 0 deletions

51
google/.blazerc Normal file
View File

@ -0,0 +1,51 @@
# Performance optimization flags (go/blaze-unleashed)
#
# Section of flags to improve build performance, especially for incremental
# builds, and that are either experimental or we can't easily change the
# defaults. DO NOT USE these flags for release builds.
#
# --nostamp: Disables stamping of binaries. Do not use for release builds, both for
# release to prod (go/buildhorizon) and for releases to corp (go/toolsearch)!
# The stamp is applied during linking, and is also applied if the binary is depended
# upon by e.g., an integration test. If the link or the integration test is
# expensive, then this is costly. You also don't get any forge caching with TAP or
# other devs, because the stamp contains your username.
# --workspace_status_command: If your build needs information about the
# client it runs in (CL synced to, etc.), dont use this flag. Do not use
# for release builds, both for release to prod (go/buildhorizon) and for releases
# to corp (go/toolsearch)!
# --experimental_spawn_scheduler: Run actions locally instead of remotely for
# incremental builds as long as enough resources are available to execute all
# runnable actions in parallel.
# --trim_test_configuration: Rollout is being tracked in b/65401043 and b/122499394.
# This flag prevents many situations where Blaze has to re-analyze before being able
# to build.
# --show_progress_rate_limit=1: Show at most one message per second (useful when working
# over SSH or Remote Desktop to reduce the amount of network traffic and screen
# updates).
# --order_output=no: By default, blaze query orders the outputs. This can be expensive,
# so this flag disables the ordering step.
build --nostamp
# build --workspace_status_command=/bin/true
# build --experimental_spawn_scheduler
build --trim_test_configuration
build --show_progress_rate_limit=1
# query --order_output=no
# --test_output / --test_summary obviously dont do anything for performance,
# keep them if you like what they do.
# test --test_output=errors --test_summary=detailed --build_tests_only
# In C++, failing tests will print a lot of noisy thread output. Use
# -undefok to allow other languages to ignore the
# -suppress_failure_output flag.
# Unfortunately, some test runners don't support --undefok, and therefore break when this is set.
# test --test_arg=--undefok=suppress_failure_output --test_arg=--suppress_failure_output
import %workspace%/java/com/google/android/gmscore/blaze/blazerc
build --config=gmscore_tap
test --config=gmscore_test
test --test_output=errors
#
# https://g3doc.corp.google.com/devtools/blaze/g3doc/faq.md?cl=head#BlazeOom
startup --host_jvm_args=-Xmx18G --host_jvm_args=-Xms18G

49
google/.hgrc Normal file
View File

@ -0,0 +1,49 @@
%include ~/hgshort/hgshort.hgrc
[ui]
editor = vim
paginate = never
merge = vimdiff
username = Christian Nieves <cnieves@google.com>
# graphnodetemplate = {label("graphnode.{graphnode}", graphnode)}
[extdiff]
cmd.meld = /usr/bin/meld
cmd.pmeld = /usr/bin/meld
[extensions]
unsupported.tree =
unsupported.alices =
extdiff =
color =
beautifygraph =
[alices]
findings.extra_args = --proxy
summarize.extra_args = --proxy
[merge-tools]
# meld.args = --auto-merge --label='incoming' $local --label='merged' $base --label='existing' $other -o $output
# https://www.mercurial-scm.org/wiki/MergingWithVim#More_Useful_3-Way_Diff
vimdiff.executable = vimdiff
vimdiff.args = -f -d $output -M $local $base $other -c "wincmd J" -c "set modifiable" -c "set write"
vimdiff.premerge = keep
[committemplate]
changeset = {desc}\n\n
HG: {extramsg}
HG: user: {author}\n{ifeq(p2rev, "-1", "",
"HG: branch merge\n")
}HG: branch '{branch}'\n{if(currentbookmark,
"HG: bookmark '{currentbookmark}'\n") }{subrepos %
"HG: subrepo {subrepo}\n" }
{splitlines(diff()) % 'HG: {line}\n'}
[alias]
whatsout = status -n --change .
whatsoutall = status --rev p4base --no-status
# unbranch = cp --forget --at-rev . $1
unbranch = !$HG uncommit --keep $1 && $HG forget $1 && $HG add $1 && $HG amend $1
[trainingwheels]
warn-head-paths=False

2
google/hgshort/OWNERS Normal file
View File

@ -0,0 +1,2 @@
parren
yurilev

7
google/hgshort/README.md Normal file
View File

@ -0,0 +1,7 @@
# hgshort - Single Letter Shorthands for Fig
hgshort makes it really easy to work with files and revisions in Fig. Use
**single letter** shorthand names, instead of long paths and hash codes.
Documentation can be found
[here](http://g3doc/experimental/fig_contrib/g3doc/hgshort).

21
google/hgshort/aliases.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# Creates the recommended alias definitions for hgshort when sourced.
HGSHORT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}}")" && pwd)"
alias hg="source $HGSHORT_DIR/hgshort.sh"
# There are two ways to customize:
# - define HGSHORT_CMDS_ADDITIONAL in your shell configuration to augment the
# following list.
# - define HGSHORT_CMDS directly in your shell configuration to override the
# following list.
if [[ -z "$HGSHORT_CMDS" ]]; then
HGSHORT_CMDS="$HGSHORT_CMDS_ADDITIONAL ls cat head tail mv cp rm chmod g4 diff merge patch meld vim emacs edit trim less more"
fi
# Doing the variable expansion with an 'echo' makes this compatible with zsh.
for c in $(echo "$HGSHORT_CMDS"); do
alias $c="source $HGSHORT_DIR/tobashargs.sh $c"
done

12
google/hgshort/hgd.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
HGSHORT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}}")" && pwd)"
source $HGSHORT_DIR/aliases.sh
cd $(hg hgd "$@")
CITC="${PWD#/google/src/cloud/$USER/}"
CITC="${CITC%/google3}"
echo "CitC $CITC"
hg l --color=always

View File

@ -0,0 +1,73 @@
# .hgrc for use with hgshort.
#
# Adds generated single letter revision and file shorthand names to the outputs
# of 'hg l/xl/ll' and 'hg status'.
#
# * For hg l/xl/ll, modifies the defaults set by:
# http://google3/devtools/piper/hgfission/client/config/google-ui-tweaks.rc
#
# * For hg status, overrides the default template (no extensible template
# available), but with one that looks the same.
#
# To use, add the following line to your ~/.hgrc:
# %include /google/src/head/depot/google3/experimental/fig_contrib/hgshort/hgshort.hgrc
#
# To make hg and other commands actually recognize the outputted shorthand
# names, follow go/hgshort#initial-setup.
#
# If you have already customized the outputs of 'hg l/xl/ll' or 'hg status',
# including this file would override them. Instead:
#
# * If you only aliased or added default arguments for 'hg status', add the
# following argument:
# --template=hgshort_status
#
# * If you customized the outputs themselves, copy the "extensions" and
# optionally the "color" sections and use:
#
# + hgshort_revision_shorthand — in your log templates.
# + hgshort_file_shorthand — in your status templates.
[extensions]
hgshort = /google/src/head/depot/google3/experimental/fig_contrib/hgshort/hgshort.py
[color]
# The color used for hgshort's single letter aliases.
hgshort.alias = red bold
[color256]
# The color used for hgshort's single letter aliases.
hgshort.alias = orange bold
##### hg l/xl/ll configuration #####
[templatealias]
# Get an alias for the current revision (node) with an uppercase letter.
hgshort_revision_shorthand='{hgshort(node,"A")}'
# Add the revision hgshort shorthand name to the output of 'hg l/xl/ll'.
google_compact_line_1_part_1 = '{hgshort_revision_shorthand}{google_compact_uniq_id}'
##### hg status configuration #####
[templatealias]
# Get an alias for the current file with a lowercase letter.
hgshort_file_shorthand='{hgshort(relpath(path),"a")}'
# Get the right built-in label (style) for the file's status.
# See http://screen/8A5ynkOdEED.png for an example output,
# and 'hg help status' for details.
hgshort_status_label(status) = '{ifeq(status, "?", "status.unknown", ifeq(status, "!", "status.deleted", get(dict(A="status.added", M="status.modified", R="status.removed", I="status.ignored", C="status.clean"), status)))}'
hgshort_status_line1 = '{hgshort_file_shorthand}{label(hgshort_status_label(status), '{status} {relpath(path)}')}'
hgshort_status_line2 = '{if(source, " {label("status.copied", " {relpath(source)}")}")}'
[templates]
# Add the hgshort file shorthand name to the output of 'hg status'.
# In conflict resolution mode, we get empty entries. Filter them out.
hgshort_status = '{if(path,"{separate("\n", hgshort_status_line1, hgshort_status_line2)}\n","")}'
[defaults]
# Override the default 'hg status' command, but keep -n working.
status = --template=hgshort_status
[alias]
# Override the default 'hg pstatus' template.
pstatus = pstatus --template=hgshort_status

82
google/hgshort/hgshort.py Normal file
View File

@ -0,0 +1,82 @@
'''"shorthand" template filter to emit bash shorthand accessors.'''
import os
import sys
from mercurial import error
from mercurial import i18n
from mercurial import registrar
from mercurial import templateutil
# dict of template built-in functions
funcs = {}
templatefunc = registrar.templatefunc(funcs)
templatefilter = registrar.templatefilter()
evalboolean = templateutil.evalboolean
evalstring = templateutil.evalstring
bashvarsfile = None
if sys.stdout.isatty():
if 'HGSHORT_BASH_VARS' in os.environ:
bashvarsfile = os.environ['HGSHORT_BASH_VARS']
nextaliasidbytype = {
b'a': ord(b'a'),
b'A': ord(b'A')}
def writealias(name, value):
if not bashvarsfile:
return
with open(bashvarsfile, 'a') as f:
f.write("export %s='%s'\n" % (name.decode('utf-8'), value.decode('utf-8')))
def nextaliaschar(aliastype):
if not bashvarsfile:
return None
aliasid = nextaliasidbytype[aliastype]
if aliasid < ord(aliastype) + 26:
nextaliasidbytype[aliastype] += 1
return chr(aliasid).encode('utf-8')
return None
def maybealias(value, aliastype):
"""Export as next bash alias and return id, or None."""
aliaschar = nextaliaschar(aliastype)
if not aliaschar: return None
writealias(b'hgshort%s' % aliaschar, value)
return aliaschar
@templatefilter(b'shorthand', intype=bytes)
def shorthand(text):
"""Export as next bash alias."""
if not bashvarsfile:
return b''
aliaschar = maybealias(text, b'a')
if not aliaschar:
return b' '
return b'%s ' % aliaschar
@templatefunc(
b'hgshort(text, aliastype)',
argspec=b'text aliastype',
requires={b'ui'})
def hgshort(context, mapping, args):
"""Export as next bash alias and return id, or None."""
if not bashvarsfile:
return b''
if b'text' not in args or b'aliastype' not in args:
raise error.ParseError(i18n._(b'hgshort() expects one to three arguments'))
text = evalstring(context, mapping, args[b'text'])
aliastype = evalstring(context, mapping, args[b'aliastype'])
aliaschar = maybealias(text, aliastype)
if not aliaschar:
return b' '
aliastext = b'%s ' % aliaschar
ui = context.resource(mapping, b'ui')
return ui.label(aliastext, b'hgshort.alias')

20
google/hgshort/hgshort.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
HGSHORT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}}")" && pwd)"
export HGSHORT_BASH_VARS="/tmp/hgshort-bash-vars-$$.sh"
export HGSHORT_BASH_ARGS="/tmp/hgshort-bash-args-$$.sh"
if [[ -f $HGSHORT_BASH_VARS ]]; then
\rm $HGSHORT_BASH_VARS # don't call rm to avoid alias loop
fi
HGSHORT_IS_HG=1 $HGSHORT_DIR/tobashargs.py "$@" > $HGSHORT_BASH_ARGS
xargs --null --arg-file=$HGSHORT_BASH_ARGS \
hg --config extensions.hgshort=$HGSHORT_DIR/hgshort.py
\rm $HGSHORT_BASH_ARGS # don't call rm to avoid alias loop
if [[ -f $HGSHORT_BASH_VARS ]]; then
source $HGSHORT_BASH_VARS
\rm $HGSHORT_BASH_VARS # don't call rm to avoid alias loop
fi

35
google/hgshort/tobashargs.py Executable file
View File

@ -0,0 +1,35 @@
#! /usr/bin/python3
"""Converts single letters like X to bash variable references like $hgshortX."""
import os
import re
import sys
# Shortands can be prefixed with an 'r', in which case several can be used in
# one argument. This is useful for revsets, for example: 'rA::rD'.
ALIAS_RE = re.compile(r'^([a-zA-Z])$|\br([A-Z])\b')
def subst(match):
char = match.group(1) or match.group(2)
var = 'hgshort%s' % char
if var in os.environ:
return os.getenv(var, '')
return match.group(0)
def substall(s):
return ALIAS_RE.sub(subst, s)
# Don't process first argument for `hg`, since it's often a command abbreviated
# to a single letter.
if 'HGSHORT_IS_HG' in os.environ:
args = sys.argv[1:2] + list(substall(a) for a in sys.argv[2:])
else:
args = list(substall(a) for a in sys.argv[1:])
# sys.stderr.write('%s\n' % repr(args)) # debug only
sys.stdout.write(chr(0).join(args))

11
google/hgshort/tobashargs.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
HGSHORT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}}")" && pwd)"
export HGSHORT_BASH_CMD="$1"
export HGSHORT_BASH_ARGS="/tmp/HGSHORT-bash-args-$$.sh"
shift
$HGSHORT_DIR/tobashargs.py "$@" > $HGSHORT_BASH_ARGS
xargs --null --arg-file=$HGSHORT_BASH_ARGS $HGSHORT_BASH_CMD
\rm $HGSHORT_BASH_ARGS # don't call rm to avoid alias loop