summaryrefslogtreecommitdiff
path: root/branding-dev-build/branding-dev-build.sh
blob: b4c3d00181b2e139c5695898c9a0a2856182a003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
#!/bin/bash

# 'branding-dev-build.sh' pre-compiled binary builds for front-end dev
# 'bootstrap.py' from:
#   https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Artifact_builds
# recipe from:
#   https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Simple_Firefox_build/Linux_and_MacOS_build_preparation

# the VCS identity used to commit to the upstream sources will be: 'nobody@nowhere.man'
# the upstream sources are not FSDG-free; and this script does not clean them
#   so the upstream sources are not to be published by parabola
# this script will leave *.patch files behind for use in the published PKGBUILDs


readonly USE_GIT=0 # git support requires 'git-cinnabar', per the Artifact_builds docs
readonly CWD=${PWD}
readonly BINARY_BUILD_SRCDIR=${CWD}/sources
readonly BINARY_BUILD_OBJDIR=${CWD}/mozbuild
readonly CID_FILENAME='UPSTREAM_CID'
readonly CID_FILE=${CWD}/${CID_FILENAME}
readonly MOZCONFIG_FILE=${BINARY_BUILD_SRCDIR}/.mozconfig

readonly BOOTSTRAP_BASE_CMD='python2 ./bootstrap.py --application-choice=browser_artifact_mode'
readonly COMMIT_MSG='nobody $(date +%F-%H-%M-%S)'
readonly PARSE_CID_CMD='$(head --bytes=40 '${CID_FILE}' 2> /dev/null)'
readonly VALIDATE_CMD='[[ "${PARSE_CID_CMD}" =~ ^[0-9a-f]{40}$ ]]'
readonly TIMESTAMP_REGEX='s|.*"nobody ([0-9-]{19})"|\1|'
readonly PATCH_FILE=${CWD}/'${timestamp}.patch'
(( ${USE_GIT} )) && readonly BOOTSTRAP_CMD=${BOOTSTRAP_BASE_CMD}' --vcs=git'                     || \
                    readonly BOOTSTRAP_CMD=${BOOTSTRAP_BASE_CMD}' --vcs=hg'
(( ${USE_GIT} )) && readonly CHECKOUT_CMD='git clone https://github.com/mozilla/gecko-dev.git'   || \
                    readonly CHECKOUT_CMD='hg  clone https://hg.mozilla.org/mozilla-unified'
(( ${USE_GIT} )) && readonly MARKER_CMD='git merge-base origin/master HEAD'                      || \
                    readonly MARKER_CMD='hg log --rev tip --template {node}'
(( ${USE_GIT} )) && readonly STAGE_CMD='git add . .gitconfig'                                    || \
                    readonly STAGE_CMD='hg addremove'
#                     readonly STAGE_CMD='hg add .'OR${CID_FILE}
(( ${USE_GIT} )) && readonly VCS_ENV_CMD='cp {${CWD}/,${BINARY_BUILD_SRCDIR}/.}gitconfig'        || \
                    readonly VCS_ENV_CMD='cp {${CWD}/,${BINARY_BUILD_SRCDIR}/.hg/}hgrc'
(( ${USE_GIT} )) && readonly COMMIT_CMD='git commit --message=\"$(COMMIT_MSG)\"'                 || \
                    readonly COMMIT_CMD='hg commit --message=\"$(COMMIT_MSG)\"'
(( ${USE_GIT} )) && readonly PATCH_CMD='git diff --patch ${PARSE_CID_CMD} HEAD' || \
                    readonly PATCH_CMD='hg log --follow --patch' # commited range
#                     readonly PATCH_CMD='hg export -o ${PATCH_FILE} -r tip' # commited tip
#                     readonly PATCH_CMD='hg diff -r '${PARSE_CID_CMD}':0000 path > '${PATCH_FILE} # commited range
#                     readonly PATCH_CMD='hg diff -g > ${PATCH_FILE}' # uncommited
#                     readonly PATCH_CMD='hg log --patch > ${PATCH_FILE}' # commited


