Skip to content

Commit a665d20

Browse files
authored
Merge pull request #14 from googleads/client_libs_project
Support client libraries in a sub-directory under the project directory.
2 parents 3d12943 + 5a04673 commit a665d20

5 files changed

Lines changed: 30 additions & 48 deletions

File tree

GEMINI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This document outlines mandatory operational guidelines, constraints, and best p
5454
#### 2.2. File System
5555
- **Allowed Write Directories:** `saved_code/`, `saved_csv/`.
5656
- **Prohibited Write Directories:** Client library source directories (e.g., `google-ads-python/`, `google-ads-perl/`), `api_examples/`, or other project source directories unless explicitly instructed.
57+
- **NEVER** modify the files in `api_examples/`. If you need to use a file as a base for a request, copy the comments and put the file with modifications in `saved_code/`.
5758
- **All new or modified code MUST be written to the `saved_code/` directory.**
5859
- **File Naming:** Use descriptive, language-appropriate names (e.g., `get_campaign_metrics.py`, `GetCampaignMetrics.java`).
5960
- **Temporary Files:** Use the system's temporary directory.

setup.ps1

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,23 @@ param(
4343

4444
$ErrorActionPreference = "Stop"
4545

46+
# --- Project Directory Resolution ---
47+
# Determine the root directory of the current git repository.
48+
try {
49+
$ProjectDirAbs = git rev-parse --show-toplevel 2>$null
50+
if (-not $ProjectDirAbs) { throw "Not in a git repo" }
51+
# Normalize path separator
52+
$ProjectDirAbs = (Get-Item -LiteralPath $ProjectDirAbs).FullName
53+
}
54+
catch {
55+
Write-Error "ERROR: This script must be run from within the google-ads-api-developer-assistant git repository."
56+
exit 1
57+
}
58+
59+
Write-Host "Detected project root: $ProjectDirAbs"
60+
4661
# --- Configuration ---
47-
$DefaultParentDir = Join-Path $HOME "gaada"
62+
$DefaultParentDir = Join-Path $ProjectDirAbs "client_libs"
4863
$AllLangs = @("python", "php", "ruby", "java", "dotnet")
4964

5065
# Helper to get repo config
@@ -76,21 +91,6 @@ if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
7691
exit 1
7792
}
7893

79-
# --- Project Directory Resolution ---
80-
# Determine the root directory of the current git repository.
81-
try {
82-
$ProjectDirAbs = git rev-parse --show-toplevel 2>$null
83-
if (-not $ProjectDirAbs) { throw "Not in a git repo" }
84-
# Normalize path separator
85-
$ProjectDirAbs = (Get-Item -LiteralPath $ProjectDirAbs).FullName
86-
}
87-
catch {
88-
Write-Error "ERROR: This script must be run from within the google-ads-api-developer-assistant git repository."
89-
exit 1
90-
}
91-
92-
Write-Host "Detected project root: $ProjectDirAbs"
93-
9494
# --- Path Resolution and Validation ---
9595
Write-Host "Ensuring default library directory exists: $DefaultParentDir"
9696
if (-not (Test-Path -LiteralPath $DefaultParentDir)) {
@@ -117,13 +117,6 @@ foreach ($Lang in $AllLangs) {
117117
$Config = Get-RepoConfig -Lang $Lang
118118
$RepoPath = Join-Path $DefaultParentDir $Config.Name
119119
$LibPaths[$Lang] = $RepoPath
120-
121-
# Validation: check against project dir
122-
# Simple string check for subdirectory
123-
if ($RepoPath.StartsWith($ProjectDirAbs)) {
124-
Write-Error "ERROR: $Lang path ($RepoPath) cannot be a subdirectory of the project directory ($ProjectDirAbs)"
125-
exit 1
126-
}
127120
}
128121
}
129122

setup.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ err() {
3131
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
3232
}
3333

34+
# --- Project Directory Resolution ---
35+
# Determine the root directory of the current git repository.
36+
if ! PROJECT_DIR_ABS=$(git rev-parse --show-toplevel 2>/dev/null); then
37+
err "ERROR: This script must be run from within the google-ads-api-developer-assistant git repository."
38+
exit 1
39+
fi
40+
readonly PROJECT_DIR_ABS
41+
echo "Detected project root: ${PROJECT_DIR_ABS}"
42+
3443
# --- Configuration ---
35-
readonly DEFAULT_PARENT_DIR="${HOME}/gaada"
44+
readonly DEFAULT_PARENT_DIR="${PROJECT_DIR_ABS}/client_libs"
3645
readonly ALL_LANGS="python php ruby java dotnet"
3746

3847
# Helper functions for repo info (Replacing associative arrays for Bash 3.2 compatibility)
@@ -161,15 +170,6 @@ while [[ $# -gt 0 ]]; do
161170
esac
162171
done
163172

164-
# --- Project Directory Resolution ---
165-
# Determine the root directory of the current git repository.
166-
if ! PROJECT_DIR_ABS=$(git rev-parse --show-toplevel 2>/dev/null); then
167-
err "ERROR: This script must be run from within the google-ads-api-developer-assistant git repository."
168-
exit 1
169-
fi
170-
readonly PROJECT_DIR_ABS
171-
echo "Detected project root: ${PROJECT_DIR_ABS}"
172-
173173
# --- Language Selection Logic ---
174174
# If no languages selected, select all
175175
if [[ "${ANY_SELECTED}" == "false" ]]; then
@@ -219,11 +219,7 @@ for lang in $ALL_LANGS; do
219219
# Bash 3.2 compatible way to set variable by name
220220
eval "LIB_PATH_${lang}='${ABS_PATH}'"
221221

222-
# Validation: check against project dir
223-
if [[ "${ABS_PATH}" == "${PROJECT_DIR_ABS}"* ]]; then
224-
err "ERROR: ${lang} path (${ABS_PATH}) cannot be a subdirectory of the project directory (${PROJECT_DIR_ABS})"
225-
exit 1
226-
fi
222+
227223
fi
228224
done
229225

update.ps1

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ try {
194194

195195
$AbsLibPath = (Get-Item -LiteralPath $LibPath).FullName
196196

197-
# Skip if it is the project directory itself or a subdirectory of it
198-
if ($AbsLibPath.StartsWith($ProjectDirAbs)) {
199-
Write-Host "Skipping internal directory: $AbsLibPath"
200-
continue
201-
}
197+
202198

203199
# Check if it is a git repository
204200
if (-not (Test-Path -LiteralPath (Join-Path $AbsLibPath ".git"))) {

update.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,7 @@ for lib_path in "${INCLUDE_DIRS[@]}"; do
191191
continue
192192
fi
193193

194-
# Skip if it is the project directory itself or a subdirectory of it
195-
if [[ "${abs_lib_path}" == "${PROJECT_DIR_ABS}"* ]]; then
196-
echo "Skipping internal directory: ${abs_lib_path}"
197-
continue
198-
fi
194+
199195

200196
# Check if it is a git repository
201197
if [[ ! -d "${abs_lib_path}/.git" ]]; then

0 commit comments

Comments
 (0)