
    "                     8   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SS	KJr  SSKrS
rSrS
r\R,                  " S5      r\R,                  " S5      r\R,                  " S5      r " S S\
R4                  5      rS rS rS rg)z'Fingerprinting code for the Go runtime.    )absolute_import)division)unicode_literalsN)ext_runtime)config)log)filesgo)r
   customz>    env: flex
    runtime: {runtime}
    api_version: go1
    z?    .dockerignore
    Dockerfile
    .git
    .hg
    .svn
    z    # Dockerfile extending the generic Go image with application files for a
    # single application.
    FROM gcr.io/google_appengine/golang

    COPY . /go/src/app
    RUN go-wrapper install -tags appenginevm
    c                   0    \ rS rSrSrS rS rS rS rSr	g)	GoConfigurator=   z%Generates configuration for a Go app.c                     Xl         X l        g)zConstructor.

Args:
  path: (str) Root path of the source tree.
  params: (ext_runtime.Params) Parameters passed through to the
    fingerprinters.
N)rootparams)selfpathr   s      -lib/googlecloudsdk/api_lib/app/runtimes/go.py__init__GoConfigurator.__init__@   s     IK    c                    / nU R                   R                  (       d  [        R                  R	                  U R
                  S5      n[        R                  R                  U5      (       dZ  U R                   R                  (       a  SOSn[        R                  US9n[        R                  " SU5      nUR                  U5        U R                   R                  (       d  U R                   R                  (       Ga  [        R                  R	                  U R
                  [        R                  5      n[        R                  R                  U5      (       d:  [        R                  " [        R                  [        5      nUR                  U5        [        R                  R	                  U R
                  S5      n[        R                  R                  U5      (       d,  [        R                  " S[         5      n	UR                  U	5        U$ )Napp.yamlr   r
   )runtimez.dockerignore)r   appinfoosr   joinr   existsr   GO_APP_YAMLformatr   GeneratedFileappenddeployimages_config
DOCKERFILEDOCKERIGNORE)
r   all_config_filesapp_yaml_pathr   app_yaml_contentsapp_yamldockerfile_path
dockerfiledockerignore_pathdockerignores
             r   GetAllConfigFiles GoConfigurator.GetAllConfigFilesL   sU    ;;ggll499j9mWW^^M**"kk00(d'..w.?,,Z9JK){{T[[///TYY0H0HIoWW^^O,, ..}/G/G/9;

+ '',,tyy/BWW^^-.."00,O-r   c                 0   U R                   R                  (       a  [        R                  nO[        R                  R
                  nU R                  5       nSnU H(  nUR                  U R                  U5      (       d  M&  SnM*     U(       d  U" S5        U$ )zTGenerate config files for the module.

Returns:
  (bool) True if files were created
FTz8All config files already exist, not generating anything.)	r   r#   r   infostatusPrintr/   WriteTor   )r   notify	cfg_filescreatedcfg_files        r   GenerateConfigsGoConfigurator.GenerateConfigsg   su     {{xxfzzf&&(IG			$))V	,	,  GHNr   c                 ,   U R                   R                  (       a  [        R                  nO[        R                  R
                  nU R                  5       nU H1  nUR                  S:X  d  M  UR                  U R                  U5        M3     / nU H~  nUR                  S:w  d  M  [        R                  R                  [        R                  R                  U R                  UR                  5      5      (       a  Mm  UR                  U5        M     U$ )zkGenerate config files for the module.

Returns:
  list(ext_runtime.GeneratedFile) list of generated files.
r   )r   r#   r   r2   r3   r4   r/   filenamer5   r   r   r   r   r   r"   )r   r6   r7   r9   final_cfg_filesfs         r   GenerateConfigData!GoConfigurator.GenerateConfigData}   s     {{xxfzzf&&(I			j	(F+  O	
z	!"''..
'',,tyy!**
-+/ +/q!  r   )r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r/   r:   r@   __static_attributes__ r   r   r   r   =   s    -
6,r   r   c                 
   / n[         R                  " [        R                  " U 5      5       HR  u  p#n[        R
                  " US5       H1  nUR                  [         R                  R                  X%5      5        M3     MT     U$ )a(  Return list of '*.go' files under directory 'path'.

Note that os.walk by default performs a top-down search, so files higher in
the directory tree appear before others.

Args:
  path: (str) Application path.

Returns:
  ([str, ...]) List of full pathnames for all '*.go' files under 'path' dir.
z*.go)	r   walksix	text_typefnmatchfilterr"   r   r   )r   go_filesr   _	filenamesr=   s         r   _GoFilesrR      s_     (GGCMM$$78dyNN9f5oobggll423 6 9 
/r   c                 ,   [         R                  " U 5       nSnSnU HZ  n[        R                  " SU5      (       a  SnO[        R                  " SU5      (       a  SnU(       d  MI  U(       d  MR    SSS5        g   SSS5        g! , (       d  f       g= f)zCheck filename for 'package main' and 'func main'.

Args:
  filename: (str) File name to check.

Returns:
  (bool) True if main is found in filename.
Fz^package mainTz
^func mainN)r	   
FileReaderrematch)r=   r?   found_package
found_funclines        r   	_FindMainrZ      s     !QMJ	/4	(	(88L$''
	:: "!  " 
 "! 
s   AB'B0B:B
Bc                     [         R                  " S5        [        U 5      nU(       d  gSnU H.  n[        U5      (       d  M  [         R                  " SU5        Sn  O   U(       d  g[	        X5      $ )zCheck for a Go app.

Args:
  path: (str) Application path.
  params: (ext_runtime.Params) Parameters passed through to the
    fingerprinters.

Returns:
  (GoConfigurator or None) Returns a module if the path contains a
  Go app.
zChecking for Go.NFzFound Go main in %sT)r   r2   rR   rZ   r   )r   r   rO   
main_foundr?   s        r   Fingerprintr]      sf     (( d^(	 *a||	hh$a(j	 
 
		%%r   )rF   
__future__r   r   r   rM   r   rU   textwrapgae_ext_runtimer   !googlecloudsdk.api_lib.app.imagesr   r$   googlecloudsdk.corer   googlecloudsdk.core.utilr	   rK   NAMEALLOWED_RUNTIME_NAMESGO_RUNTIME_NAMEdedentr   r&   r%   Configuratorr   rR   rZ   r]   rH   r   r   <module>ri      s     . &  '  	 	  ' E # * 
 ( oo  	
    	 __  	
U[-- Up&,&r   