PrepareMozillaBinaryBuild()
{
  [[ -d ${BINARY_BUILD_OBJDIR}/ ]] || mkdir ${BINARY_BUILD_OBJDIR}
  if [[ ! -d ${BINARY_BUILD_SRCDIR}/ ]]
  then echo
       echo "NOTE: This initial setup will be run only once, or when the upstream sources are otherwise mising."
       echo "      The build will require approximately 30GB disk space."
       ${CHECKOUT_CMD} ${BINARY_BUILD_SRCDIR}
       echo
       echo "NOTE: This bootstrap script will prompt for a series of decisions."
       echo "      You should see: \"Using an experimental bootstrapper for Archlinux.\"."
       echo "      When prompted for requisites, opt to install the required Parabola and AUR packages."
       echo "      When prompted to configure the VCS tool, deny."
       echo "      When prompted to enable telemetry, deny."
       echo "      The bootstrap script will then download the tooling."
       echo "      You should see: \"Your system should be ready to build Firefox for Desktop Artifact Mode!
\""
       echo "      Ignore the note about the $topsrcdir/mozconfig file; but do open a new shell to continue."
       cd ${BINARY_BUILD_SRCDIR}/ ; ${BOOTSTRAP_CMD} ; cd ${CWD} ;
  else echo "Source directory 'sources' already exists."
  fi

  # mark upstream CID and validate
  rm ${CID_FILE} 2> /dev/null
  cd ${BINARY_BUILD_SRCDIR}/ ; ${MARKER_CMD} > ${CID_FILE} ; cd ${CWD} ;

  if ! eval echo ${VALIDATE_CMD} > /dev/null
  then echo
       echo "NOTE: The file: ${CID_FILE} is missing. The VCS may be insane."
       echo "      The contents of that file will be injected as a comment into the patch files,"
       echo "        to indicate the upstream checkout-point against which the patch was created."
       echo "      Try running these commands before continuing:"
       echo "        $ cd ${BINARY_BUILD_SRCDIR}"
       echo "        $ git merge-base origin/master HEAD > ../${CID_FILENAME}"
       echo "        $ cd ${CWD}"
       echo "      If that fails, you probably need to delete the"
       echo " ${BINARY_BUILD_SRCDIR} directory and start fresh."
       return 1
  else return 0
  fi
}

ConfigMozillaBinaryBuild()
{
  cd ${BINARY_BUILD_SRCDIR}/

  # modify the mozconfig file to download and re-build against pre-built binary artifacts
  echo
  echo "NOTE: Any existing .mozconfig file is about to be clobbered;"
  echo "      then the changes defined in ConfigMozillaBinaryBuild() will be re-applied."
  echo "      Ensure that all modifications to .mozconfig are in ConfigMozillaBinaryBuild()."
  cat > ${MOZCONFIG_FILE} <<'BINARY_BUILD_END'
    # download and use pre-compiled C++ components
    ac_add_options --enable-artifact-builds
    mk_add_options MOZ_OBJDIR=objdir-artifact

    # prefer debug versions of the pre-built binary artifacts
    ac_add_options --enable-debug

    # specify build target (IIRC 'browser' is the default)
    # binary builds are also available for icedove and iceape (optional)
    ac_add_options --enable-application=browser
    # ac_add_options --enable-application=mail
    # ac_add_options --enable-application=suite

    # build multiple of iceweasel|icedove|iceape
    # mk_add_options MOZ_OBJDIR=obj-artifact-@CONFIG_GUESS@
    # mk_add_options MOZ_BUILD_PROJECTS="browser mail suite"
BINARY_BUILD_END

  local commit_cmd=$(eval echo ${COMMIT_CMD})
  local timestamp=$(sed -E "${TIMESTAMP_REGEX}" <<< ${commit_cmd})
  local patch_comment="Created against upstream VCS checkout-point: $(eval echo ${PARSE_CID_CMD})"
echo "commit_cmd=${commit_cmd}"
echo "timestamp=${timestamp}"
eval echo ${PATCH_FILE}
  echo
  echo "NOTE: Your local changes are about to be committed to the upstream VCS;"
  echo "      and a patch file against the pristine upstream source will be written."
  echo "      The ID of this commit/patch is: ${timestamp}."
  echo ${patch_comment} > $(eval echo ${PATCH_FILE})
  ${STAGE_CMD} && eval ${VCS_ENV_CMD} && eval ${commit_cmd}                            && \
                  eval ${PATCH_CMD} >> ${PATCH_FILE}                       && return 0 || \
                  echo "Failed to commit changes and/or write patch file." && return 1
}

ReBuildMozillaBinaryBuild()
{
  cd ${BINARY_BUILD_SRCDIR}

  export MOZBUILD_STATE_PATH=${BINARY_BUILD_OBJDIR}
  ./mach build
  ./mach run
}


## main entry ##

echo -e "\n\n== PrepareMozillaBinaryBuild ==" && PrepareMozillaBinaryBuild && \
# echo -e "\n\n== ConfigMozillaBinaryBuild =="  && ConfigMozillaBinaryBuild  && \
# echo -e "\n\n== ReBuildMozillaBinaryBuild ==" && ReBuildMozillaBinaryBuild
echo -e "\n\n== ReBuildMozillaBinaryBuild ==" && echo out # ReBuildMozillaBinaryBuild