Skip to content

Commit 50e57ac

Browse files
authored
Parameterize (#859)
* feat(build): Parameterize binary names in build scripts - Add CHAT_BINARY_BRANCH and CLI_BINARY_NAME_MINIMAL to const.py - Import CHAT_BINARY_BRANCH and TAURI_PRODUCT_NAME in build.py - Replace hardcoded 'qchat' with CHAT_BINARY_NAME constant - Replace hardcoded 'q_desktop' with TAURI_PRODUCT_NAME constant - Replace hardcoded 'q_cli' with CLI_PACKAGE_NAME constant - Replace hardcoded 'prod' with CHAT_BINARY_BRANCH constant - Update comments to use generic binary name placeholders * feat(build): Parameterize manifest.py with binary name constants - Import APP_NAME, CLI_BINARY_NAME, PTY_BINARY_NAME, CHAT_BINARY_NAME - Replace hardcoded 'Amazon Q.app' with f-string using APP_NAME - Replace hardcoded binary paths and identifiers with constants * feat(build): Update qchatbuild.py comments to use generic placeholders - Replace hardcoded 'qchat' in comments with {chat_binary} placeholder * feat(build): Update qchatmain.py description to be generic - Replace 'qchat binary' with 'chat binary' in argparse description * feat(rust): Parameterize hardcoded qchat.log references - Import CHAT_BINARY_NAME in chat-cli/src/logging.rs - Import CHAT_BINARY_NAME in fig_log/src/lib.rs - Import CHAT_BINARY_NAME in chat-cli/src/cli/mod.rs - Replace hardcoded 'qchat.log' with format string using CHAT_BINARY_NAME * feat(bundle): Parameterize binary names in install scripts - Add CLI_BINARY_NAME, CHAT_BINARY_NAME, PTY_BINARY_NAME variables to bundle/linux/install.sh - Replace hardcoded binary names with variables in install commands - Add DESKTOP_BINARY_NAME variable to scripts/install.sh - Replace hardcoded 'q_desktop' with DESKTOP_BINARY_NAME variable * fix(shell): Add shellcheck SC2329 disable directives - Add SC2329 to bash-preexec.sh __bp_adjust_histcontrol function - Add SC2329 disable before override function in shell integration generator - Add cfg_attr to suppress dead_code warning on Windows for list_profiles_blocking - Regenerate test snapshots with updated shellcheck directives SC2329 warns about functions defined after being called, which is intentional in our bash-preexec override pattern. 🤖 Assisted by Amazon Q Developer
1 parent 8cd1cc5 commit 50e57ac

File tree

17 files changed

+68
-46
lines changed

17 files changed

+68
-46
lines changed

build-scripts/build.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from importlib import import_module
3737
from const import (
3838
APP_NAME,
39+
CHAT_BINARY_BRANCH,
3940
CHAT_BINARY_NAME,
4041
CHAT_PACKAGE_NAME,
4142
CLI_BINARY_NAME,
@@ -51,6 +52,7 @@
5152
MACOS_BUNDLE_ID,
5253
PTY_BINARY_NAME,
5354
PTY_PACKAGE_NAME,
55+
TAURI_PRODUCT_NAME,
5456
URL_SCHEMA,
5557
)
5658

@@ -179,7 +181,7 @@ def fetch_chat_bin(chat_build_bucket_name: str | None, chat_download_role_arn: s
179181
warn("missing required chat arguments, creating dummy binary")
180182
dummy_dir = BUILD_DIR / "dummy_chat"
181183
dummy_dir.mkdir(exist_ok=True)
182-
dummy_path = dummy_dir / f"qchat-{get_target_triple()}"
184+
dummy_path = dummy_dir / f"{CHAT_BINARY_NAME}-{get_target_triple()}"
183185
dummy_path.write_text("#!/usr/bin/env sh\n\necho dummy chat binary\n")
184186
set_executable(dummy_path)
185187
return dummy_path
@@ -205,21 +207,21 @@ def fetch_chat_bin(chat_build_bucket_name: str | None, chat_download_role_arn: s
205207
)
206208

207209
# The path to the download should be:
208-
# BUILD_BUCKET/prod/latest/{target}/qchat.zip
210+
# BUILD_BUCKET/{CHAT_BINARY_BRANCH}/latest/{target}/{CHAT_BINARY_NAME}.zip
209211
target = get_target_triple()
210-
chat_bucket_path = f"prod/latest/{target}/qchat.zip"
212+
chat_bucket_path = f"{CHAT_BINARY_BRANCH}/latest/{target}/{CHAT_BINARY_NAME}.zip"
211213
chat_dl_dir = BUILD_DIR / "chat_download"
212214
chat_dl_dir.mkdir(exist_ok=True)
213-
chat_dl_path = chat_dl_dir / "qchat.zip"
214-
info(f"Downloading qchat zip from bucket: {chat_bucket_path} and path: {chat_bucket_path}")
215+
chat_dl_path = chat_dl_dir / f"{CHAT_BINARY_NAME}.zip"
216+
info(f"Downloading {CHAT_BINARY_NAME} zip from bucket: {chat_bucket_path} and path: {chat_bucket_path}")
215217
s3.download_file(chat_build_bucket_name, chat_bucket_path, chat_dl_path)
216218

217219
# unzip and return the path to the contained binary
218220
run_cmd(["unzip", "-o", chat_dl_path, "-d", chat_dl_dir])
219221

220222
# Append target triple, as expected by tauri cli.
221-
chat_path = chat_dl_dir / f"qchat-{target}"
222-
(chat_dl_dir / "qchat").rename(chat_path)
223+
chat_path = chat_dl_dir / f"{CHAT_BINARY_NAME}-{target}"
224+
(chat_dl_dir / CHAT_BINARY_NAME).rename(chat_path)
223225
return chat_path
224226

225227

@@ -341,7 +343,7 @@ def build_macos_desktop_app(
341343
manifest_path.unlink(missing_ok=True)
342344
tauri_config_path.unlink(missing_ok=True)
343345

344-
target_bundle = pathlib.Path(f"target/{target}/release/bundle/macos/q_desktop.app")
346+
target_bundle = pathlib.Path(f"target/{target}/release/bundle/macos/{TAURI_PRODUCT_NAME}.app")
345347
app_path = BUILD_DIR / f"{APP_NAME}.app"
346348
shutil.rmtree(app_path, ignore_errors=True)
347349
shutil.copytree(target_bundle, app_path)
@@ -466,9 +468,9 @@ def build_linux_minimal(cli_path: pathlib.Path, pty_path: pathlib.Path, chat_pat
466468
Creates tar.gz, tar.xz, tar.zst, and zip archives under `BUILD_DIR`.
467469
468470
Each archive has the following structure:
469-
- archive/bin/q
470-
- archive/bin/qterm
471-
- archive/bin/qchat
471+
- archive/bin/{cli_binary}
472+
- archive/bin/{pty_binary}
473+
- archive/bin/{chat_binary}
472474
- archive/install.sh
473475
- archive/README
474476
- archive/BUILD-INFO
@@ -879,7 +881,7 @@ def build(
879881
else:
880882
signing_data = None
881883

882-
cargo_features: Mapping[str, Sequence[str]] = {"q_cli": ["wayland"]}
884+
cargo_features: Mapping[str, Sequence[str]] = {CLI_PACKAGE_NAME: ["wayland"]}
883885

884886
match stage_name:
885887
case "prod" | None:

build-scripts/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
APP_NAME = "Amazon Q"
55
CLI_BINARY_NAME = "q"
6+
CLI_BINARY_NAME_MINIMAL = "q-minimal"
67
CHAT_BINARY_NAME = "qchat"
78
PTY_BINARY_NAME = "qterm"
89
DESKTOP_BINARY_NAME = "q-desktop"
910
URL_SCHEMA = "q"
1011
TAURI_PRODUCT_NAME = "q_desktop"
1112
LINUX_PACKAGE_NAME = "amazon-q"
13+
CHAT_BINARY_BRANCH = "prod"
1214

1315
# macos specific
1416
MACOS_BUNDLE_ID = "com.amazon.codewhisperer"

build-scripts/manifest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dataclasses import dataclass
22
from enum import Enum
33

4-
from const import APPLE_TEAM_ID
4+
from const import APPLE_TEAM_ID, APP_NAME, CLI_BINARY_NAME, PTY_BINARY_NAME, CHAT_BINARY_NAME
55

66

77
class CdSigningType(Enum):
@@ -52,21 +52,21 @@ def manifest(
5252

5353
def app_manifest():
5454
return manifest(
55-
name="Amazon Q.app",
55+
name=f"{APP_NAME}.app",
5656
identifier="com.amazon.codewhisperer",
5757
entitlements=True,
5858
embedded_requirements=[
5959
EmbeddedRequirement(
60-
path="Contents/MacOS/q",
61-
identifier="com.amazon.q",
60+
path=f"Contents/MacOS/{CLI_BINARY_NAME}",
61+
identifier=f"com.amazon.{CLI_BINARY_NAME}",
6262
),
6363
EmbeddedRequirement(
64-
path="Contents/MacOS/qterm",
65-
identifier="com.amazon.qterm",
64+
path=f"Contents/MacOS/{PTY_BINARY_NAME}",
65+
identifier=f"com.amazon.{PTY_BINARY_NAME}",
6666
),
6767
EmbeddedRequirement(
68-
path="Contents/MacOS/qchat",
69-
identifier="com.amazon.qchat",
68+
path=f"Contents/MacOS/{CHAT_BINARY_NAME}",
69+
identifier=f"com.amazon.{CHAT_BINARY_NAME}",
7070
),
7171
],
7272
)

build-scripts/qchatbuild.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def cd_build_signed_package(exe_path: pathlib.Path):
201201
```
202202
package
203203
├─ EXECUTABLES_TO_SIGN
204-
| ├─ qchat
204+
| ├─ {chat_binary}
205205
```
206206
"""
207207
# Trying a different format without manifest.yaml and placing EXECUTABLES_TO_SIGN
@@ -376,7 +376,7 @@ def sign_and_notarize(signing_data: CdSigningData, chat_path: pathlib.Path) -> p
376376

377377
def build_macos(chat_path: pathlib.Path, signing_data: CdSigningData | None):
378378
"""
379-
Creates a qchat.zip under the build directory.
379+
Creates a chat binary zip under the build directory.
380380
"""
381381
chat_dst = BUILD_DIR / CHAT_BINARY_NAME
382382
chat_dst.unlink(missing_ok=True)
@@ -495,7 +495,7 @@ def build_linux(chat_path: pathlib.Path, signer: GpgSigner | None):
495495
Creates tar.gz, tar.xz, tar.zst, and zip archives under `BUILD_DIR`.
496496
497497
Each archive has the following structure:
498-
- archive/qchat
498+
- archive/{chat_binary}
499499
"""
500500
archive_name = CHAT_BINARY_NAME
501501

build-scripts/qchatmain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __call__(self, parser, namespace, values, option_string=None):
1010

1111
parser = argparse.ArgumentParser(
1212
prog="build",
13-
description="Builds the qchat binary",
13+
description="Builds the chat binary",
1414
)
1515
subparsers = parser.add_subparsers(help="sub-command help", dest="subparser", required=True)
1616

bundle/linux/install.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set -o errexit
77
set -o nounset
88

99
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
10+
CLI_BINARY_NAME="q"
11+
CHAT_BINARY_NAME="qchat"
12+
PTY_BINARY_NAME="qterm"
1013

1114
log_error() {
1215
printf '\e[31m[ERROR]\e[0m %s\n' "$1" >&2
@@ -136,22 +139,22 @@ if is_target_triple_gnu && ! check_glibc_version; then
136139
fi
137140

138141
if [ -n "${Q_INSTALL_GLOBAL:-}" ]; then
139-
install -m 755 "$SCRIPT_DIR/bin/q" /usr/local/bin/
140-
install -m 755 "$SCRIPT_DIR/bin/qchat" /usr/local/bin/
141-
install -m 755 "$SCRIPT_DIR/bin/qterm" /usr/local/bin/
142+
install -m 755 "$SCRIPT_DIR/bin/$CLI_BINARY_NAME" /usr/local/bin/
143+
install -m 755 "$SCRIPT_DIR/bin/$CHAT_BINARY_NAME" /usr/local/bin/
144+
install -m 755 "$SCRIPT_DIR/bin/$PTY_BINARY_NAME" /usr/local/bin/
142145

143146
if [ -z "${Q_SKIP_SETUP:-}" ]; then
144-
/usr/local/bin/q integrations install dotfiles
145-
/usr/local/bin/q setup --global "$@"
147+
/usr/local/bin/$CLI_BINARY_NAME integrations install dotfiles
148+
/usr/local/bin/$CLI_BINARY_NAME setup --global "$@"
146149
fi
147150
else
148151
mkdir -p "$HOME/.local/bin"
149152

150-
install -m 755 "$SCRIPT_DIR/bin/q" "$HOME/.local/bin/"
151-
install -m 755 "$SCRIPT_DIR/bin/qchat" "$HOME/.local/bin/"
152-
install -m 755 "$SCRIPT_DIR/bin/qterm" "$HOME/.local/bin/"
153+
install -m 755 "$SCRIPT_DIR/bin/$CLI_BINARY_NAME" "$HOME/.local/bin/"
154+
install -m 755 "$SCRIPT_DIR/bin/$CHAT_BINARY_NAME" "$HOME/.local/bin/"
155+
install -m 755 "$SCRIPT_DIR/bin/$PTY_BINARY_NAME" "$HOME/.local/bin/"
153156

154157
if [ -z "${Q_SKIP_SETUP:-}" ]; then
155-
"$HOME/.local/bin/q" setup "$@"
158+
"$HOME/.local/bin/$CLI_BINARY_NAME" setup "$@"
156159
fi
157160
fi

crates/chat-cli/src/cli/chat/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ impl ContextManager {
251251
///
252252
/// # Returns
253253
/// A Result containing a vector of profile names, with "default" always first
254+
#[cfg_attr(target_os = "windows", allow(dead_code))]
254255
pub fn list_profiles_blocking(&self, os: &Os) -> Result<Vec<String>> {
255256
let _ = self;
256257

crates/chat-cli/src/cli/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use crate::logging::{
4848
use crate::os::Os;
4949
use crate::util::directories::logs_dir;
5050
use crate::util::{
51+
CHAT_BINARY_NAME,
5152
CLI_BINARY_NAME,
5253
GOV_REGIONS,
5354
};
@@ -216,7 +217,11 @@ impl Cli {
216217
},
217218
log_to_stdout: std::env::var_os("Q_LOG_STDOUT").is_some() || self.verbose > 0,
218219
log_file_path: match subcommand {
219-
RootSubcommand::Chat { .. } => Some(logs_dir().expect("home dir must be set").join("qchat.log")),
220+
RootSubcommand::Chat { .. } => Some(
221+
logs_dir()
222+
.expect("home dir must be set")
223+
.join(format!("{CHAT_BINARY_NAME}.log")),
224+
),
220225
_ => None,
221226
},
222227
delete_old_log_file: false,

crates/chat-cli/src/logging.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use tracing_subscriber::{
1414
fmt,
1515
};
1616

17+
use crate::util::consts::CHAT_BINARY_NAME;
1718
use crate::util::env_var::Q_LOG_LEVEL;
1819

1920
const MAX_FILE_SIZE: u64 = 10 * 1024 * 1024;
@@ -76,7 +77,7 @@ pub fn initialize_logging<T: AsRef<Path>>(args: LogArgs<T>) -> Result<LogGuard,
7677

7778
// Make the log path parent directory if it doesn't exist.
7879
if let Some(parent) = log_path.parent() {
79-
if log_path.ends_with("qchat.log") {
80+
if log_path.ends_with(format!("{CHAT_BINARY_NAME}.log")) {
8081
mcp_path = Some(parent.to_path_buf());
8182
}
8283
std::fs::create_dir_all(parent)?;

crates/fig_integrations/src/shell/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ impl ShellExt for Shell {
198198
include_str!("scripts/bash-preexec.sh"),
199199
"}\n",
200200
"__fig_source_bash_preexec\n",
201+
"# shellcheck disable=SC2329\n",
201202
"function __bp_adjust_histcontrol() { :; }\n",
202203
include_str!("scripts/pre.sh")
203204
)
@@ -208,6 +209,7 @@ impl ShellExt for Shell {
208209
include_str!("scripts/bash-preexec.sh"),
209210
"}\n",
210211
"__fig_source_bash_preexec\n",
212+
"# shellcheck disable=SC2329\n",
211213
"function __bp_adjust_histcontrol() { :; }\n",
212214
include_str!("scripts/post.bash")
213215
)

0 commit comments

Comments
 (0)